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

Appearance settings

Commit b47dfdf

Browse filesBrowse files
committed
[core][utest] fix Print/test_print.cpp
1 parent cbe8ed9 commit b47dfdf
Copy full SHA for b47dfdf

File tree

Expand file treeCollapse file tree

5 files changed

+76
-67
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+76
-67
lines changed

‎core/utest/Print/mock/PrintMock.h

Copy file name to clipboardExpand all lines: core/utest/Print/mock/PrintMock.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class PrintMock : public Print
2323
{
2424
public:
2525
String _str;
26-
size_t write(uint8_t b) { _str += static_cast<char>(b); return 1;};
26+
void flush() { _str = String(); }
27+
size_t write(uint8_t b) { _str += static_cast<char>(b); return 1; };
2728
void mock_setWriteError() { setWriteError(); }
2829
void mock_setWriteError(int err) { setWriteError(err); }
2930
};

‎core/utest/Print/test_print.cpp

Copy file name to clipboardExpand all lines: core/utest/Print/test_print.cpp
+59-51Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ TEST_CASE ("Print::print(char)", "[Print-print-01]")
1313
PrintMock mock;
1414

1515
mock.print('A');
16-
1716
REQUIRE(mock._str == "A");
17+
mock.flush();
1818
}
1919

2020
TEST_CASE ("Print::print(const String &)", "[Print-print-02]")
@@ -23,8 +23,8 @@ TEST_CASE ("Print::print(const String &)", "[Print-print-02]")
2323
String const str("Test String");
2424

2525
mock.print(str);
26-
2726
REQUIRE(mock._str == "Test String");
27+
mock.flush();
2828
}
2929

3030
TEST_CASE ("Print::print(const char str[])", "[Print-print-03]")
@@ -33,8 +33,8 @@ TEST_CASE ("Print::print(const char str[])", "[Print-print-03]")
3333
const char str[] = "Test String";
3434

3535
mock.print(str);
36-
3736
REQUIRE(mock._str == "Test String");
37+
mock.flush();
3838
}
3939

4040
TEST_CASE ("Print::print(int, int = DEC|HEX|OCT|BIN)", "[Print-print-04]")
@@ -43,58 +43,66 @@ TEST_CASE ("Print::print(int, int = DEC|HEX|OCT|BIN)", "[Print-print-04]")
4343

4444
int const val = -1;
4545

46-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); }
47-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); }
48-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); }
49-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); }
46+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); mock.flush(); }
47+
#ifdef ARCH_CPU_64BIT
48+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); mock.flush(); }
49+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); mock.flush(); }
50+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); mock.flush(); }
51+
#else
52+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFF"); mock.flush(); }
53+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "37777777777"); mock.flush(); }
54+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "11111111111111111111111111111111"); mock.flush(); }
55+
#endif /* ARCH_CPU_64BIT */
5056
}
5157

5258
TEST_CASE ("Print::print(unsigned int, int = DEC|HEX|OCT|BIN)", "[Print-print-05]")
5359
{
5460
PrintMock mock;
55-
5661
unsigned int const val = 17;
5762

58-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); }
59-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); }
60-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
61-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
63+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); mock.flush(); }
64+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); mock.flush(); }
65+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); mock.flush(); }
66+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); mock.flush(); }
6267
}
6368

6469
TEST_CASE ("Print::print(long, int = DEC|HEX|OCT|BIN)", "[Print-print-06]")
6570
{
6671
PrintMock mock;
67-
6872
long const val = -1;
6973

70-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); }
71-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); }
72-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); }
73-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); }
74+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); mock.flush(); }
75+
#ifdef ARCH_CPU_64BIT
76+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); mock.flush(); }
77+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); mock.flush(); }
78+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); mock.flush(); }
79+
#else
80+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFF"); mock.flush(); }
81+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "37777777777"); mock.flush(); }
82+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "11111111111111111111111111111111"); mock.flush(); }
83+
#endif /* ARCH_CPU_64BIT */
7484
}
7585

7686
TEST_CASE ("Print::print(unsigned long, int = DEC|HEX|OCT|BIN)", "[Print-print-07]")
7787
{
7888
PrintMock mock;
79-
8089
unsigned long const val = 17;
8190

82-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); }
83-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); }
84-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
85-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
91+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); mock.flush(); }
92+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); mock.flush(); }
93+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); mock.flush(); }
94+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); mock.flush(); }
8695
}
8796

8897
TEST_CASE ("Print::print(long long, int = DEC|HEX|OCT|BIN)", "[Print-print-08]")
8998
{
9099
PrintMock mock;
91-
92100
long long const val = -1;
93101

94-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); }
95-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); }
96-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); }
97-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); }
102+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); mock.flush(); }
103+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); mock.flush(); }
104+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); mock.flush(); }
105+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); mock.flush(); }
98106
}
99107

