Skip to content

Commit 883f1d9

Browse files
Mirela Chiricaadbridge
authored andcommitted
Cellular: Added UT for case when read_string buff size hits middle of stop tag
1 parent d47f18a commit 883f1d9

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ TEST_F(TestATHandler, test_ATHandler_read_string)
716716
at.resp_start("s");
717717
// TO read from: ss\rsss -> read all 6 chars ss\rsss
718718
EXPECT_TRUE(6 == at.read_string(buf4, 6 + 1/*for NULL*/));
719+
at.resp_stop();
719720

720721
// *** Reading when buffer only has " ***
721722
at.clear_error();
@@ -729,6 +730,7 @@ TEST_F(TestATHandler, test_ATHandler_read_string)
729730
// TO read from buffer having only " -> trying to find delimiter or stop_tag(OKCRLF)
730731
EXPECT_TRUE(-1 == at.read_string(buf4, 5));
731732
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
733+
at.resp_stop();
732734

733735
// *** Reading through partially matching stop tag ***
734736
at.clear_error();
@@ -760,10 +762,10 @@ TEST_F(TestATHandler, test_ATHandler_read_string)
760762
EXPECT_TRUE(6 == at.read_string(buf9, 6 + 1/*for NULL*/));
761763

762764
at.clear_error();
763-
char table11[] = "\"1016\",\"39AB\",9\r\n\0";
765+
char table10[] = "\"1016\",\"39AB\",9\r\n\0";
764766
mbed_poll_stub::int_value = 0;
765767
at.flush();
766-
filehandle_stub_table = table11;
768+
filehandle_stub_table = table10;
767769
filehandle_stub_table_pos = 0;
768770
mbed_poll_stub::revents_value = POLLIN;
769771
mbed_poll_stub::int_value = 1;
@@ -776,19 +778,46 @@ TEST_F(TestATHandler, test_ATHandler_read_string)
776778

777779
// *** CRLF part of the string ***
778780
at.clear_error();
779-
char table10[] = "\"s\"\r\nOK\r\n\0";
781+
char table11[] = "\"s\"\r\nOK\r\n\0";
780782
mbed_poll_stub::int_value = 0;
781783
at.flush();
782-
filehandle_stub_table = table10;
784+
filehandle_stub_table = table11;
783785
filehandle_stub_table_pos = 0;
784786
mbed_poll_stub::revents_value = POLLIN;
785787
mbed_poll_stub::int_value = 1;
786-
char buf10[10];
788+
char buf11[10];
787789

788790
// NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read
789791
at.resp_start();
790792
// TO read from
791-
EXPECT_TRUE(3 == at.read_string(buf10, 9 + 1/*for NULL*/));
793+
EXPECT_TRUE(3 == at.read_string(buf11, 9 + 1/*for NULL*/));
794+
795+
// *** Read size hits in the middle of stop tag ***
796+
at.clear_error();
797+
char table12[] = "abcdOK\r\nefg\r\n\0";
798+
mbed_poll_stub::int_value = 0;
799+
at.flush();
800+
filehandle_stub_table = table12;
801+
filehandle_stub_table_pos = 0;
802+
mbed_poll_stub::revents_value = POLLIN;
803+
mbed_poll_stub::int_value = 1;
804+
char buf12[7];
805+
806+
at.resp_start();
807+
// Read size hits in the middle of OKCRLF
808+
EXPECT_TRUE(4 == at.read_string(buf12, 7));
809+
EXPECT_TRUE(!strncmp(buf12, "abcd", 4));
810+
// Not running into time out
811+
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
812+
// No error -> -1 returned because stop tag found already
813+
EXPECT_TRUE(-1 == at.read_string(buf12, 1));
814+
815+
at.resp_stop();
816+
at.resp_start();
817+
EXPECT_TRUE(3 == at.read_string(buf12, 4));
818+
EXPECT_TRUE(!strncmp(buf12, "efg", 3));
819+
// No stop tag found
820+
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
792821
}
793822

794823
TEST_F(TestATHandler, test_ATHandler_read_hex_string)

0 commit comments

Comments
 (0)