-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPrint64Test.ino
107 lines (82 loc) · 2.44 KB
/
Print64Test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#line 2 "Print64Test.ino"
#include <AUnit.h>
#include <aunit/fake/FakePrint.h>
using namespace aunit;
using namespace aunit::fake;
using namespace aunit::internal;
test(Print64, fakePrint) {
FakePrint fakePrint;
fakePrint.print('a');
assertEqual("a", fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print("01234567890123456789");
assertEqual("01234567890123456789", fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print(123);
assertEqual("123", fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print(10, 16);
assertEqual("A", fakePrint.getBuffer());
fakePrint.flush();
// Don't know why print() for base==0 just prints out the lower 8-bits,
// but that's what we need to assert.
fakePrint.print(256 + 'A', 0);
assertEqual("A", fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print(-1, 16);
const char* expected = (sizeof(long) == 8) ? "FFFFFFFFFFFFFFFF" : "FFFFFFFF";
assertEqual(expected, fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print(INT32_MIN);
assertEqual("-2147483648", fakePrint.getBuffer());
fakePrint.flush();
fakePrint.print(-20.5);
assertEqual("-20.50", fakePrint.getBuffer());
fakePrint.flush();
}
test(Print64, print64_LL) {
FakePrint fakePrint;
print64(fakePrint, 1LL);
assertEqual("1", fakePrint.getBuffer());
fakePrint.flush();
print64(fakePrint, -1LL);
assertEqual("-1", fakePrint.getBuffer());
fakePrint.flush();
print64(fakePrint, -1LL, 16);
assertEqual("FFFFFFFFFFFFFFFF", fakePrint.getBuffer());
fakePrint.flush();
}
test(Print64, println64_LL) {
FakePrint fakePrint;
println64(fakePrint, 1LL);
assertEqual("1\r\n", fakePrint.getBuffer());
fakePrint.flush();
}
test(Print64, print64_ULL) {
FakePrint fakePrint;
print64(fakePrint, 1ULL);
assertEqual("1", fakePrint.getBuffer());
fakePrint.flush();
print64(fakePrint, 0x1234567890123456ULL, 16);
assertEqual("1234567890123456", fakePrint.getBuffer());
fakePrint.flush();
}
test(Print64, println64_ULL) {
FakePrint fakePrint;
println64(fakePrint, 1ULL);
assertEqual("1\r\n", fakePrint.getBuffer());
fakePrint.flush();
}
void setup() {
#if ! defined(EPOXY_DUINO)
delay(1000); // Wait for stability on some boards, otherwise garage on Serial
#endif
SERIAL_PORT_MONITOR.begin(115200);
while (! SERIAL_PORT_MONITOR); // Wait until Serial is ready - Leonardo
#if defined(EPOXY_DUINO)
SERIAL_PORT_MONITOR.setLineModeUnix();
#endif
}
void loop() {
TestRunner::run();
}