File tree 2 files changed +50
-0
lines changed
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ set(TEST_SRCS
52
52
src/Stream/test_getTimeout.cpp
53
53
src/Stream/test_parseFloat.cpp
54
54
src/Stream/test_parseInt.cpp
55
+ src/Stream/test_readBytes.cpp
55
56
src/Stream/test_readString.cpp
56
57
src/Stream/test_readStringUntil.cpp
57
58
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
+
25
+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == 0 );
26
+ }
27
+
28
+ WHEN (" the stream contains less data then we want to read" )
29
+ {
30
+ char buf[32 ] = {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 );
36
+ REQUIRE (mock.readString () == arduino::String (" " ));
37
+ }
38
+
39
+ WHEN (" the stream contains more data then we want to read" )
40
+ {
41
+ char buf[5 ] = {0 };
42
+ mock << " some stream content" ;
43
+ char const EXPECTED_STR[] = " some " ;
44
+
45
+ REQUIRE (mock.readBytes (buf, sizeof (buf)) == 5 );
46
+ REQUIRE (strncmp (buf, EXPECTED_STR, sizeof (buf)) == 0 );
47
+ REQUIRE (mock.readString () == arduino::String (" stream content" ));
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments