|
52 | 52 | #define CELLULAR_AT_MULTI_DATA_WO_PREFIX_STRING_RESP "+QIRD: 32\r123243154354364576587utrhfgdghfg"
|
53 | 53 | #define CELLULAR_URC_TOKEN_STRING_INPUT "RDY"
|
54 | 54 | #define CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS "+RDY"
|
| 55 | +#define CELLULAR_URC_TOKEN_STRING_INPUT_WITH_PAYLOAD "+RDY:START" |
55 | 56 | #define CELLULAR_URC_TOKEN_STRING_GREATER_INPUT "RDYY"
|
56 | 57 | #define CELLULAR_URC_TOKEN_STRING_SMALLER_INPUT "RD"
|
57 | 58 | #define CELLULAR_PLUS_TOKEN_ONLY_STRING "+"
|
@@ -327,6 +328,38 @@ uint16_t MockvQueueDelete( QueueHandle_t queue )
|
327 | 328 | return 1;
|
328 | 329 | }
|
329 | 330 |
|
| 331 | +CellularATError_t Cellular_ATIsPrefixPresent( const char * pString, |
| 332 | + bool * pResult ) |
| 333 | +{ |
| 334 | + CellularATError_t atStatus = CELLULAR_AT_SUCCESS; |
| 335 | + |
| 336 | + TEST_ASSERT( pString != NULL ); |
| 337 | + TEST_ASSERT( pResult != NULL ); |
| 338 | + |
| 339 | + if( strcmp( pString, CELLULAR_AT_MULTI_DATA_WO_PREFIX_STRING_RESP ) == 0 ) |
| 340 | + { |
| 341 | + *pResult = true; |
| 342 | + } |
| 343 | + else if( strcmp( pString, CELLULAR_PLUS_TOKEN_ONLY_STRING ) == 0 ) |
| 344 | + { |
| 345 | + *pResult = true; |
| 346 | + } |
| 347 | + else if( strcmp( pString, CELLULAR_URC_TOKEN_STRING_INPUT_WITH_PAYLOAD ) == 0 ) |
| 348 | + { |
| 349 | + *pResult = true; |
| 350 | + } |
| 351 | + else if( strcmp( pString, CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS ) == 0 ) |
| 352 | + { |
| 353 | + *pResult = false; |
| 354 | + } |
| 355 | + else |
| 356 | + { |
| 357 | + *pResult = false; |
| 358 | + } |
| 359 | + |
| 360 | + return atStatus; |
| 361 | +} |
| 362 | + |
330 | 363 | CellularATError_t _CMOCK_Cellular_ATStrDup_CALLBACK( char ** ppDst,
|
331 | 364 | const char * pSrc,
|
332 | 365 | int cmock_num_calls )
|
@@ -623,10 +656,45 @@ void test__Cellular_HandlePacket_AT_UNSOLICITED_Happy_Path( void )
|
623 | 656 |
|
624 | 657 | /* set for cellularAtParseTokenHandler function */
|
625 | 658 | passCompareString = false;
|
626 |
| - pCompareString = getStringAfterColon( CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS ); |
| 659 | + pCompareString = getStringAfterColon( CELLULAR_URC_TOKEN_STRING_INPUT_WITH_PAYLOAD ); |
| 660 | + |
| 661 | + pktStatus = _Cellular_HandlePacket( &context, AT_UNSOLICITED, CELLULAR_URC_TOKEN_STRING_INPUT_WITH_PAYLOAD ); |
| 662 | + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); |
| 663 | + TEST_ASSERT_EQUAL( true, passCompareString ); |
| 664 | +} |
| 665 | + |
| 666 | +/** |
| 667 | + * @brief Test input string without payload for _Cellular_HandlePacket. |
| 668 | + * |
| 669 | + * URC input string "+RDY" should be regarded as URC without prefix. |
| 670 | + * If there is a handler function registered in the table, the handler function is |
| 671 | + * called with pInputStr point to "+RDY" string. |
| 672 | + */ |
| 673 | +void test__Cellular_HandlePacket_AT_UNSOLICITED_Input_String_without_payload( void ) |
| 674 | +{ |
| 675 | + CellularContext_t context; |
| 676 | + CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; |
| 677 | + CellularAtParseTokenMap_t cellularTestUrcHandlerTable[] = |
| 678 | + { |
| 679 | + /* Use the URC string instead of the URC prefix in the mapping table. */ |
| 680 | + { CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS, cellularAtParseTokenHandler } |
| 681 | + }; |
| 682 | + |
| 683 | + memset( &context, 0, sizeof( CellularContext_t ) ); |
| 684 | + context.tokenTable.pCellularUrcHandlerTable = cellularTestUrcHandlerTable; |
| 685 | + context.tokenTable.cellularPrefixToParserMapSize = 1; |
| 686 | + |
| 687 | + Cellular_ATStrDup_StubWithCallback( _CMOCK_Cellular_ATStrDup_CALLBACK ); |
| 688 | + |
| 689 | + /* set for cellularAtParseTokenHandler function */ |
| 690 | + passCompareString = false; |
| 691 | + pCompareString = CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS; |
627 | 692 |
|
628 | 693 | pktStatus = _Cellular_HandlePacket( &context, AT_UNSOLICITED, CELLULAR_URC_TOKEN_STRING_INPUT_START_PLUS );
|
629 | 694 | TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
|
| 695 | + |
| 696 | + /* passCompareString is set to true in cellularAtParseTokenHandler if pCompareString |
| 697 | + * equals to parameter pInputStr. */ |
630 | 698 | TEST_ASSERT_EQUAL( true, passCompareString );
|
631 | 699 | }
|
632 | 700 |
|
|
0 commit comments