Skip to content

Commit 369aad4

Browse files
committed
Adding basic tests for 'Print::getWriteError'
1 parent 9c3efec commit 369aad4

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(TEST_SRCS
2828
src/Common/test_makeWord.cpp
2929
src/Common/test_max.cpp
3030
src/Common/test_min.cpp
31+
src/Print/test_getWriteError.cpp
3132
src/Print/test_print.cpp
3233
src/Ringbuffer/test_available.cpp
3334
src/Ringbuffer/test_availableForStore.cpp

Diff for: test/include/PrintMock.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class PrintMock : public Print
2222
public:
2323
std::string _str;
2424
virtual size_t write(uint8_t b) override;
25+
void mock_setWriteError() { setWriteError(); }
26+
void mock_setWriteError(int err) { setWriteError(err); }
2527
};
2628

2729
#endif /* PRINT_MOCK_H_ */

Diff for: test/src/Print/test_getWriteError.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <Print.h>
12+
13+
#include <PrintMock.h>
14+
15+
/**************************************************************************************
16+
* TEST CODE
17+
**************************************************************************************/
18+
19+
TEST_CASE ("No write error has been set", "[Print-getWriteError-01]")
20+
{
21+
PrintMock mock;
22+
REQUIRE(mock.getWriteError() == 0);
23+
}
24+
25+
TEST_CASE ("A write error has been set", "[Print-getWriteError-02]")
26+
{
27+
PrintMock mock;
28+
mock.mock_setWriteError(5);
29+
REQUIRE(mock.getWriteError() == 5);
30+
}

Diff for: test/src/Print/test_print.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include <catch.hpp>
1010

11-
#include <string>
12-
1311
#include <Print.h>
1412

1513
#include <PrintMock.h>

0 commit comments

Comments
 (0)