@@ -21,22 +21,29 @@ TEST_CASE ("Testing readBytes(char *buffer, size_t length)", "[Stream-readBytes-
2121 WHEN (" the stream is empty" )
2222 {
2323 char buf[32 ] = {0 };
24+
2425 REQUIRE (mock.readBytes (buf, sizeof (buf)) == 0 );
2526 }
27+
2628 WHEN (" the stream contains less data then we want to read" )
2729 {
28- mock << " some stream content" ;
2930 char buf[32 ] = {0 };
30- REQUIRE (mock.readBytes (buf, sizeof (buf)) == strlen (" some stream content" ));
31- REQUIRE (strcmp (buf, " some stream content" ) == 0 );
31+ char const str[] = " some stream content" ;
32+ mock << str;
33+
34+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == strlen (str));
35+ REQUIRE (strncmp (buf, str, sizeof (buf)) == 0 );
3236 REQUIRE (mock.readString () == arduino::String (" " ));
3337 }
34- WHEN (" the stream contains more data then we want to read" )
38+
39+ WHEN (" the stream contains more data then we want to read" )
3540 {
36- mock << " some stream content" ;
3741 char buf[5 ] = {0 };
42+ mock << " some stream content" ;
43+ char const EXPECTED_STR[] = " some " ;
44+
3845 REQUIRE (mock.readBytes (buf, sizeof (buf)) == 5 );
39- REQUIRE (strcmp (buf, " some " ) == 0 );
46+ REQUIRE (strncmp (buf, EXPECTED_STR, sizeof (buf) ) == 0 );
4047 REQUIRE (mock.readString () == arduino::String (" stream content" ));
4148 }
4249}
0 commit comments