Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\sensorlogger-tests.cpp
Line
Count
Source
1
//  Copyright 2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "test-templates.h"
6
7
#include "catch.hpp"
8
9
#include <string>
10
11
#include "herald/herald.h"
12
13
1
TEST_CASE("sensorlogger-output-dbg", "[sensorlogger][output]") {
14
1
  SECTION("sensorlogger-output-dbg") {
15
1
    DummyLoggingSink dls;
16
1
    DummyBluetoothStateManager dbsm;
17
1
    herald::DefaultPlatformType dpt;
18
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
19
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
20
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
21
1
22
1
    HTDBG("Simple string");
23
1
    std::string r("testout,mytest,Simple string");
24
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
25
1
26
1
    HTDBG("There are {} strings","two");
27
1
    r = "testout,mytest,There are two strings";
28
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
29
1
30
1
    HTDBG("There are {} strings",2);
31
1
    r = "testout,mytest,There are 2 strings";
32
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
33
1
34
1
    const char* cc = "some const char";
35
1
    HTDBG("There are {} const chars",cc);
36
1
    r = "testout,mytest,There are some const char const chars";
37
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
38
1
39
1
    HTDBG("There are two params 1: {} and 2: {} and some more text", 15, 45);
40
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text";
41
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
42
1
43
1
    HTDBG("There are two params 1: {} and 2: {} and some more text {} <- but this is blank", 15, 45);
44
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text  <- but this is blank";
45
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
46
1
47
1
    HTDBG("Too few {} parameters",15,45);
48
1
    r = "testout,mytest,Too few 15 parameters";
49
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
50
1
  }
51
1
}
52
53
1
TEST_CASE("sensorlogger-output-log", "[sensorlogger][output]") {
54
1
  SECTION("sensorlogger-output-log") {
55
1
    DummyLoggingSink dls;
56
1
    DummyBluetoothStateManager dbsm;
57
1
    herald::DefaultPlatformType dpt;
58
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
59
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
60
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
61
1
62
1
    HTLOG("Simple string");
63
1
    std::string r("testout,mytest,Simple string");
64
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
65
1
66
1
    HTLOG("There are {} strings","two");
67
1
    r = "testout,mytest,There are two strings";
68
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
69
1
70
1
    HTLOG("There are {} strings",2);
71
1
    r = "testout,mytest,There are 2 strings";
72
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
73
1
74
1
    HTLOG("There are two params 1: {} and 2: {} and some more text", 15, 45);
75
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text";
76
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
77
1
78
1
    HTLOG("There are two params 1: {} and 2: {} and some more text {} <- but this is blank", 15, 45);
79
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text  <- but this is blank";
80
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
81
1
82
1
    HTLOG("Too few {} parameters",15,45);
83
1
    r = "testout,mytest,Too few 15 parameters";
84
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
85
1
  }
86
1
}
87
88
1
TEST_CASE("sensorlogger-output-fault", "[sensorlogger][output]") {
89
1
  SECTION("sensorlogger-output-fault") {
90
1
    DummyLoggingSink dls;
91
1
    DummyBluetoothStateManager dbsm;
92
1
    herald::DefaultPlatformType dpt;
93
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
94
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
95
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
96
1
97
1
    HTERR("Simple string");
98
1
    std::string r("testout,mytest,Simple string");
99
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
100
1
101
1
    HTERR("There are {} strings","two");
102
1
    r = "testout,mytest,There are two strings";
103
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
104
1
105
1
    HTERR("There are {} strings",2);
106
1
    r = "testout,mytest,There are 2 strings";
107
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
108
1
109
1
    HTERR("There are two params 1: {} and 2: {} and some more text", 15, 45);
110
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text";
111
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
112
1
113
1
    HTERR("There are two params 1: {} and 2: {} and some more text {} <- but this is blank", 15, 45);
114
1
    r = "testout,mytest,There are two params 1: 15 and 2: 45 and some more text  <- but this is blank";
115
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
116
1
117
1
    HTERR("Too few {} parameters",15,45);
118
1
    r = "testout,mytest,Too few 15 parameters";
119
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
120
1
  }
121
1
}
122
123
124
1
TEST_CASE("sensorlogger-output-intrinsic", "[sensorlogger][output]") {
125
1
  SECTION("sensorlogger-output-intrinsic") {
126
1
    DummyLoggingSink dls;
127
1
    DummyBluetoothStateManager dbsm;
128
1
    herald::DefaultPlatformType dpt;
129
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
130
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
131
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
132
1
133
1
    int i = 37;
134
1
    HTLOG("Intrinsic {} type",i);
135
1
    std::string r("testout,mytest,Intrinsic 37 type");
136
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
137
1
138
1
    std::uint8_t ui8 = 39;
139
1
    HTLOG("Intrinsic {} type",ui8);
140
1
    r = "testout,mytest,Intrinsic 39 type";
141
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
142
1
143
1
    std::size_t st = 128;
144
1
    HTLOG("Intrinsic {} type",st);
145
1
    r = "testout,mytest,Intrinsic 128 type";
146
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
147
1
148
1
    std::uint16_t ui16 = 3737;
149
1
    HTLOG("Intrinsic {} type",ui16);
150
1
    r = "testout,mytest,Intrinsic 3737 type";
151
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
152
1
153
1
    std::uint32_t ui32 = 373737;
154
1
    HTLOG("Intrinsic {} type",ui32);
155
1
    r = "testout,mytest,Intrinsic 373737 type";
156
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
157
1
158
1
    std::uint32_t ui64 = 3737373737;
159
1
    HTLOG("Intrinsic {} type",ui64);
160
1
    r = "testout,mytest,Intrinsic 3737373737 type";
161
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
162
1
163
1
    std::int8_t i8 = -39;
164
1
    HTLOG("Intrinsic {} type",i8);
165
1
    r = "testout,mytest,Intrinsic -39 type";
166
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
167
1
168
1
    std::int16_t i16 = -3737;
169
1
    HTLOG("Intrinsic {} type",i16);
170
1
    r = "testout,mytest,Intrinsic -3737 type";
171
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
172
1
173
1
    std::int32_t i32 = -373737;
174
1
    HTLOG("Intrinsic {} type",i32);
175
1
    r = "testout,mytest,Intrinsic -373737 type";
176
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
177
1
178
1
    std::int32_t i64 = -37373737;
179
1
    HTLOG("Intrinsic {} type",i64);
180
1
    r = "testout,mytest,Intrinsic -37373737 type";
181
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
182
1
  }
183
1
}
184
185
186
1
TEST_CASE("sensorlogger-bug-negativesuccess", "[sensorlogger][output][bug]") {
187
1
  SECTION("sensorlogger-bug-negativesuccess") {
188
1
    DummyLoggingSink dls;
189
1
    DummyBluetoothStateManager dbsm;
190
1
    herald::DefaultPlatformType dpt;
191
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
192
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
193
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
194
1
195
1
    int success = -22;
196
1
    HTDBG(" - Issue connecting: {}",success);
197
1
    std::string r("testout,mytest, - Issue connecting: -22");
198
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
199
1
  }
200
1
}
201
202
203
1
TEST_CASE("sensorlogger-bug-targetidatend", "[sensorlogger][output][bug]") {
204
1
  SECTION("sensorlogger-bug-targetidatend") {
205
1
    DummyLoggingSink dls;
206
1
    DummyBluetoothStateManager dbsm;
207
1
    herald::DefaultPlatformType dpt;
208
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
209
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
210
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
211
1
212
1
    herald::datatype::TargetIdentifier t(herald::datatype::Data(std::byte(0x09),3));
213
1
214
1
    HTLOG("Complex {}",t);
215
1
    std::string r("testout,mytest,Complex 090909");
216
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
217
1
  }
218
1
}
219
220
221
1
TEST_CASE("sensorlogger-output-data", "[sensorlogger][output]") {
222
1
  SECTION("sensorlogger-output-data") {
223
1
    DummyLoggingSink dls;
224
1
    DummyBluetoothStateManager dbsm;
225
1
    herald::DefaultPlatformType dpt;
226
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
227
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
228
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
229
1
230
1
    herald::datatype::Data t(std::byte(0x09),3);
231
1
232
1
    HTLOG("Complex {} type",t);
233
1
    std::string r("testout,mytest,Complex 090909 type");
234
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
235
1
  }
236
1
}
237
238
239
1
TEST_CASE("sensorlogger-output-targetidentifier", "[sensorlogger][output]") {
240
1
  SECTION("sensorlogger-output-targetidentifier") {
241
1
    DummyLoggingSink dls;
242
1
    DummyBluetoothStateManager dbsm;
243
1
    herald::DefaultPlatformType dpt;
244
1
    herald::Context ctx(dpt,dls,dbsm); // default context include
245
1
    // using CT = typename herald::Context<herald::DefaultPlatformType,DummyLoggingSink,DummyBluetoothStateManager>;
246
1
    herald::data::SensorLogger logger(ctx.getLoggingSink(),"testout","mytest");
247
1
248
1
    herald::datatype::TargetIdentifier t(herald::datatype::Data(std::byte(0x09),3));
249
1
250
1
    std::string r("testout,mytest,Complex 090909 type");
251
1
    HTLOG("Complex {} type",t);
252
1
    REQUIRE(strcmp(r.c_str(),dls.value.c_str()) == 0);
253
1
  }
254
1
}