100108
TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-print-09]")
@@ -105,19 +113,19 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr
105113
{
106114
unsigned long long const val = 0;
107115

108-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); }
109-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); }
110-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); }
111-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); }
116+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); mock.flush(); }
117+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); mock.flush(); }
118+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); mock.flush(); }
119+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); mock.flush(); }
112120
}
113121
GIVEN("a non-zero value ...")
114122
{
115123
unsigned long long const val = 17;
116124

117-
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); }
118-
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); }
119-
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
120-
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
125+
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); mock.flush(); }
126+
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); mock.flush(); }
127+
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); mock.flush(); }
128+
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); mock.flush(); }
121129
}
122130
}
123131

@@ -128,28 +136,28 @@ TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]")
128136
WHEN ("val is a positive floating point value")
129137
{
130138
double const val = 3.1459;
131-
WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); }
132-
WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); }
133-
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); }
134-
WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); }
135-
WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); }
136-
WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); }
139+
WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); mock.flush(); }
140+
WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); mock.flush(); }
141+
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); mock.flush(); }
142+
WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); mock.flush(); }
143+
WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); mock.flush(); }
144+
WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); mock.flush(); }
137145
}
138146

139147
WHEN ("digits are negative")
140148
{
141149
double const val = 3.1459;
142-
WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); }
150+
WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); mock.flush(); }
143151
}
144152

145153
WHEN ("val is a negative floating point value")
146154
{
147155
double const val = -3.1459;
148-
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); }
156+
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); mock.flush(); }
149157
}
150158

151-
WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); }
152-
WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); }
159+
WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); mock.flush(); }
160+
WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); mock.flush(); }
153161
}
154162

155163
TEST_CASE ("Print::print(Printable)", "[Print-print-11]")
@@ -160,18 +168,18 @@ TEST_CASE ("Print::print(Printable)", "[Print-print-11]")
160168
printable._i = 1;
161169

162170
mock.print(printable);
163-
164171
REQUIRE(mock._str == "PrintableMock i = 1");
172+
mock.flush();
165173
}
166174

167175
TEST_CASE ("Print::print(unsigned char, int)", "[Print-print-12]")
168176
{
169177
PrintMock mock;
170178

171-
WHEN("DEC") { mock.print('A', DEC); REQUIRE(mock._str == "65"); }
172-
WHEN("HEX") { mock.print('A', HEX); REQUIRE(mock._str == "41"); }
173-
WHEN("OCT") { mock.print('A', OCT); REQUIRE(mock._str == "101"); }
174-
WHEN("BIN") { mock.print('A', BIN); REQUIRE(mock._str == "1000001"); }
179+
WHEN("DEC") { mock.print('A', DEC); REQUIRE(mock._str == "65"); mock.flush(); }
180+
WHEN("HEX") { mock.print('A', HEX); REQUIRE(mock._str == "41"); mock.flush(); }
181+
WHEN("OCT") { mock.print('A', OCT); REQUIRE(mock._str == "101"); mock.flush(); }
182+
WHEN("BIN") { mock.print('A', BIN); REQUIRE(mock._str == "1000001"); mock.flush(); }
175183
}
176184

177185
TEST_CASE ("Testing Print::print(const __FlashStringHelper *)", "[Print-print-13]")
@@ -181,6 +189,6 @@ TEST_CASE ("Testing Print::print(const __FlashStringHelper *)", "[Print-print-13
181189
PrintMock mock;
182190

183191
mock.print(F("Hello flash string"));
184-
185192
REQUIRE(mock._str == "Hello flash string");
193+
mock.flush();
186194
}

‎core/utest/Print/test_println.cpp

Copy file name to clipboardExpand all lines: core/utest/Print/test_println.cpp
+13-13Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ TEST_CASE ("Print::println(char)", "[Print-println-01]")
1313
PrintMock mock;
1414

1515
mock.println('A');
16-
1716
REQUIRE(mock._str == "A\r\n");
17+
mock.flush();
1818
}
1919

2020
TEST_CASE ("Print::println(const String &)", "[Print-println-02]")
@@ -23,8 +23,8 @@ TEST_CASE ("Print::println(const String &)", "[Print-println-02]")
2323
String const str("Test String");
2424

2525
mock.println(str);
26-
2726
REQUIRE(mock._str == "Test String\r\n");
27+
mock.flush();
2828
}
2929

3030
TEST_CASE ("Print::println(const char str[])", "[Print-println-03]")
@@ -33,8 +33,8 @@ TEST_CASE ("Print::println(const char str[])", "[Print-println-03]")
3333
const char str[] = "Test String";
3434

3535
mock.println(str);
36-
3736
REQUIRE(mock._str == "Test String\r\n");
37+
mock.flush();
3838
}
3939

