forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream.cpp
72 lines (58 loc) · 1.37 KB
/
stream.cpp
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
#include <ArduinoUnitTests.h>
#include <Arduino.h>
unittest(stream_construction)
{
String data = "";
unsigned long micros = 100;
Stream s;
s.mGodmodeDataIn = &data;
s.mGodmodeMicrosDelay = µs;
assertEqual(0, s.available());
data = "abcd";
assertEqual(4, s.available());
assertEqual('a', s.peek());
assertEqual('a', s.read());
assertEqual("bcd", s.readString());
assertEqual("", s.readString());
}
unittest(stream_find)
{
String data = "";
unsigned long micros = 100;
Stream s;
s.mGodmodeDataIn = &data;
s.mGodmodeMicrosDelay = µs;
data = "abcdefghijkl";
assertEqual('a', s.peek());
assertEqual(true, s.find('f'));
assertEqual('f', s.peek());
assertEqual("fghijkl", s.readString());
data = "fghijkl";
assertEqual(false, s.findUntil("k", "j"));
assertEqual('j', s.peek());
}
unittest(stream_parse)
{
String data = "";
unsigned long micros = 100;
Stream s;
s.mGodmodeDataIn = &data;
s.mGodmodeMicrosDelay = µs;
long l;
float f;
data = "abcdefghijkl-123-456abcd";
l = s.parseInt();
assertEqual(-123, l);
assertEqual('-', data[0]);
l = s.parseInt();
assertEqual(-456, l);
l = s.parseInt();
assertEqual(0, l);
data = "abc123.456-345.322";
f = s.parseFloat();
assertLess(123.456 - f, 0.0001);
assertEqual('-', data[0]);
f = s.parseFloat();
assertLess(-345.322 - f, 0.0001);
}
unittest_main()