File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ set(TEST_SRCS
5252 src/Stream/test_getTimeout.cpp
5353 src/Stream/test_parseFloat.cpp
5454 src/Stream/test_parseInt.cpp
55+ src/Stream/test_readBytes.cpp
5556 src/Stream/test_readString.cpp
5657 src/Stream/test_readStringUntil.cpp
5758 src/Stream/test_setTimeout.cpp
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 Arduino. All rights reserved.
3+ */
4+
5+ /* *************************************************************************************
6+ * INCLUDE
7+ **************************************************************************************/
8+
9+ #include < catch.hpp>
10+
11+ #include < StreamMock.h>
12+
13+ /* *************************************************************************************
14+ * TEST CODE
15+ **************************************************************************************/
16+
17+ TEST_CASE (" Testing readBytes(char *buffer, size_t length)" , " [Stream-readBytes-01]" )
18+ {
19+ StreamMock mock;
20+
21+ WHEN (" the stream is empty" )
22+ {
23+ char buf[32 ] = {0 };
24+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == 0 );
25+ }
26+ WHEN (" the stream contains less data then we want to read" )
27+ {
28+ mock << " some stream content" ;
29+ char buf[32 ] = {0 };
30+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == strlen (" some stream content" ));
31+ REQUIRE (strcmp (buf, " some stream content" ) == 0 );
32+ REQUIRE (mock.readString () == arduino::String (" " ));
33+ }
34+ WHEN (" the stream contains more data then we want to read" )
35+ {
36+ mock << " some stream content" ;
37+ char buf[5 ] = {0 };
38+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == 5 );
39+ REQUIRE (strcmp (buf, " some " ) == 0 );
40+ REQUIRE (mock.readString () == arduino::String (" stream content" ));
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments