diff --git a/source/cellular_3gpp_api.c b/source/cellular_3gpp_api.c index 12979660..cc208ef5 100644 --- a/source/cellular_3gpp_api.c +++ b/source/cellular_3gpp_api.c @@ -1589,7 +1589,7 @@ 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: @@ -1597,7 +1597,7 @@ static CellularATError_t parseT3324TimerValue( char * pToken, break; case T3324_TIMER_UNIT_DECIHOURS: - *pTimerValueSeconds = timerValue * ( 15U * 60U ); + *pTimerValueSeconds = timerValue * ( 6U * 60U ); break; case T3324_TIMER_UNIT_DEACTIVATED: diff --git a/test/unit-test/cellular_3gpp_api_utest.c b/test/unit-test/cellular_3gpp_api_utest.c index 233c5422..77ede2ed 100644 --- a/test/unit-test/cellular_3gpp_api_utest.c +++ b/test/unit-test/cellular_3gpp_api_utest.c @@ -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; @@ -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; @@ -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 ) { @@ -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 ); @@ -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 ); @@ -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 { @@ -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; @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 );