-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathtest_insertion_operator.cpp
53 lines (41 loc) · 1.58 KB
/
test_insertion_operator.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <StreamMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing 'Format' initialisation", "[Stream-insertion-operator-01]") {
arduino::Format<char> fmt {'a', 2};
REQUIRE(fmt.data == 'a');
REQUIRE(fmt.modifier == 2);
}
TEST_CASE ("Testing 'format' helper function", "[Stream-insertion-operator-02]") {
arduino::Format<char> fmt {arduino::format('a', 2)};
REQUIRE(fmt.data == 'a');
REQUIRE(fmt.modifier == 2);
}
TEST_CASE ("Testing basic insertion operator", "[Stream-insertion-operator-03]") {
StreamMock mock;
mock << 'a' << 12 << 'b' << 34; // Note we cannot test C strings because `StreamMock` has its own << operator.
REQUIRE(mock.available() == 6);
char buf[10] {};
mock.readBytes(buf, 6);
REQUIRE(not strncmp(buf, "a12b34", 6));
}
TEST_CASE ("Testing insertion operator with modifiers", "[Stream-insertion-operator-04]") {
StreamMock mock;
mock << arduino::format(1.2, 4);
REQUIRE(mock.available() == 6);
char buf[10] {};
mock.readBytes(buf, 6);
REQUIRE(not strncmp(buf, "1.2000", 6));
mock << arduino::format(12, BIN);
REQUIRE(mock.available() == 4);
mock.readBytes(buf, 4);
REQUIRE(not strncmp(buf, "1100", 4));
}