@@ -194,11 +194,24 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback( CellularContext_t * pContext,
194194 CellularAtReq_t atReq ,
195195 int cmock_num_calls )
196196{
197- cellularOperatorInfo_t * pOperatorInfo = ( cellularOperatorInfo_t * ) atReq . pData ;
197+ cellularOperatorInfo_t * pOperatorInfo ;
198198
199199 ( void ) pContext ;
200- ( void ) cmock_num_calls ;
201- pOperatorInfo -> rat = CELLULAR_RAT_INVALID ;
200+
201+ if ( cmock_num_calls == 0 )
202+ {
203+ /* AT+COPS=3,2 call. */
204+ }
205+ else if ( cmock_num_calls == 1 )
206+ {
207+ /* AT+COPS? call. */
208+ pOperatorInfo = ( cellularOperatorInfo_t * ) atReq .pData ;
209+ pOperatorInfo -> rat = CELLULAR_RAT_INVALID ;
210+ }
211+ else
212+ {
213+ TEST_FAIL_MESSAGE ( "Unexpected Mock_AtcmdRequestWithCallback call" );
214+ }
202215
203216 return CELLULAR_PKT_STATUS_OK ;
204217}
@@ -643,35 +656,46 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback__Cellular_RecvFuncUpdateMccMnc
643656 CellularATCommandResponse_t atResp ;
644657 cellularOperatorInfo_t cellularOperatorInfo ;
645658
646- ( void ) cmock_num_calls ;
647659 memset ( & atResp , 0 , sizeof ( CellularATCommandResponse_t ) );
648660 memset ( & cellularOperatorInfo , 0 , sizeof ( cellularOperatorInfo_t ) );
649661
650- if ( cbCondition < 3 )
662+ if ( cmock_num_calls == 0 )
651663 {
652- pktStatus = handleCommonCallback ( pContext , atReq );
664+ /* AT+COPS=3,2 call. */
653665 }
654- else if ( cbCondition == 3 )
666+ else if ( cmock_num_calls == 1 )
655667 {
656- char pLine [] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT ;
657-
658- _saveData ( pLine , & atResp , strlen ( pLine ) + 1 );
659-
660- if ( parseNetworkNameFailureCase == 2 )
661- {
662- cellularOperatorInfo .operatorNameFormat = OPERATOR_NAME_FORMAT_LONG ;
663- pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
664- }
665- else if ( parseNetworkNameFailureCase == 3 )
668+ /* AT+COPS? call. */
669+ if ( cbCondition < 3 )
666670 {
667- cellularOperatorInfo .operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC ;
668- pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
671+ pktStatus = handleCommonCallback ( pContext , atReq );
669672 }
670- else
673+ else if ( cbCondition == 3 )
671674 {
672- pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
675+ char pLine [] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT ;
676+
677+ _saveData ( pLine , & atResp , strlen ( pLine ) + 1 );
678+
679+ if ( parseNetworkNameFailureCase == 2 )
680+ {
681+ cellularOperatorInfo .operatorNameFormat = OPERATOR_NAME_FORMAT_LONG ;
682+ pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
683+ }
684+ else if ( parseNetworkNameFailureCase == 3 )
685+ {
686+ cellularOperatorInfo .operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC ;
687+ pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
688+ }
689+ else
690+ {
691+ pktStatus = atReq .respCallback ( pContext , & atResp , & cellularOperatorInfo , sizeof ( cellularOperatorInfo_t ) );
692+ }
673693 }
674694 }
695+ else
696+ {
697+ TEST_FAIL_MESSAGE ( "Unexpected Mock_AtcmdRequestWithCallback call" );
698+ }
675699
676700 return pktStatus ;
677701}
@@ -2016,6 +2040,44 @@ void test_Cellular_CommonGetRegisteredNetwork_No_Memory( void )
20162040 TEST_ASSERT_EQUAL ( CELLULAR_NO_MEMORY , cellularStatus );
20172041}
20182042
2043+ /**
2044+ * @brief Test that set to numeric format failed.
2045+ *
2046+ * <b>Coverage</b>
2047+ * @code{c}
2048+ * static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
2049+ * cellularOperatorInfo_t * pOperatorInfo )
2050+ * {
2051+ * ...
2052+ * atCopsRequest.pAtCmd = "AT+COPS=3,2",
2053+ * atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
2054+ * pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
2055+ *
2056+ * if( pktStatus == CELLULAR_PKT_STATUS_OK )
2057+ * {
2058+ * ...
2059+ * }
2060+ * }
2061+ * @endcode
2062+ * ( pktStatus == CELLULAR_PKT_STATUS_OK ) is false.
2063+ */
2064+ void test_Cellular_CommonGetRegisteredNetwork_Set_Numeric_Format_Fail ( void )
2065+ {
2066+ CellularError_t cellularStatus = CELLULAR_SUCCESS ;
2067+ CellularContext_t context ;
2068+
2069+ memset ( & context , 0 , sizeof ( CellularContext_t ) );
2070+ CellularHandle_t cellularHandle = & context ;
2071+ CellularPlmnInfo_t networkInfo ;
2072+
2073+ _Cellular_CheckLibraryStatus_IgnoreAndReturn ( CELLULAR_SUCCESS );
2074+ _Cellular_AtcmdRequestWithCallback_IgnoreAndReturn ( CELLULAR_PKT_STATUS_FAILURE );
2075+ _Cellular_TranslatePktStatus_ExpectAndReturn ( CELLULAR_PKT_STATUS_FAILURE , CELLULAR_INTERNAL_FAILURE );
2076+
2077+ cellularStatus = Cellular_CommonGetRegisteredNetwork ( cellularHandle , & networkInfo );
2078+ TEST_ASSERT_EQUAL ( CELLULAR_INTERNAL_FAILURE , cellularStatus );
2079+ }
2080+
20192081/**
20202082 * @brief Test that invalid rat case Cellular_CommonGetRegisteredNetwork to return CELLULAR_UNKNOWN.
20212083 */
0 commit comments