4040
TEST_CASE ("Print::println(int, int = DEC (default))", "[Print-println-04]")
@@ -43,8 +43,8 @@ TEST_CASE ("Print::println(int, int = DEC (default))", "[Print-println-04]")
4343
int const val = -1;
4444

4545
mock.println(val);
46-
4746
REQUIRE(mock._str == "-1\r\n");
47+
mock.flush();
4848
}
4949

5050
TEST_CASE ("Print::println(unsigned int, int = DEC (default))", "[Print-println-05]")
@@ -53,8 +53,8 @@ TEST_CASE ("Print::println(unsigned int, int = DEC (default))", "[Print-println-
5353
unsigned int const val = 17;
5454

5555
mock.println(val);
56-
5756
REQUIRE(mock._str == "17\r\n");
57+
mock.flush();
5858
}
5959

6060
TEST_CASE ("Print::println(long, int = DEC (default))", "[Print-println-06]")
@@ -63,8 +63,8 @@ TEST_CASE ("Print::println(long, int = DEC (default))", "[Print-println-06]")
6363
long const val = -1;
6464

6565
mock.println(val);
66-
6766
REQUIRE(mock._str == "-1\r\n");
67+
mock.flush();
6868
}
6969

7070
TEST_CASE ("Print::println(unsigned long, int = DEC (default))", "[Print-println-07]")
@@ -73,8 +73,8 @@ TEST_CASE ("Print::println(unsigned long, int = DEC (default))", "[Print-println
7373
unsigned long const val = 17;
7474

7575
mock.println(val);
76-
7776
REQUIRE(mock._str == "17\r\n");
77+
mock.flush();
7878
}
7979

8080
TEST_CASE ("Print::println(long long, int = DEC (default))", "[Print-println-08]")
@@ -83,8 +83,8 @@ TEST_CASE ("Print::println(long long, int = DEC (default))", "[Print-println-08]
8383
long long const val = -1;
8484

8585
mock.println(val);
86-
8786
REQUIRE(mock._str == "-1\r\n");
87+
mock.flush();
8888
}
8989

9090
TEST_CASE ("Print::println(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-println-09]")
@@ -93,8 +93,8 @@ TEST_CASE ("Print::println(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-
9393
unsigned long long const val = 17;
9494

9595
mock.println(val);
96-
9796
REQUIRE(mock._str == "17\r\n");
97+
mock.flush();
9898
}
9999

100100
TEST_CASE ("Print::println(double, int = 2)", "[Print-println-10]")
@@ -103,8 +103,8 @@ TEST_CASE ("Print::println(double, int = 2)", "[Print-println-10]")
103103
double const val = 3.1459;
104104

105105
mock.println(val);
106-
107106
REQUIRE(mock._str == "3.15\r\n");
107+
mock.flush();
108108
}
109109

110110
TEST_CASE ("Print::println(Printable)", "[Print-println-11]")
@@ -114,17 +114,17 @@ TEST_CASE ("Print::println(Printable)", "[Print-println-11]")
114114
printable._i = 1;
115115

116116
mock.println(printable);
117-
118117
REQUIRE(mock._str == "PrintableMock i = 1\r\n");
118+
mock.flush();
119119
}
120120

121121
TEST_CASE ("Print::println(unsigned char, int base = DEC (default))", "[Print-println-12]")
122122
{
123123
PrintMock mock;
124124

125125
mock.println('A', DEC);
126-
127126
REQUIRE(mock._str == "65\r\n");
127+
mock.flush();
128128
}
129129

130130
TEST_CASE ("Testing Print::println(const __FlashStringHelper *)", "[Print-println-13]")
@@ -134,6 +134,6 @@ TEST_CASE ("Testing Print::println(const __FlashStringHelper *)", "[Print-printl
134134
PrintMock mock;
135135

136136
mock.println(F("Hello flash string"));
137-
138137
REQUIRE(mock._str == "Hello flash string\r\n");
138+
mock.flush();
139139
}

‎core/utest/TC_Print.cpp

Copy file name to clipboardExpand all lines: core/utest/TC_Print.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void TC_getWriteError(void)
3737

3838
static void TC_print(void)
3939
{
40-
// #include "Print/test_print.cpp"
40+
#include "Print/test_print.cpp"
4141
}
4242

4343
static void TC_println(void)

‎core/utest/catch_compatible.h

Copy file name to clipboardExpand all lines: core/utest/catch_compatible.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <utest.h>
1818

19-
#define TEST_CASE(name, tags) LOG_I("[==========] [ TESTCASE ] %s", name);
19+
#define TEST_CASE(name, tags) LOG_I("[==========] %s %s", tags, name);
2020
#define WHEN(name) LOG_I("[==========] [ WHEN ] %s", name);
2121
#define THEN(name) LOG_I("[==========] [ THEN ] %s", name);
2222
#define GIVEN(name) LOG_I("[==========] [ GIVEN ] %s", name);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.