File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ set(TEST_SRCS
4747 src/Ringbuffer/test_peek.cpp
4848 src/Ringbuffer/test_read_char.cpp
4949 src/Ringbuffer/test_store_char.cpp
50+ src/Stream/test_getTimeout.cpp
5051 src/String /test_concat.cpp
5152 src/String /test_operators.cpp
5253 src/String /test_compareTo.cpp
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 Arduino. All rights reserved.
3+ */
4+
5+ #ifndef STREAM_MOCK_H_
6+ #define STREAM_MOCK_H_
7+
8+ /* *************************************************************************************
9+ * INCLUDE
10+ **************************************************************************************/
11+
12+ #include < sstream>
13+
14+ #include < Stream.h>
15+
16+ /* *************************************************************************************
17+ * CLASS DECLARATION
18+ **************************************************************************************/
19+
20+ class StreamMock : public arduino ::Stream
21+ {
22+ public:
23+ std::stringstream _ss;
24+
25+ virtual size_t write (uint8_t ch) override { _ss << static_cast <char >(ch); return 1 ; }
26+ virtual int available () override { return _ss.gcount (); }
27+ virtual int read () override
28+ {
29+ char ch;
30+ _ss >> ch;
31+ return ch;
32+ }
33+ virtual int peek () override
34+ {
35+ char ch = _ss.peek ();
36+ return ch;
37+ }
38+ };
39+
40+ #endif /* STREAM_MOCK_H_ */
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 (" Verifying if default timeout is returned correctly" , " [Stream-getTimeout-01]" )
18+ {
19+ StreamMock mock;
20+ REQUIRE (mock.getTimeout () == 1000 );
21+ }
You can’t perform that action at this time.
0 commit comments