From c2ed6288b2cface62f96a25f999c75b5128ac1a7 Mon Sep 17 00:00:00 2001 From: ActoryOu Date: Wed, 20 Nov 2024 13:18:04 +0800 Subject: [PATCH] Parsing CREG/CGREG/CEREG separately. (#182) * Parsing CREG/CGREG/CEREG separately. --- .gitignore | 3 +- docs/doxygen/include/size_table.md | 8 +- source/cellular_3gpp_urc_handler.c | 357 ++++++-- .../cellular_3gpp_urc_handler_utest.c | 828 ++++++++++++++++-- 4 files changed, 1068 insertions(+), 128 deletions(-) diff --git a/.gitignore b/.gitignore index 6caf68af..09f22516 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -output \ No newline at end of file +output +build diff --git a/docs/doxygen/include/size_table.md b/docs/doxygen/include/size_table.md index bbe2276b..634fbd66 100644 --- a/docs/doxygen/include/size_table.md +++ b/docs/doxygen/include/size_table.md @@ -14,8 +14,8 @@ cellular_3gpp_urc_handler.c -
0.9K
-
0.8K
+
1.1K
+
1.0K
cellular_at_core.c @@ -44,7 +44,7 @@ Total estimates -
15.1K
-
13.7K
+
15.3K
+
13.9K
diff --git a/source/cellular_3gpp_urc_handler.c b/source/cellular_3gpp_urc_handler.c index dfd82083..94fffc1a 100644 --- a/source/cellular_3gpp_urc_handler.c +++ b/source/cellular_3gpp_urc_handler.c @@ -49,12 +49,23 @@ /*-----------------------------------------------------------*/ +#define CELLULAR_REG_POS_NONE ( 0U ) +#define CELLULAR_REG_POS_NET_REG ( 1U ) #define CELLULAR_REG_POS_STAT ( 2U ) #define CELLULAR_REG_POS_LAC_TAC ( 3U ) #define CELLULAR_REG_POS_CELL_ID ( 4U ) #define CELLULAR_REG_POS_RAT ( 5U ) #define CELLULAR_REG_POS_REJ_TYPE ( 6U ) #define CELLULAR_REG_POS_REJ_CAUSE ( 7U ) +#define CELLULAR_REG_POS_RAC ( 8U ) + +/*-----------------------------------------------------------*/ + +/* Function pointer prototype to point to corresponding function for CREG/CEREG/CGREG. */ +typedef CellularPktStatus_t ( * RegStatusSwitchParsingFunc_t )( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ); /*-----------------------------------------------------------*/ static CellularPktStatus_t _parseRegStatusInRegStatusParsing( CellularContext_t * pContext, @@ -74,11 +85,25 @@ static CellularPktStatus_t _parseRejectTypeInRegStatus( CellularNetworkRegType_t static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_t regType, const char * pToken, cellularAtData_t * pLibAtData ); +static CellularPktStatus_t _parseRoutingAreaCodeInRegStatus( const char * pToken, + cellularAtData_t * pLibAtData ); static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext, uint8_t i, CellularNetworkRegType_t regType, const char * pToken, cellularAtData_t * pLibAtData ); +static CellularPktStatus_t _regStatusSwitchParsingFuncCreg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ); +static CellularPktStatus_t _regStatusSwitchParsingFuncCereg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ); +static CellularPktStatus_t _regStatusSwitchParsingFuncCgreg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ); static void _regStatusGenerateLog( char * pRegPayload, CellularNetworkRegType_t regType ); static void _regStatusGenerateEvent( const CellularContext_t * pContext, @@ -101,33 +126,25 @@ static CellularPktStatus_t _parseRegStatusInRegStatusParsing( CellularContext_t CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularNetworkRegistrationStatus_t regStatus = REGISTRATION_STATUS_UNKNOWN; - if( ( regType != CELLULAR_REG_TYPE_CREG ) && ( regType != CELLULAR_REG_TYPE_CEREG ) && - ( regType != CELLULAR_REG_TYPE_CGREG ) ) - { - packetStatus = CELLULAR_PKT_STATUS_BAD_PARAM; - } - else - { - atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue ); + atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue ); - if( atCoreStatus == CELLULAR_AT_SUCCESS ) + if( atCoreStatus == CELLULAR_AT_SUCCESS ) + { + if( ( tempValue >= 0 ) && ( tempValue < ( int32_t ) REGISTRATION_STATUS_MAX ) ) { - if( ( tempValue >= 0 ) && ( tempValue < ( int32_t ) REGISTRATION_STATUS_MAX ) ) - { - /* MISRA Ref 10.5.1 [Essential type casting] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-105 */ - /* coverity[misra_c_2012_rule_10_5_violation] */ - regStatus = ( CellularNetworkRegistrationStatus_t ) tempValue; - } - else - { - atCoreStatus = CELLULAR_AT_ERROR; - } + /* MISRA Ref 10.5.1 [Essential type casting] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-105 */ + /* coverity[misra_c_2012_rule_10_5_violation] */ + regStatus = ( CellularNetworkRegistrationStatus_t ) tempValue; + } + else + { + atCoreStatus = CELLULAR_AT_ERROR; } - - packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); } + packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); + if( packetStatus == CELLULAR_PKT_STATUS_OK ) { if( regType == CELLULAR_REG_TYPE_CREG ) @@ -196,14 +213,12 @@ static CellularPktStatus_t _parseLacTacInRegStatus( CellularNetworkRegType_t reg { pLibAtData->lac = ( uint16_t ) var; } - /* Parsing Tracking area code for CEREG. */ - else if( regType == CELLULAR_REG_TYPE_CEREG ) - { - pLibAtData->tac = ( uint16_t ) var; - } + + /* regType has been checked in _Cellular_ParseRegStatus. + * The only possible value of else here is CEREG. */ else { - /* Empty else MISRA 15.7 */ + pLibAtData->tac = ( uint16_t ) var; } } @@ -252,7 +267,7 @@ static CellularPktStatus_t _parseRatInfoInRegStatus( const char * pToken, if( atCoreStatus == CELLULAR_AT_SUCCESS ) { - if( var >= ( int32_t ) CELLULAR_RAT_MAX ) + if( ( var >= ( int32_t ) CELLULAR_RAT_MAX ) || ( var < 0 ) ) { atCoreStatus = CELLULAR_AT_ERROR; LogError( ( "Error in processing RAT. Token %s", pToken ) ); @@ -307,24 +322,23 @@ static CellularPktStatus_t _parseRejectTypeInRegStatus( CellularNetworkRegType_t if( atCoreStatus == CELLULAR_AT_SUCCESS ) { - if( regType == CELLULAR_REG_TYPE_CREG ) - { - /* Reject Type is only stored if the registration status is denied. */ - if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) - { - pLibAtData->csRejectType = rejType; - } - } - else if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) ) + if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) ) { if( pLibAtData->psRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) { pLibAtData->psRejectType = rejType; } } + + /* regType has been checked in _Cellular_ParseRegStatus. + * The only possible value of else here is CREG. */ else { - /* Empty else MISRA 15.7 */ + /* Reject Type is only stored if the registration status is denied. */ + if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) + { + pLibAtData->csRejectType = rejType; + } } } @@ -359,44 +373,75 @@ static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_ if( atCoreStatus == CELLULAR_AT_SUCCESS ) { - if( regType == CELLULAR_REG_TYPE_CREG ) + if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) ) { - if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) + if( pLibAtData->psRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) { - pLibAtData->csRejCause = rejCause; + pLibAtData->psRejCause = rejCause; } } - else if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) ) + + /* regType has been checked in _Cellular_ParseRegStatus. + * The only possible value of else here is CREG. */ + else { - if( pLibAtData->psRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) + if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED ) { - pLibAtData->psRejCause = rejCause; + pLibAtData->csRejCause = rejCause; } } + } + + packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); + + return packetStatus; +} + +/*-----------------------------------------------------------*/ + +static CellularPktStatus_t _parseRoutingAreaCodeInRegStatus( const char * pToken, + cellularAtData_t * pLibAtData ) +{ + int32_t tempValue = 0; + uint8_t rac = 0; + CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS; + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + + atCoreStatus = Cellular_ATStrtoi( pToken, 16, &tempValue ); + + if( atCoreStatus == CELLULAR_AT_SUCCESS ) + { + if( ( tempValue >= 0 ) && ( tempValue <= ( int32_t ) UINT8_MAX ) ) + { + rac = ( uint8_t ) tempValue; + } else { - /* Empty else MISRA 15.7 */ + atCoreStatus = CELLULAR_AT_ERROR; } } - packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); + if( atCoreStatus == CELLULAR_AT_SUCCESS ) + { + pLibAtData->rac = rac; + } + packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); return packetStatus; } /*-----------------------------------------------------------*/ static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext, - uint8_t i, + uint8_t regPos, CellularNetworkRegType_t regType, const char * pToken, cellularAtData_t * pLibAtData ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; - switch( i ) + switch( regPos ) { - /* Parsing network Registration status in CREG or CGREG or CEREG response. */ case CELLULAR_REG_POS_STAT: packetStatus = _parseRegStatusInRegStatusParsing( pContext, regType, pToken, pLibAtData ); break; @@ -425,6 +470,13 @@ static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pCon packetStatus = _parseRejectCauseInRegStatus( regType, pToken, pLibAtData ); break; + /* Parsing the routing area code */ + case CELLULAR_REG_POS_RAC: + packetStatus = _parseRoutingAreaCodeInRegStatus( pToken, pLibAtData ); + break; + + /* Ignore network Registration status in CREG or CGREG or CEREG response. */ + case CELLULAR_REG_POS_NET_REG: default: LogDebug( ( "Unknown Parameter Position in Registration URC" ) ); break; @@ -435,6 +487,128 @@ static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pCon /*-----------------------------------------------------------*/ +static CellularPktStatus_t _regStatusSwitchParsingFuncCreg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + const uint8_t parsingTable[] = + { + CELLULAR_REG_POS_NONE, + CELLULAR_REG_POS_NET_REG, + CELLULAR_REG_POS_STAT, + CELLULAR_REG_POS_LAC_TAC, + CELLULAR_REG_POS_CELL_ID, + CELLULAR_REG_POS_RAT, + CELLULAR_REG_POS_REJ_TYPE, + CELLULAR_REG_POS_REJ_CAUSE + }; + + if( i >= ( sizeof( parsingTable ) / sizeof( parsingTable[ 0 ] ) ) ) + { + /** + * +CREG URC response format: + * - +CREG: ,[,[],[],[][,,]] + */ + LogDebug( ( "Ignore unknown +CREG parameter at position(%u) in registration URC. Token %s.", i, pToken ) ); + } + else + { + packetStatus = _regStatusSwitchParsingFunc( pContext, parsingTable[ i ], CELLULAR_REG_TYPE_CREG, + pToken, pLibAtData ); + } + + return packetStatus; +} + +/*-----------------------------------------------------------*/ + +static CellularPktStatus_t _regStatusSwitchParsingFuncCgreg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + const uint8_t parsingTable[] = + { + CELLULAR_REG_POS_NONE, + CELLULAR_REG_POS_NET_REG, + CELLULAR_REG_POS_STAT, + CELLULAR_REG_POS_LAC_TAC, + CELLULAR_REG_POS_CELL_ID, + CELLULAR_REG_POS_RAT, + CELLULAR_REG_POS_RAC, + CELLULAR_REG_POS_REJ_TYPE, + CELLULAR_REG_POS_REJ_CAUSE + }; + + if( i >= ( sizeof( parsingTable ) / sizeof( parsingTable[ 0 ] ) ) ) + { + /** + * In +CGREG, there are two possible formats: + * - when is in range of 0~3: + * - +CGREG: ,[,[],[],[],[][,,]] + * - when is in range of 4~5: + * - +CGREG: ,[,[],[],[],[][,[],[][,[],[],[]]]] + * + * For now we only handle the format for 0~3, And ignores additional parameters for in range 4-5. + */ + LogDebug( ( "Ignore unknown +CGREG parameter at position(%u) in registration URC. Token %s.", i, pToken ) ); + } + else + { + packetStatus = _regStatusSwitchParsingFunc( pContext, parsingTable[ i ], CELLULAR_REG_TYPE_CGREG, + pToken, pLibAtData ); + } + + return packetStatus; +} + +/*-----------------------------------------------------------*/ + +static CellularPktStatus_t _regStatusSwitchParsingFuncCereg( CellularContext_t * pContext, + uint8_t i, + const char * pToken, + cellularAtData_t * pLibAtData ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + const uint8_t parsingTable[] = + { + CELLULAR_REG_POS_NONE, + CELLULAR_REG_POS_NET_REG, + CELLULAR_REG_POS_STAT, + CELLULAR_REG_POS_LAC_TAC, + CELLULAR_REG_POS_CELL_ID, + CELLULAR_REG_POS_RAT, + CELLULAR_REG_POS_REJ_TYPE, + CELLULAR_REG_POS_REJ_CAUSE + }; + + if( i >= ( sizeof( parsingTable ) / sizeof( parsingTable[ 0 ] ) ) ) + { + /** + * In +CEREG, there are two possible formats: + * - when is in range of 0~3: + * - +CEREG: ,[,[],[],[[,,]]] + * - when is in range of 4~5: + * - +CEREG: ,[,[],[],[][,[],[][,[],[]]]] + * + * For now we only handle the format for 0~3, And ignores additional parameters for in range 4-5. + */ + LogDebug( ( "Ignore unknown +CEREG parameter at position(%u) in registration URC. Token %s.", i, pToken ) ); + } + else + { + packetStatus = _regStatusSwitchParsingFunc( pContext, parsingTable[ i ], CELLULAR_REG_TYPE_CEREG, + pToken, pLibAtData ); + } + + return packetStatus; +} + +/*-----------------------------------------------------------*/ + static void _regStatusGenerateLog( char * pRegPayload, CellularNetworkRegType_t regType ) { @@ -548,6 +722,7 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS; CellularNetworkRegistrationStatus_t prevCsRegStatus = REGISTRATION_STATUS_UNKNOWN; CellularNetworkRegistrationStatus_t prevPsRegStatus = REGISTRATION_STATUS_UNKNOWN; + RegStatusSwitchParsingFunc_t pRegStatusParsingFunc = NULL; if( pContext == NULL ) { @@ -558,17 +733,48 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, packetStatus = CELLULAR_PKT_STATUS_BAD_PARAM; } else + { + /* Empty else MISRA 15.7 */ + } + + if( packetStatus == CELLULAR_PKT_STATUS_OK ) { pLibAtData = &( pContext->libAtData ); - if( isUrc == true ) + pRegStr = pRegPayload; + + switch( regType ) { - i++; + case CELLULAR_REG_TYPE_CREG: + pRegStatusParsingFunc = _regStatusSwitchParsingFuncCreg; + break; + + case CELLULAR_REG_TYPE_CGREG: + pRegStatusParsingFunc = _regStatusSwitchParsingFuncCgreg; + break; + + case CELLULAR_REG_TYPE_CEREG: + pRegStatusParsingFunc = _regStatusSwitchParsingFuncCereg; + break; + + default: + LogDebug( ( "Unknown Registration Type %d", regType ) ); + atCoreStatus = CELLULAR_AT_BAD_PARAMETER; + break; } - pRegStr = pRegPayload; + if( atCoreStatus != CELLULAR_AT_SUCCESS ) + { + packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); + } + } - atCoreStatus = Cellular_ATRemoveAllDoubleQuote( pRegStr ); + if( packetStatus == CELLULAR_PKT_STATUS_OK ) + { + if( atCoreStatus == CELLULAR_AT_SUCCESS ) + { + atCoreStatus = Cellular_ATRemoveAllDoubleQuote( pRegStr ); + } if( atCoreStatus == CELLULAR_AT_SUCCESS ) { @@ -580,23 +786,38 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, atCoreStatus = Cellular_ATGetNextTok( &pRegStr, &pToken ); } - if( atCoreStatus == CELLULAR_AT_SUCCESS ) + if( atCoreStatus != CELLULAR_AT_SUCCESS ) + { + packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus ); + } + } + + if( packetStatus == CELLULAR_PKT_STATUS_OK ) + { + if( isUrc == true ) { - /* Backup the previous regStatus. */ - prevCsRegStatus = pLibAtData->csRegStatus; - prevPsRegStatus = pLibAtData->psRegStatus; + i++; + } + + /* Backup the previous regStatus. */ + prevCsRegStatus = pLibAtData->csRegStatus; + prevPsRegStatus = pLibAtData->psRegStatus; + + while( pToken != NULL ) + { + i++; + + packetStatus = pRegStatusParsingFunc( pContext, i, pToken, pLibAtData ); + + if( packetStatus != CELLULAR_PKT_STATUS_OK ) + { + break; + } - while( pToken != NULL ) + /* Getting next token to parse. */ + if( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS ) { - i++; - packetStatus = _regStatusSwitchParsingFunc( pContext, i, regType, - pToken, pLibAtData ); - - /* Getting next token to parse. */ - if( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS ) - { - break; - } + break; } } diff --git a/test/unit-test/cellular_3gpp_urc_handler_utest.c b/test/unit-test/cellular_3gpp_urc_handler_utest.c index 6318f33f..fe47fd2d 100644 --- a/test/unit-test/cellular_3gpp_urc_handler_utest.c +++ b/test/unit-test/cellular_3gpp_urc_handler_utest.c @@ -47,12 +47,15 @@ #include "mock_cellular_at_core.h" #include "mock_cellular_common.h" +static CellularNetworkRegType_t parseRegType = CELLULAR_REG_TYPE_UNKNOWN; static int parseRegStatusCase = 0; static int parseLacTacInRegCase = 0; static int parseCellIdInRegCase = 0; static int parseRatInfoInRegCase = 0; +static int parseRacInfoInRegCase = 0; static int parseRejectTypeInRegCase = 0; static int parseRejectCauseInRegCase = 0; +static int parseExtraUnknownParamNum = 0; static int returnNULL = 0; static int atoiFailure = 0; /* ============================ UNITY FIXTURES ============================ */ @@ -60,6 +63,7 @@ static int atoiFailure = 0; /* Called before each test method. */ void setUp() { + parseRegType = CELLULAR_REG_TYPE_UNKNOWN; parseRegStatusCase = 0; parseLacTacInRegCase = 0; parseCellIdInRegCase = 0; @@ -68,6 +72,8 @@ void setUp() parseRejectCauseInRegCase = 0; returnNULL = 0; atoiFailure = 0; + parseRacInfoInRegCase = 0; + parseExtraUnknownParamNum = 0; } /* Called after each test method. */ @@ -199,7 +205,7 @@ void handleNextTok_parseRatInfoInRegCase( char ** ppTokOutput, } else if( parseRatInfoInRegCase == 4 ) { - char pTestString[] = "3"; + char pTestString[] = "-1"; *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } @@ -215,6 +221,19 @@ void handleNextTok_parseRatInfoInRegCase( char ** ppTokOutput, *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } + else if( parseRatInfoInRegCase == 7 ) + { + char pTestString[] = "ABCD"; /* Invalid decimal value */ + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else if( parseRatInfoInRegCase == 8 ) + { + char pTestString[] = "3"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } } void handleNextTok_parseRejectTypeInRegCase( char ** ppTokOutput, @@ -238,6 +257,13 @@ void handleNextTok_parseRejectTypeInRegCase( char ** ppTokOutput, *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } + else if( parseRejectTypeInRegCase == 4 ) + { + char pTestString[] = "1"; + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } } void handleNextTok_parseRejectCauseInRegCase( char ** ppTokOutput, @@ -261,23 +287,197 @@ void handleNextTok_parseRejectCauseInRegCase( char ** ppTokOutput, *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } + else if( parseRejectCauseInRegCase == 4 ) + { + char pTestString[] = "ABCD"; + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } } -CellularATError_t Mock_Cellular_ATGetNextTok_Callback( char ** ppString, - char ** ppTokOutput, - int cmockNumCalls ) +void handleNextTok_parseRoutingAreaCodeInRegCase( char ** ppTokOutput, + int32_t parseRacInfoInRegCase ) +{ + if( parseRacInfoInRegCase == 1 ) + { + char pTestString[] = "256"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else if( parseRacInfoInRegCase == 2 ) + { + /* Invalid hex value. */ + char pTestString[] = "-1"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else if( parseRacInfoInRegCase == 3 ) + { + /* Invalid hex value. */ + char pTestString[] = "GG"; + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } +} + +/** + * In +CGREG, it's assumed to handle in the following sequence. + * - +CGREG: ,[,[],[],[],[][,,]] + */ +CellularATError_t handleNextTok_Cgreg( char ** ppTokOutput, + int cmockNumCalls ) { CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS; char pFitNum[] = "1"; - ( void ) ppString; - - if( *ppTokOutput ) + if( cmockNumCalls < 8 ) { - free( *ppTokOutput ); - *ppTokOutput = NULL; + if( cmockNumCalls == 1 ) + { + if( parseRegStatusCase > 0 ) + { + handleNextTok_parseRegStatusCase( ppTokOutput, parseRegStatusCase ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else if( cmockNumCalls == 2 ) + { + if( parseLacTacInRegCase == 1 ) + { + char pTestString[] = "65536"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else if( parseLacTacInRegCase == 2 ) + { + char pTestString[] = "-3"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else if( parseLacTacInRegCase == 3 ) + { + char pTestString[] = "GGGG"; /* Invalid hex value */ + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else if( cmockNumCalls == 3 ) + { + if( parseCellIdInRegCase == 1 ) + { + char pTestString[] = "-10"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else if( cmockNumCalls == 4 ) + { + if( parseRatInfoInRegCase > 0 ) + { + handleNextTok_parseRatInfoInRegCase( ppTokOutput, parseRatInfoInRegCase ); + } + else + { + char pTestString[] = "0"; + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } + } + else if( cmockNumCalls == 5 ) + { + if( parseRacInfoInRegCase > 0 ) + { + /* In +CGREG, the field is filled with RAC instead of reject type. */ + handleNextTok_parseRoutingAreaCodeInRegCase( ppTokOutput, parseRacInfoInRegCase ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else if( cmockNumCalls == 6 ) + { + if( parseRejectTypeInRegCase > 0 ) + { + handleNextTok_parseRejectTypeInRegCase( ppTokOutput, parseRejectTypeInRegCase ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else if( cmockNumCalls == 7 ) + { + if( parseRejectCauseInRegCase > 0 ) + { + handleNextTok_parseRejectCauseInRegCase( ppTokOutput, parseRejectCauseInRegCase ); + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + else + { + if( returnNULL != 0 ) + { + /* Do nothing to return NULL token. */ + } + else + { + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + } + } + else + { + if( parseExtraUnknownParamNum > 0 ) + { + parseExtraUnknownParamNum--; + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + else + { + atCoreStatus = CELLULAR_AT_ERROR; + } } + return atCoreStatus; +} + +/** + * By default, it's assumed to handle in the following sequence. + * - +CREG: ,[,[],[],[][,,]] + * - +CEREG: ,[,[],[],[[,,]]] + */ +CellularATError_t handleNextTok_Default( char ** ppTokOutput, + int cmockNumCalls ) +{ + CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS; + char pFitNum[] = "1"; + if( cmockNumCalls < 7 ) { if( cmockNumCalls == 1 ) @@ -306,6 +506,13 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Callback( char ** ppString, *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } + else if( parseLacTacInRegCase == 3 ) + { + char pTestString[] = "GGGG"; /* Invalid hex value */ + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } else { *ppTokOutput = malloc( sizeof( pFitNum ) ); @@ -320,6 +527,13 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Callback( char ** ppString, *ppTokOutput = malloc( sizeof( pTestString ) ); memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); } + else if( parseCellIdInRegCase == 2 ) + { + char pTestString[] = "GGGG"; /* Invalid hex value */ + atoiFailure = 1; /* Trigger atoi failure */ + *ppTokOutput = malloc( sizeof( pTestString ) ); + memcpy( *ppTokOutput, pTestString, sizeof( pTestString ) ); + } else { *ppTokOutput = malloc( sizeof( pFitNum ) ); @@ -378,7 +592,46 @@ CellularATError_t Mock_Cellular_ATGetNextTok_Callback( char ** ppString, } else { - atCoreStatus = CELLULAR_AT_ERROR; + if( parseExtraUnknownParamNum > 0 ) + { + parseExtraUnknownParamNum--; + *ppTokOutput = malloc( sizeof( pFitNum ) ); + memcpy( *ppTokOutput, pFitNum, sizeof( pFitNum ) ); + } + else + { + atCoreStatus = CELLULAR_AT_ERROR; + } + } + + return atCoreStatus; +} + +CellularATError_t Mock_Cellular_ATGetNextTok_Callback( char ** ppString, + char ** ppTokOutput, + int cmockNumCalls ) +{ + CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS; + + ( void ) ppString; + + if( *ppTokOutput ) + { + free( *ppTokOutput ); + *ppTokOutput = NULL; + } + + switch( parseRegType ) + { + case CELLULAR_REG_TYPE_CGREG: + atCoreStatus = handleNextTok_Cgreg( ppTokOutput, cmockNumCalls ); + break; + + case CELLULAR_REG_TYPE_CREG: + case CELLULAR_REG_TYPE_CEREG: + default: + atCoreStatus = handleNextTok_Default( ppTokOutput, cmockNumCalls ); + break; } return atCoreStatus; @@ -493,9 +746,9 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_POS_RAT_Invalid_Value( void ) } /** - * @brief Test that register out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + * @brief Test that register status out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRange( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRegStatus( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -508,19 +761,14 @@ void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRange( void ) Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); parseRegStatusCase = 1; - parseLacTacInRegCase = 1; - parseCellIdInRegCase = 1; - parseRatInfoInRegCase = 1; - parseRejectTypeInRegCase = 1; - parseRejectCauseInRegCase = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that register out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + * @brief Test that tracking area code out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRange( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundTac( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -532,21 +780,15 @@ void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRange( void ) Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - parseRegStatusCase = 5; - parseLacTacInRegCase = 2; - parseCellIdInRegCase = 1; - /* CELLULAR_RAT_EDGE case. */ - parseRatInfoInRegCase = 4; - parseRejectTypeInRegCase = 3; - parseRejectCauseInRegCase = 3; + parseLacTacInRegCase = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + * @brief Test that cell ID out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_Regs_Atoi_Fail( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundCellId( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -558,20 +800,15 @@ void test_Cellular_ParseRegStatus_Regs_Atoi_Fail( void ) Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - parseRegStatusCase = 1; - parseLacTacInRegCase = 1; parseCellIdInRegCase = 1; - parseRejectTypeInRegCase = 1; - parseRejectCauseInRegCase = 3; - atoiFailure = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that CELLULAR_RAT_CATM1 case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + * @brief Test that access technology of the serving cell out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_CELLULAR_RAT_CATM1( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRatInfo( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -583,16 +820,15 @@ void test_Cellular_ParseRegStatus_CELLULAR_RAT_CATM1( void ) Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - /* CELLULAR_RAT_CATM1 case. */ - parseRatInfoInRegCase = 5; + parseRatInfoInRegCase = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); - TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that CELLULAR_REG_POS_RAT CELLULAR_RAT_LTE case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + * @brief Test that cause type out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_CELLULAR_REG_POS_RAT_Status_CELLULAR_RAT_LTE( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundCauseType( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -604,15 +840,15 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_POS_RAT_Status_CELLULAR_RAT_LTE( Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - parseRatInfoInRegCase = 2; + parseRejectTypeInRegCase = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); - TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that CELLULAR_REG_TYPE_CEREG clear atlib data case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + * @brief Test that reject cause out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Clear_AtLib_Data( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRejCause( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -624,16 +860,15 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Clear_AtLib_Dat Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - parseRegStatusCase = 4; - parseRatInfoInRegCase = 6; + parseRejectCauseInRegCase = 1; packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); - TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that CELLULAR_REG_TYPE_CEREG status registration denied case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + * @brief Test that routing area code out of upper bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Registration_Denied( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfUpperBoundRac( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -645,15 +880,352 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Registration_De Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); - parseRegStatusCase = 3; - packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); - TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); + parseRacInfoInRegCase = 1; + parseRegType = CELLULAR_REG_TYPE_CGREG; + packetStatus = _Cellular_ParseRegStatus( &context, "+CGREG: 2", false, CELLULAR_REG_TYPE_CGREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); } /** - * @brief Test that CELLULAR_REG_TYPE_CEREG status registration roaming case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + * @brief Test that register status out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. */ -void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Registration_Roaming( void ) +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRegStatus( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRegStatusCase = 5; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that tracking area code out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundTac( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseLacTacInRegCase = 2; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that cell ID out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundCellId( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseCellIdInRegCase = 1; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that access technology of the serving cell out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRatInfo( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRatInfoInRegCase = 4; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that cause type out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundCauseType( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRejectTypeInRegCase = 3; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that reject cause out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRejCause( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRejectCauseInRegCase = 3; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that routing area code out of lower bound range case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_OutOfLowerBoundRac( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRacInfoInRegCase = 2; + parseRegType = CELLULAR_REG_TYPE_CGREG; + packetStatus = _Cellular_ParseRegStatus( &context, "+CGREG: 2", false, CELLULAR_REG_TYPE_CGREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that more paremeters in +CREG response. + */ +void test_Cellular_ParseRegStatus_Regs_TooManyParametersInCreg( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + + parseExtraUnknownParamNum = 1; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that more paremeters in +CGREG response. + */ +void test_Cellular_ParseRegStatus_Regs_TooManyParametersInCgreg( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + + parseExtraUnknownParamNum = 1; + parseRegType = CELLULAR_REG_TYPE_CGREG; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CGREG: 2", false, CELLULAR_REG_TYPE_CGREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that more paremeters in +CEREG response. + */ +void test_Cellular_ParseRegStatus_Regs_TooManyParametersInCereg( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + + parseExtraUnknownParamNum = 1; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE. + */ +void test_Cellular_ParseRegStatus_Regs_Atoi_Fail( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRegStatusCase = 1; + parseLacTacInRegCase = 1; + parseCellIdInRegCase = 1; + parseRejectTypeInRegCase = 1; + parseRejectCauseInRegCase = 3; + atoiFailure = 1; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that CELLULAR_RAT_CATM1 case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_RAT_CATM1( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + /* CELLULAR_RAT_CATM1 case. */ + parseRatInfoInRegCase = 5; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that CELLULAR_RAT_EDGE case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_RAT_EDGE( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + /* CELLULAR_RAT_EDGE case. */ + parseRatInfoInRegCase = 8; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that CELLULAR_REG_POS_RAT CELLULAR_RAT_LTE case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_POS_RAT_Status_CELLULAR_RAT_LTE( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRatInfoInRegCase = 2; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that CELLULAR_REG_TYPE_CEREG clear atlib data case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Clear_AtLib_Data( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRegStatusCase = 4; + parseRatInfoInRegCase = 6; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that CELLULAR_REG_TYPE_CEREG status registration denied case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Registration_Denied( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRegStatusCase = 3; + packetStatus = _Cellular_ParseRegStatus( &context, "+CEREG: 2", false, CELLULAR_REG_TYPE_CEREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); +} + +/** + * @brief Test that CELLULAR_REG_TYPE_CEREG status registration roaming case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CEREG_Status_Registration_Roaming( void ) { CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; CellularContext_t context; @@ -732,10 +1304,156 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CGREG_Happy_Path( void ) Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRegType = CELLULAR_REG_TYPE_CGREG; packetStatus = _Cellular_ParseRegStatus( &context, "+CGREG: 2", false, CELLULAR_REG_TYPE_CGREG ); TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); } +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling LAC. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_LAC( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseLacTacInRegCase = 3; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling Cell ID. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_CellId( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseCellIdInRegCase = 2; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling RAT info. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_RatInfo( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRatInfoInRegCase = 7; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling reject type. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_RejectType( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRejectTypeInRegCase = 4; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling reject cause. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_RejectCause( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRejectCauseInRegCase = 4; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CREG: 2", false, CELLULAR_REG_TYPE_CREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + +/** + * @brief Test that atoi fail case _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_FAILURE + * while handling routing area code. + */ +void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_CREG_Invalid_Rac( void ) +{ + CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + + context.cbEvents.networkRegistrationCallback = cellularUrcNetworkRegistrationCallback; + _Cellular_NetworkRegistrationCallback_Ignore(); + Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATRemoveAllWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS ); + Cellular_ATGetNextTok_StubWithCallback( Mock_Cellular_ATGetNextTok_Callback ); + Cellular_ATStrtoi_StubWithCallback( Mock_Cellular_ATStrtoi_Callback ); + _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); + parseRacInfoInRegCase = 3; + parseRegType = CELLULAR_REG_TYPE_CGREG; + + packetStatus = _Cellular_ParseRegStatus( &context, "+CGREG: 2", false, CELLULAR_REG_TYPE_CGREG ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_FAILURE, packetStatus ); +} + /** * @brief Test that CELLULAR_REG_TYPE_UNKNOWN case for _Cellular_ParseRegStatus to return CELLULAR_PKT_STATUS_OK. * @@ -754,7 +1472,7 @@ void test_Cellular_ParseRegStatus_CELLULAR_REG_TYPE_UNKNOWN( void ) _Cellular_TranslateAtCoreStatus_StubWithCallback( Mock__Cellular_TranslateAtCoreStatus_Callback ); packetStatus = _Cellular_ParseRegStatus( &context, "123456789", false, CELLULAR_REG_TYPE_UNKNOWN ); - TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, packetStatus ); + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_BAD_PARAM, packetStatus ); } /**