Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6a55a8

Browse files
committed
Adding StreamMock class to test functions of Stream base class as well as test code for Stream::getTimeout()
1 parentf2dcfc4 commitb6a55a8

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

‎test/include/StreamMock.h‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
#ifndef STREAM_MOCK_H_
6+
#defineSTREAM_MOCK_H_
7+
8+
/**************************************************************************************
9+
* INCLUDE
10+
**************************************************************************************/
11+
12+
#include<sstream>
13+
14+
#include<Stream.h>
15+
16+
/**************************************************************************************
17+
* CLASS DECLARATION
18+
**************************************************************************************/
19+
20+
classStreamMock :publicarduino::Stream
21+
{
22+
public:
23+
std::stringstream _ss;
24+
25+
virtualsize_twrite(uint8_t ch)override { _ss <<static_cast<char>(ch);return1; }
26+
virtualintavailable()override {return _ss.gcount(); }
27+
virtualintread()override
28+
{
29+
char ch;
30+
_ss >> ch;
31+
return ch;
32+
}
33+
virtualintpeek()override
34+
{
35+
char ch = _ss.peek();
36+
return ch;
37+
}
38+
};
39+
40+
#endif/* STREAM_MOCK_H_*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp