@@ -460,7 +460,7 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
460
460
fh1.short_value = POLLIN;
461
461
at.resp_start ();
462
462
at.skip_param ();
463
- EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR );
463
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_OK );
464
464
465
465
char table1[] = " ss,sssssssssssss,sssssssssssOK\r\n\0 " ;
466
466
filehandle_stub_table = table1;
@@ -935,15 +935,88 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
935
935
filehandle_stub_table_pos = 0 ;
936
936
at.resp_start ();
937
937
938
- char table7[] = " ssssss\0 " ;
938
+ char table7[] = " urc: info\r\n responseOK\r\n\0 " ;
939
+ at.flush ();
940
+ at.clear_error ();
939
941
filehandle_stub_table = table7;
940
942
filehandle_stub_table_pos = 0 ;
941
943
944
+ at.set_urc_handler (" urc: " , NULL );
945
+ at.resp_start (); // recv_buff: "responseOK\r\n\0"
946
+ at.resp_stop (); // consumes to OKCRLF -> OK
947
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_OK);
948
+
949
+ char table8[] = " urc: info\r\n response\0 " ;
950
+ at.flush ();
951
+ at.clear_error ();
952
+ filehandle_stub_table = table8;
953
+ filehandle_stub_table_pos = 0 ;
954
+
955
+ at.set_urc_handler (" urc: " , NULL );
956
+ at.resp_start ();
957
+ at.resp_stop ();
958
+ // No stop tag(OKCRLF) found
959
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR);
960
+
961
+ char table9[] = " urc: prefix: infoOK\r\n\0 " ;
942
962
at.flush ();
943
963
at.clear_error ();
944
- at. set_urc_handler ( " ss " , NULL ) ;
964
+ filehandle_stub_table = table9 ;
945
965
filehandle_stub_table_pos = 0 ;
966
+
967
+ at.set_urc_handler (" urc: " , NULL );
946
968
at.resp_start ();
969
+ // Match URC consumes to CRLF -> nothing to read after that -> ERROR
970
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR);
971
+
972
+ char table10[] = " urc: info\r\n garbage\r\n prefix: info\r\n OK\r\n\0 " ;
973
+ at.flush ();
974
+ at.clear_error ();
975
+ filehandle_stub_table = table10;
976
+ filehandle_stub_table_pos = 0 ;
977
+
978
+ at.set_urc_handler (" urc: " , NULL );
979
+ at.resp_start (" prefix" ); // match URC -> consumes to first CRLF -> consumes the garbage because there is expected prefix and no match found -> then prefix match
980
+ at.resp_stop (); // ends the info scope -> consumes to CRLF -> ends the resp scope -> consumes to OKCRLF
981
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_OK);
982
+
983
+ // No stop tag(OKCRLF) will be found because, after match URC consumed everything to CRLF, rest of buffer
984
+ // is consumed to next/last CRLF because there is expected prefix and no match found
985
+ // -> nothing to read after that -> ERROR
986
+ char table11[] = " urc: info\r\n garbageprefix: infoOK\r\n\0 " ;
987
+ at.flush ();
988
+ at.clear_error ();
989
+ filehandle_stub_table = table11;
990
+ filehandle_stub_table_pos = 0 ;
991
+
992
+ at.set_urc_handler (" urc: " , NULL );
993
+ at.resp_start (" prefix" );
994
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR);
995
+
996
+ // After URC match no prefix match -> try to read more -> no more to read
997
+ char table12[] = " urc: infoprefix: info\0 " ;
998
+ at.flush ();
999
+ at.clear_error ();
1000
+ filehandle_stub_table = table12;
1001
+ filehandle_stub_table_pos = 0 ;
1002
+
1003
+ at.set_urc_handler (" urc: " , NULL );
1004
+ at.resp_start (" prefix" );
1005
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR);
1006
+
1007
+ // Will run into mem_str check of identical strings
1008
+ char table13[] = " \r\n\r\n\0 " ;
1009
+ at.flush ();
1010
+ at.clear_error ();
1011
+ filehandle_stub_table = table13;
1012
+ filehandle_stub_table_pos = 0 ;
1013
+
1014
+ char buf[3 ];
1015
+ at.resp_start ();
1016
+ EXPECT_TRUE (2 == at.read_string (buf, 3 ));
1017
+ EXPECT_TRUE (!strncmp (buf, " \r\n " , 2 ));
1018
+ // Consume to delimiter or stop_tag OKCRLF fails -> ERROR
1019
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_DEVICE_ERROR);
947
1020
}
948
1021
949
1022
TEST_F (TestATHandler, test_ATHandler_resp_stop)
0 commit comments