Skip to content

Commit

Permalink
Fix decihours to 6 minutes and UT (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ActoryOu authored Nov 8, 2023
1 parent ccbd0fc commit b9679f3
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
4 changes: 2 additions & 2 deletions source/cellular_3gpp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1589,15 +1589,15 @@ static CellularATError_t parseT3324TimerValue( char * pToken,
switch( timerUnitIndex )
{
case T3324_TIMER_UNIT_2SECONDS:
*pTimerValueSeconds = timerValue * 2u;
*pTimerValueSeconds = timerValue * 2U;
break;

case T3324_TIMER_UNIT_1MINUTE:
*pTimerValueSeconds = timerValue * 60U;
break;

case T3324_TIMER_UNIT_DECIHOURS:
*pTimerValueSeconds = timerValue * ( 15U * 60U );
*pTimerValueSeconds = timerValue * ( 6U * 60U );
break;

case T3324_TIMER_UNIT_DEACTIVATED:
Expand Down
91 changes: 85 additions & 6 deletions test/unit-test/cellular_3gpp_api_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ static int cpsms_pos_mode_error = 0;
static int recvFuncGetHplmnCase = 0;
static int parseHplmn_test = 0;
static int simLockStateTestCase = 0;
static int psmSettingsTimerIndex = 0;
static int psmSettingsCheckTimerValue = 0;
static int psmSettingsTimerIndex = -1;
static int psmSettingsTimerError = 0;
static int psmSettingsActiveTimerValue = 0;
static int parseEidrxTokenOutOfRange = 0;
static int mallocAllocFail = 0;
static int nullTokenFirst = 0;
Expand All @@ -126,8 +128,10 @@ void setUp()
recvFuncGetHplmnCase = 0;
parseHplmn_test = 0;
simLockStateTestCase = 0;
psmSettingsTimerIndex = 0;
psmSettingsCheckTimerValue = 0;
psmSettingsTimerIndex = -1;
psmSettingsTimerError = 0;
psmSettingsActiveTimerValue = 0;
parseEidrxTokenOutOfRange = 0;
mallocAllocFail = 0;
nullTokenFirst = 0;
Expand Down Expand Up @@ -728,7 +732,36 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettin
char pLine[] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );
memset( &cellularPsmSettings, 0, sizeof( CellularPsmSettings_t ) );
pktStatus = atReq.respCallback( pContext, &atResp, &cellularPsmSettings, sizeof( CellularPsmSettings_t ) );

if( psmSettingsCheckTimerValue == 1 )
{
uint32_t ulTimeValueSeconds = 0U;

if( psmSettingsTimerIndex == 0 )
{
ulTimeValueSeconds = psmSettingsActiveTimerValue * 2U;
}
else if( psmSettingsTimerIndex == 1 )
{
ulTimeValueSeconds = psmSettingsActiveTimerValue * 60U;
}
else if( psmSettingsTimerIndex == 2 )
{
ulTimeValueSeconds = psmSettingsActiveTimerValue * 6 * 60U;
}
else if( psmSettingsTimerIndex == 7 )
{
ulTimeValueSeconds = 0xFFFFFFFFU;
}
else
{
ulTimeValueSeconds = 0U;
}

TEST_ASSERT_EQUAL_INT( ulTimeValueSeconds, cellularPsmSettings.activeTimeValue );
}
}
else if( cbCondition == 4 )
{
Expand Down Expand Up @@ -1358,7 +1391,7 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Calback( char ** ppString,
{
if( cmock_num_calls == 3 )
{
if( psmSettingsTimerIndex > 0 )
if( psmSettingsTimerIndex >= 0 )
{
int t3412TimerInx = ( psmSettingsTimerIndex << 5U );

Expand All @@ -1378,7 +1411,7 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Calback( char ** ppString,
}
else
{
if( ( cmock_num_calls == 4 ) && ( psmSettingsTimerIndex > 0 ) )
if( ( cmock_num_calls == 4 ) && ( psmSettingsTimerIndex >= 0 ) )
{
int t3324TimerInx = ( psmSettingsTimerIndex << 5U );

Expand All @@ -1388,7 +1421,7 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Calback( char ** ppString,
}

*ppTokOutput = malloc( len );
snprintf( *ppTokOutput, len, "%d", t3324TimerInx );
snprintf( *ppTokOutput, len, "%d", t3324TimerInx | psmSettingsActiveTimerValue );
}
else
{
Expand Down Expand Up @@ -8107,7 +8140,39 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_CPSMS
* @brief Test that happy path case in callback function _Cellular_RecvFuncGetPsmSettings
* for Cellular_CommonGetPsmSettings to return CELLULAR_SUCCESS.
*/
void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy_Path( void )
void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy_Path_Idx_0( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;

memset( &context, 0, sizeof( CellularContext_t ) );
CellularHandle_t cellularHandle = &context;
CellularPsmSettings_t psmSettings;

_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 0;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi );

_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_OK );
_Cellular_TranslatePktStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

cellularStatus = Cellular_CommonGetPsmSettings( cellularHandle, &psmSettings );
TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus );
}

/**
* @brief Test that happy path case in callback function _Cellular_RecvFuncGetPsmSettings
* for Cellular_CommonGetPsmSettings to return CELLULAR_SUCCESS.
*/
void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy_Path_Idx_1( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;
Expand All @@ -8120,7 +8185,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 1;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8150,7 +8217,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 2;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8180,7 +8249,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 3;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8210,7 +8281,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 4;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8240,7 +8313,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 5;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8270,7 +8345,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 6;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down Expand Up @@ -8300,7 +8377,9 @@ void test_Cellular_CommonGetPsmSettings_Cb_Cellular_RecvFuncGetPsmSettings_Happy
_Cellular_IsValidPdn_IgnoreAndReturn( CELLULAR_SUCCESS );
cbCondition = 3;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetPsmSettings );
psmSettingsCheckTimerValue = 1;
psmSettingsTimerIndex = 7;
psmSettingsActiveTimerValue = 2;
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Calback );
Expand Down

0 comments on commit b9679f3

Please sign in to comment.