29
29
using namespace mbed ;
30
30
using namespace events ;
31
31
32
+ uint8_t urc_callback_count;
33
+
32
34
void urc_callback ()
33
35
{
36
+ urc_callback_count++;
34
37
}
35
38
36
39
void urc2_callback ()
@@ -44,6 +47,7 @@ class TestATHandler : public testing::Test {
44
47
45
48
void SetUp ()
46
49
{
50
+ urc_callback_count = 0 ;
47
51
}
48
52
49
53
void TearDown ()
@@ -954,16 +958,19 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
954
958
filehandle_stub_table_pos = 0 ;
955
959
at.resp_start ();
956
960
957
- char table7[] = " urc: info\r\n responseOK \r\n\0 " ;
961
+ char table7[] = " urc: info\r\n response \r\n OK \r\n\0 " ;
958
962
at.flush ();
959
963
at.clear_error ();
960
964
filehandle_stub_table = table7;
961
965
filehandle_stub_table_pos = 0 ;
962
966
963
- at.set_urc_handler (" urc: " , NULL );
967
+ mbed::Callback<void ()> cb1 (&urc_callback);
968
+ at.set_urc_handler (" urc: " , cb1);
964
969
at.resp_start (); // recv_buff: "responseOK\r\n\0"
965
970
at.resp_stop (); // consumes to OKCRLF -> OK
966
971
EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_OK);
972
+ EXPECT_TRUE (urc_callback_count == 1 );
973
+ urc_callback_count = 0 ;
967
974
968
975
char table8[] = " urc: info\r\n response\0 " ;
969
976
at.flush ();
@@ -1060,8 +1067,21 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
1060
1067
filehandle_stub_table = table3;
1061
1068
filehandle_stub_table_pos = 0 ;
1062
1069
at.resp_start ();
1070
+ at.resp_stop ();
1071
+
1072
+ // Set stop tag for response to CRLF -> resp stop should stop on first CRLF
1073
+ char table6[] = " line1\r\n line2\r\n OK\r\n " ;
1074
+ filehandle_stub_table = table6;
1075
+ filehandle_stub_table_pos = 0 ;
1063
1076
1077
+ at.flush ();
1078
+ at.clear_error ();
1079
+ filehandle_stub_table_pos = 0 ;
1080
+
1081
+ at.resp_start ();
1082
+ at.set_stop_tag (" \r\n " );
1064
1083
at.resp_stop ();
1084
+ EXPECT_TRUE (at.get_last_error () == NSAPI_ERROR_OK);
1065
1085
1066
1086
char table7[] = " ssssss\0 " ;
1067
1087
filehandle_stub_table = table7;
@@ -1072,6 +1092,38 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
1072
1092
filehandle_stub_table_pos = 0 ;
1073
1093
at.resp_start (" ss" , false );
1074
1094
at.resp_stop ();
1095
+
1096
+ // prefix + URC line + some other line + URC line + URC line + OKCRLF
1097
+ char table4[] = " line1\r\n line2abcd\r\n line3abcd\r\n line4\r\n\r\n line3\r\n line3\r\n OK\r\n " ;
1098
+ filehandle_stub_table = table4;
1099
+ filehandle_stub_table_pos = 0 ;
1100
+
1101
+ at.flush ();
1102
+ at.clear_error ();
1103
+ filehandle_stub_table_pos = 0 ;
1104
+ mbed::Callback<void ()> cb1 (&urc_callback);
1105
+ at.set_urc_handler (" line3" , cb1);
1106
+
1107
+ at.resp_start (" line2" );
1108
+ at.resp_stop ();
1109
+ EXPECT_TRUE (urc_callback_count == 3 );
1110
+ urc_callback_count = 0 ;
1111
+
1112
+ // URC line + prefix + URC line + some other line + URC line + URC line + some other line + OKCRLF
1113
+ char table5[] = " line1\r\n line3\r\n line2abcd\r\n line3abcd\r\n line4\r\n\r\n line3\r\n line3\r\n line4\r\n OK\r\n " ;
1114
+ filehandle_stub_table = table5;
1115
+ filehandle_stub_table_pos = 0 ;
1116
+
1117
+ at.flush ();
1118
+ at.clear_error ();
1119
+ filehandle_stub_table_pos = 0 ;
1120
+ mbed::Callback<void ()> cb2 (&urc_callback);
1121
+ at.set_urc_handler (" line3" , cb2);
1122
+
1123
+ at.resp_start (" line2" );
1124
+ at.resp_stop ();
1125
+ EXPECT_TRUE (urc_callback_count == 4 );
1126
+ urc_callback_count = 0 ;
1075
1127
}
1076
1128
1077
1129
TEST_F (TestATHandler, test_ATHandler_info_resp)
0 commit comments