1 #include "utils.hpp"
2
3 #include <nlohmann/json.hpp>
4
5 #include <string>
6 #include <variant>
7
8 #include "gtest/gtest.h"
9
10 using namespace std::string_literals;
11
TEST(TemplateCharReplace,replaceOneInt)12 TEST(TemplateCharReplace, replaceOneInt)
13 {
14 nlohmann::json j = {{"foo", "$bus"}};
15 auto it = j.begin();
16 DBusInterface data;
17 data["BUS"] = 23;
18
19 templateCharReplace(it, data, 0);
20
21 nlohmann::json expected = 23;
22 EXPECT_EQ(expected, j["foo"]);
23 }
24
TEST(TemplateCharReplace,replaceOneStr)25 TEST(TemplateCharReplace, replaceOneStr)
26 {
27 nlohmann::json j = {{"foo", "$TEST"}};
28 auto it = j.begin();
29 DBusInterface data;
30 data["TEST"] = std::string("Test");
31
32 templateCharReplace(it, data, 0);
33
34 nlohmann::json expected = "Test";
35 EXPECT_EQ(expected, j["foo"]);
36 }
37
TEST(TemplateCharReplace,replaceSecondStr)38 TEST(TemplateCharReplace, replaceSecondStr)
39 {
40 nlohmann::json j = {{"foo", "the $TEST"}};
41 auto it = j.begin();
42 DBusInterface data;
43 data["TEST"] = std::string("Test");
44
45 templateCharReplace(it, data, 0);
46
47 nlohmann::json expected = "the Test";
48 EXPECT_EQ(expected, j["foo"]);
49 }
50
TEST(TemplateCharReplace,replaceMiddleStr)51 TEST(TemplateCharReplace, replaceMiddleStr)
52 {
53 nlohmann::json j = {{"foo", "the $TEST worked"}};
54 auto it = j.begin();
55 DBusInterface data;
56 data["TEST"] = std::string("Test");
57
58 templateCharReplace(it, data, 0);
59
60 nlohmann::json expected = "the Test worked";
61 EXPECT_EQ(expected, j["foo"]);
62 }
63
TEST(TemplateCharReplace,replaceLastStr)64 TEST(TemplateCharReplace, replaceLastStr)
65 {
66 nlohmann::json j = {{"foo", "the Test $TEST"}};
67 auto it = j.begin();
68 DBusInterface data;
69 data["TEST"] = 23;
70
71 templateCharReplace(it, data, 0);
72
73 nlohmann::json expected = "the Test 23";
74 EXPECT_EQ(expected, j["foo"]);
75 }
76
TEST(TemplateCharReplace,increment)77 TEST(TemplateCharReplace, increment)
78 {
79 nlohmann::json j = {{"foo", "3 plus 1 equals $TEST + 1"}};
80 auto it = j.begin();
81 DBusInterface data;
82 data["TEST"] = 3;
83
84 templateCharReplace(it, data, 0);
85
86 nlohmann::json expected = "3 plus 1 equals 4";
87 EXPECT_EQ(expected, j["foo"]);
88 }
89
TEST(TemplateCharReplace,decrement)90 TEST(TemplateCharReplace, decrement)
91 {
92 nlohmann::json j = {{"foo", "3 minus 1 equals $TEST - 1 !"}};
93 auto it = j.begin();
94 DBusInterface data;
95 data["TEST"] = 3;
96
97 templateCharReplace(it, data, 0);
98
99 nlohmann::json expected = "3 minus 1 equals 2 !";
100 EXPECT_EQ(expected, j["foo"]);
101 }
102
TEST(TemplateCharReplace,modulus)103 TEST(TemplateCharReplace, modulus)
104 {
105 nlohmann::json j = {{"foo", "3 mod 2 equals $TEST % 2"}};
106 auto it = j.begin();
107 DBusInterface data;
108 data["TEST"] = 3;
109
110 templateCharReplace(it, data, 0);
111
112 nlohmann::json expected = "3 mod 2 equals 1";
113 EXPECT_EQ(expected, j["foo"]);
114 }
115
TEST(TemplateCharReplace,multiply)116 TEST(TemplateCharReplace, multiply)
117 {
118 nlohmann::json j = {{"foo", "3 * 2 equals $TEST * 2"}};
119 auto it = j.begin();
120 DBusInterface data;
121 data["TEST"] = 3;
122
123 templateCharReplace(it, data, 0);
124
125 nlohmann::json expected = "3 * 2 equals 6";
126 EXPECT_EQ(expected, j["foo"]);
127 }
128
TEST(TemplateCharReplace,divide)129 TEST(TemplateCharReplace, divide)
130 {
131 nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2"}};
132 auto it = j.begin();
133 DBusInterface data;
134 data["TEST"] = 4;
135
136 templateCharReplace(it, data, 0);
137
138 nlohmann::json expected = "4 / 2 equals 2";
139 EXPECT_EQ(expected, j["foo"]);
140 }
141
TEST(TemplateCharReplace,multiMath)142 TEST(TemplateCharReplace, multiMath)
143 {
144 nlohmann::json j = {{"foo", "4 * 2 % 6 equals $TEST * 2 % 6"}};
145 auto it = j.begin();
146 DBusInterface data;
147 data["TEST"] = 4;
148
149 templateCharReplace(it, data, 0);
150
151 nlohmann::json expected = "4 * 2 % 6 equals 2";
152 EXPECT_EQ(expected, j["foo"]);
153 }
154
TEST(TemplateCharReplace,twoReplacements)155 TEST(TemplateCharReplace, twoReplacements)
156 {
157 nlohmann::json j = {{"foo", "$FOO $BAR"}};
158 auto it = j.begin();
159 DBusInterface data;
160 data["FOO"] = std::string("foo");
161 data["BAR"] = std::string("bar");
162
163 templateCharReplace(it, data, 0);
164
165 nlohmann::json expected = "foo bar";
166 EXPECT_EQ(expected, j["foo"]);
167 }
168
TEST(TemplateCharReplace,twoReplacementsWithMath)169 TEST(TemplateCharReplace, twoReplacementsWithMath)
170 {
171 nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2 $BAR"}};
172 auto it = j.begin();
173 DBusInterface data;
174 data["TEST"] = 4;
175 data["BAR"] = std::string("bar");
176
177 templateCharReplace(it, data, 0);
178
179 nlohmann::json expected = "4 / 2 equals 2 bar";
180 }
181
TEST(TemplateCharReplace,twoReplacementsWithMath2)182 TEST(TemplateCharReplace, twoReplacementsWithMath2)
183 {
184 nlohmann::json j = {{"foo", "4 / 2 equals $ADDRESS / 2 $BAR"}};
185 auto it = j.begin();
186 DBusInterface data;
187 data["ADDRESS"] = 4;
188 data["BAR"] = std::string("bar");
189
190 templateCharReplace(it, data, 0);
191
192 nlohmann::json expected = "4 / 2 equals 2 bar";
193 EXPECT_EQ(expected, j["foo"]);
194 }
195
TEST(TemplateCharReplace,hexAndWrongCase)196 TEST(TemplateCharReplace, hexAndWrongCase)
197 {
198 nlohmann::json j = {{"Address", "0x54"},
199 {"Bus", 15},
200 {"Name", "$bus sensor 0"},
201 {"Type", "SomeType"}};
202
203 DBusInterface data;
204 data["BUS"] = 15;
205
206 for (auto it = j.begin(); it != j.end(); it++)
207 {
208 templateCharReplace(it, data, 0);
209 }
210 nlohmann::json expected = {{"Address", 84},
211 {"Bus", 15},
212 {"Name", "15 sensor 0"},
213 {"Type", "SomeType"}};
214 EXPECT_EQ(expected, j);
215 }
216
TEST(TemplateCharReplace,replaceSecondAsInt)217 TEST(TemplateCharReplace, replaceSecondAsInt)
218 {
219 nlohmann::json j = {{"foo", "twelve is $TEST"}};
220 auto it = j.begin();
221 DBusInterface data;
222 data["test"] = 12;
223
224 templateCharReplace(it, data, 0);
225
226 nlohmann::json expected = "twelve is 12";
227 EXPECT_EQ(expected, j["foo"]);
228 }
229
TEST(TemplateCharReplace,singleHex)230 TEST(TemplateCharReplace, singleHex)
231 {
232 nlohmann::json j = {{"foo", "0x54"}};
233 auto it = j.begin();
234 DBusInterface data;
235
236 templateCharReplace(it, data, 0);
237
238 nlohmann::json expected = 84;
239 EXPECT_EQ(expected, j["foo"]);
240 }
241
TEST(MatchProbe,stringEqString)242 TEST(MatchProbe, stringEqString)
243 {
244 nlohmann::json j = R"("foo")"_json;
245 DBusValueVariant v = "foo"s;
246 EXPECT_TRUE(matchProbe(j, v));
247 }
248
TEST(MatchProbe,stringRegexEqString)249 TEST(MatchProbe, stringRegexEqString)
250 {
251 nlohmann::json j = R"("foo*")"_json;
252 DBusValueVariant v = "foobar"s;
253 EXPECT_TRUE(matchProbe(j, v));
254 }
255
TEST(MatchProbe,stringNeqString)256 TEST(MatchProbe, stringNeqString)
257 {
258 nlohmann::json j = R"("foobar")"_json;
259 DBusValueVariant v = "foo"s;
260 EXPECT_FALSE(matchProbe(j, v));
261 }
262
TEST(MatchProbe,stringRegexError)263 TEST(MatchProbe, stringRegexError)
264 {
265 nlohmann::json j = R"("foo[")"_json;
266 DBusValueVariant v = "foobar"s;
267 EXPECT_FALSE(matchProbe(j, v));
268 }
269
TEST(MatchProbe,stringRegexNotPrefix)270 TEST(MatchProbe, stringRegexNotPrefix)
271 {
272 nlohmann::json j = R"("foo(?!bar)...foo")"_json;
273 DBusValueVariant v1 = "foobarfoo"s;
274 DBusValueVariant v2 = "foofoofoo"s;
275 EXPECT_FALSE(matchProbe(j, v1));
276 EXPECT_TRUE(matchProbe(j, v2));
277 }
278
TEST(MatchProbe,stringZeroNeqFalse)279 TEST(MatchProbe, stringZeroNeqFalse)
280 {
281 nlohmann::json j = R"("0")"_json;
282 DBusValueVariant v = false;
283 EXPECT_FALSE(matchProbe(j, v));
284 }
285
TEST(MatchProbe,stringOneNeqTrue)286 TEST(MatchProbe, stringOneNeqTrue)
287 {
288 nlohmann::json j = R"("1")"_json;
289 DBusValueVariant v = true;
290 EXPECT_FALSE(matchProbe(j, v));
291 }
292
TEST(MatchProbe,stringElevenNeqTrue)293 TEST(MatchProbe, stringElevenNeqTrue)
294 {
295 nlohmann::json j = R"("11")"_json;
296 DBusValueVariant v = true;
297 EXPECT_FALSE(matchProbe(j, v));
298 }
299
TEST(MatchProbe,stringFalseNeqFalse)300 TEST(MatchProbe, stringFalseNeqFalse)
301 {
302 nlohmann::json j = R"("false")"_json;
303 DBusValueVariant v = false;
304 EXPECT_FALSE(matchProbe(j, v));
305 }
306
TEST(MatchProbe,stringTrueNeqTrue)307 TEST(MatchProbe, stringTrueNeqTrue)
308 {
309 nlohmann::json j = R"("true")"_json;
310 DBusValueVariant v = true;
311 EXPECT_FALSE(matchProbe(j, v));
312 }
313
TEST(MatchProbe,stringFalseNeqTrue)314 TEST(MatchProbe, stringFalseNeqTrue)
315 {
316 nlohmann::json j = R"("false")"_json;
317 DBusValueVariant v = true;
318 EXPECT_FALSE(matchProbe(j, v));
319 }
320
TEST(MatchProbe,stringNeqUint8)321 TEST(MatchProbe, stringNeqUint8)
322 {
323 nlohmann::json j = R"("255")"_json;
324 DBusValueVariant v = uint8_t(255);
325 EXPECT_FALSE(matchProbe(j, v));
326 }
327
TEST(MatchProbe,stringNeqUint8Overflow)328 TEST(MatchProbe, stringNeqUint8Overflow)
329 {
330 nlohmann::json j = R"("65535")"_json;
331 DBusValueVariant v = uint8_t(255);
332 EXPECT_FALSE(matchProbe(j, v));
333 }
334
TEST(MatchProbe,stringFalseNeqUint8Zero)335 TEST(MatchProbe, stringFalseNeqUint8Zero)
336 {
337 nlohmann::json j = R"("false")"_json;
338 DBusValueVariant v = uint8_t(0);
339 EXPECT_FALSE(matchProbe(j, v));
340 }
341
TEST(MatchProbe,stringTrueNeqUint8Zero)342 TEST(MatchProbe, stringTrueNeqUint8Zero)
343 {
344 nlohmann::json j = R"("true")"_json;
345 DBusValueVariant v = uint8_t(1);
346 EXPECT_FALSE(matchProbe(j, v));
347 }
348
TEST(MatchProbe,stringNeqUint32)349 TEST(MatchProbe, stringNeqUint32)
350 {
351 nlohmann::json j = R"("11")"_json;
352 DBusValueVariant v = uint32_t(11);
353 EXPECT_FALSE(matchProbe(j, v));
354 }
355
TEST(MatchProbe,stringNeqInt32)356 TEST(MatchProbe, stringNeqInt32)
357 {
358 nlohmann::json j = R"("-11")"_json;
359 DBusValueVariant v = int32_t(-11);
360 EXPECT_FALSE(matchProbe(j, v));
361 }
362
TEST(MatchProbe,stringRegexNeqInt32)363 TEST(MatchProbe, stringRegexNeqInt32)
364 {
365 nlohmann::json j = R"("1*4")"_json;
366 DBusValueVariant v = int32_t(124);
367 EXPECT_FALSE(matchProbe(j, v));
368 }
369
TEST(MatchProbe,stringNeqUint64)370 TEST(MatchProbe, stringNeqUint64)
371 {
372 nlohmann::json j = R"("foo")"_json;
373 DBusValueVariant v = uint64_t(65535);
374 EXPECT_FALSE(matchProbe(j, v));
375 }
376
TEST(MatchProbe,stringNeqDouble)377 TEST(MatchProbe, stringNeqDouble)
378 {
379 nlohmann::json j = R"("123.4")"_json;
380 DBusValueVariant v = double(123.4);
381 EXPECT_FALSE(matchProbe(j, v));
382 }
383
TEST(MatchProbe,stringNeqEmpty)384 TEST(MatchProbe, stringNeqEmpty)
385 {
386 nlohmann::json j = R"("-123.4")"_json;
387 DBusValueVariant v;
388 EXPECT_FALSE(matchProbe(j, v));
389 }
390
TEST(MatchProbe,stringNeqArray)391 TEST(MatchProbe, stringNeqArray)
392 {
393 nlohmann::json j = R"("-123.4")"_json;
394 DBusValueVariant v = std::vector<uint8_t>{1, 2};
395 EXPECT_FALSE(matchProbe(j, v));
396 }
397
TEST(MatchProbe,boolNeqString)398 TEST(MatchProbe, boolNeqString)
399 {
400 nlohmann::json j = R"(false)"_json;
401 DBusValueVariant v = "false"s;
402 EXPECT_FALSE(matchProbe(j, v));
403 }
404
TEST(MatchProbe,trueEqTrue)405 TEST(MatchProbe, trueEqTrue)
406 {
407 nlohmann::json j = R"(true)"_json;
408 DBusValueVariant v = true;
409 EXPECT_TRUE(matchProbe(j, v));
410 }
411
TEST(MatchProbe,falseEqFalse)412 TEST(MatchProbe, falseEqFalse)
413 {
414 nlohmann::json j = R"(false)"_json;
415 DBusValueVariant v = false;
416 EXPECT_TRUE(matchProbe(j, v));
417 }
418
TEST(MatchProbe,trueNeqFalse)419 TEST(MatchProbe, trueNeqFalse)
420 {
421 nlohmann::json j = R"(true)"_json;
422 DBusValueVariant v = false;
423 EXPECT_FALSE(matchProbe(j, v));
424 }
425
TEST(MatchProbe,trueNeqInt32Zero)426 TEST(MatchProbe, trueNeqInt32Zero)
427 {
428 nlohmann::json j = R"(true)"_json;
429 DBusValueVariant v = int32_t(0);
430 EXPECT_FALSE(matchProbe(j, v));
431 }
432
TEST(MatchProbe,trueNeqInt32NegativeOne)433 TEST(MatchProbe, trueNeqInt32NegativeOne)
434 {
435 nlohmann::json j = R"(true)"_json;
436 DBusValueVariant v = int32_t(-1);
437 EXPECT_FALSE(matchProbe(j, v));
438 }
439
TEST(MatchProbe,falseNeqUint32One)440 TEST(MatchProbe, falseNeqUint32One)
441 {
442 nlohmann::json j = R"(false)"_json;
443 DBusValueVariant v = uint32_t(1);
444 EXPECT_FALSE(matchProbe(j, v));
445 }
446
TEST(MatchProbe,falseNeqUint32Zero)447 TEST(MatchProbe, falseNeqUint32Zero)
448 {
449 nlohmann::json j = R"(false)"_json;
450 DBusValueVariant v = uint32_t(0);
451 EXPECT_FALSE(matchProbe(j, v));
452 }
453
TEST(MatchProbe,trueNeqDoubleNegativeOne)454 TEST(MatchProbe, trueNeqDoubleNegativeOne)
455 {
456 nlohmann::json j = R"(true)"_json;
457 DBusValueVariant v = double(-1.1);
458 EXPECT_FALSE(matchProbe(j, v));
459 }
460
TEST(MatchProbe,trueNeqDoubleOne)461 TEST(MatchProbe, trueNeqDoubleOne)
462 {
463 nlohmann::json j = R"(true)"_json;
464 DBusValueVariant v = double(1.0);
465 EXPECT_FALSE(matchProbe(j, v));
466 }
467
TEST(MatchProbe,falseNeqDoubleOne)468 TEST(MatchProbe, falseNeqDoubleOne)
469 {
470 nlohmann::json j = R"(false)"_json;
471 DBusValueVariant v = double(1.0);
472 EXPECT_FALSE(matchProbe(j, v));
473 }
474
TEST(MatchProbe,falseNeqDoubleZero)475 TEST(MatchProbe, falseNeqDoubleZero)
476 {
477 nlohmann::json j = R"(false)"_json;
478 DBusValueVariant v = double(0.0);
479 EXPECT_FALSE(matchProbe(j, v));
480 }
481
TEST(MatchProbe,falseNeqEmpty)482 TEST(MatchProbe, falseNeqEmpty)
483 {
484 nlohmann::json j = R"(false)"_json;
485 DBusValueVariant v;
486 EXPECT_FALSE(matchProbe(j, v));
487 }
488
TEST(MatchProbe,trueNeqEmpty)489 TEST(MatchProbe, trueNeqEmpty)
490 {
491 nlohmann::json j = R"(true)"_json;
492 DBusValueVariant v;
493 EXPECT_FALSE(matchProbe(j, v));
494 }
495
TEST(MatchProbe,trueNeqArray)496 TEST(MatchProbe, trueNeqArray)
497 {
498 nlohmann::json j = R"(true)"_json;
499 DBusValueVariant v = std::vector<uint8_t>{1, 2};
500 EXPECT_FALSE(matchProbe(j, v));
501 }
502
TEST(MatchProbe,uintNeqString)503 TEST(MatchProbe, uintNeqString)
504 {
505 nlohmann::json j = R"(11)"_json;
506 DBusValueVariant v = "11"s;
507 EXPECT_FALSE(matchProbe(j, v));
508 }
509
TEST(MatchProbe,uintNeqTrue)510 TEST(MatchProbe, uintNeqTrue)
511 {
512 nlohmann::json j = R"(1)"_json;
513 DBusValueVariant v = true;
514 EXPECT_FALSE(matchProbe(j, v));
515 }
516
TEST(MatchProbe,uintNeqFalse)517 TEST(MatchProbe, uintNeqFalse)
518 {
519 nlohmann::json j = R"(0)"_json;
520 DBusValueVariant v = false;
521 EXPECT_FALSE(matchProbe(j, v));
522 }
523
TEST(MatchProbe,uintEqUint8)524 TEST(MatchProbe, uintEqUint8)
525 {
526 nlohmann::json j = R"(11)"_json;
527 DBusValueVariant v = uint8_t(11);
528 EXPECT_TRUE(matchProbe(j, v));
529 }
530
TEST(MatchProbe,uintNeqUint8)531 TEST(MatchProbe, uintNeqUint8)
532 {
533 nlohmann::json j = R"(11)"_json;
534 DBusValueVariant v = uint8_t(12);
535 EXPECT_FALSE(matchProbe(j, v));
536 }
537
TEST(MatchProbe,uintNeqUint8Overflow)538 TEST(MatchProbe, uintNeqUint8Overflow)
539 {
540 nlohmann::json j = R"(65535)"_json;
541 DBusValueVariant v = uint8_t(255);
542 EXPECT_FALSE(matchProbe(j, v));
543 }
544
TEST(MatchProbe,uintEqInt8)545 TEST(MatchProbe, uintEqInt8)
546 {
547 nlohmann::json j = R"(11)"_json;
548 DBusValueVariant v = int8_t(11);
549 EXPECT_TRUE(matchProbe(j, v));
550 }
551
TEST(MatchProbe,uintEqDouble)552 TEST(MatchProbe, uintEqDouble)
553 {
554 nlohmann::json j = R"(11)"_json;
555 DBusValueVariant v = double(11.0);
556 EXPECT_TRUE(matchProbe(j, v));
557 }
558
TEST(MatchProbe,uintNeqDouble)559 TEST(MatchProbe, uintNeqDouble)
560 {
561 nlohmann::json j = R"(11)"_json;
562 DBusValueVariant v = double(11.7);
563 EXPECT_FALSE(matchProbe(j, v));
564 }
565
TEST(MatchProbe,uintNeqEmpty)566 TEST(MatchProbe, uintNeqEmpty)
567 {
568 nlohmann::json j = R"(11)"_json;
569 DBusValueVariant v;
570 EXPECT_FALSE(matchProbe(j, v));
571 }
572
TEST(MatchProbe,uintNeqArray)573 TEST(MatchProbe, uintNeqArray)
574 {
575 nlohmann::json j = R"(11)"_json;
576 DBusValueVariant v = std::vector<uint8_t>{11};
577 EXPECT_FALSE(matchProbe(j, v));
578 }
579
TEST(MatchProbe,intNeqString)580 TEST(MatchProbe, intNeqString)
581 {
582 nlohmann::json j = R"(-11)"_json;
583 DBusValueVariant v = "-11"s;
584 EXPECT_FALSE(matchProbe(j, v));
585 }
586
TEST(MatchProbe,intNeqTrue)587 TEST(MatchProbe, intNeqTrue)
588 {
589 nlohmann::json j = R"(-1)"_json;
590 DBusValueVariant v = true;
591 EXPECT_FALSE(matchProbe(j, v));
592 }
593
TEST(MatchProbe,intNeqUint8)594 TEST(MatchProbe, intNeqUint8)
595 {
596 nlohmann::json j = R"(-11)"_json;
597 DBusValueVariant v = uint8_t(11);
598 EXPECT_FALSE(matchProbe(j, v));
599 }
600
TEST(MatchProbe,intEqInt8)601 TEST(MatchProbe, intEqInt8)
602 {
603 nlohmann::json j = R"(-11)"_json;
604 DBusValueVariant v = int8_t(-11);
605 EXPECT_TRUE(matchProbe(j, v));
606 }
607
TEST(MatchProbe,intNeqDouble)608 TEST(MatchProbe, intNeqDouble)
609 {
610 nlohmann::json j = R"(-124)"_json;
611 DBusValueVariant v = double(-123.0);
612 EXPECT_FALSE(matchProbe(j, v));
613 }
614
TEST(MatchProbe,intEqDouble)615 TEST(MatchProbe, intEqDouble)
616 {
617 nlohmann::json j = R"(-11)"_json;
618 DBusValueVariant v = double(-11.0);
619 EXPECT_TRUE(matchProbe(j, v));
620 }
621
TEST(MatchProbe,intNeqDoubleRound)622 TEST(MatchProbe, intNeqDoubleRound)
623 {
624 nlohmann::json j = R"(-11)"_json;
625 DBusValueVariant v = double(-11.7);
626 EXPECT_FALSE(matchProbe(j, v));
627 }
628
TEST(MatchProbe,intNeqEmpty)629 TEST(MatchProbe, intNeqEmpty)
630 {
631 nlohmann::json j = R"(-11)"_json;
632 DBusValueVariant v;
633 EXPECT_FALSE(matchProbe(j, v));
634 }
635
TEST(MatchProbe,intNeqArray)636 TEST(MatchProbe, intNeqArray)
637 {
638 nlohmann::json j = R"(-11)"_json;
639 DBusValueVariant v = std::vector<uint8_t>{11};
640 EXPECT_FALSE(matchProbe(j, v));
641 }
642
TEST(MatchProbe,doubleNeqString)643 TEST(MatchProbe, doubleNeqString)
644 {
645 nlohmann::json j = R"(0.0)"_json;
646 DBusValueVariant v = "0.0"s;
647 EXPECT_FALSE(matchProbe(j, v));
648 }
649
TEST(MatchProbe,doubleNeqFalse)650 TEST(MatchProbe, doubleNeqFalse)
651 {
652 nlohmann::json j = R"(0.0)"_json;
653 DBusValueVariant v = false;
654 EXPECT_FALSE(matchProbe(j, v));
655 }
656
TEST(MatchProbe,doubleNeqTrue)657 TEST(MatchProbe, doubleNeqTrue)
658 {
659 nlohmann::json j = R"(1.0)"_json;
660 DBusValueVariant v = true;
661 EXPECT_FALSE(matchProbe(j, v));
662 }
663
TEST(MatchProbe,doubleEqInt32)664 TEST(MatchProbe, doubleEqInt32)
665 {
666 nlohmann::json j = R"(-124.0)"_json;
667 DBusValueVariant v = int32_t(-124);
668 EXPECT_TRUE(matchProbe(j, v));
669 }
670
TEST(MatchProbe,doubleNeqInt32)671 TEST(MatchProbe, doubleNeqInt32)
672 {
673 nlohmann::json j = R"(-124.0)"_json;
674 DBusValueVariant v = int32_t(-123);
675 EXPECT_FALSE(matchProbe(j, v));
676 }
677
TEST(MatchProbe,doubleRoundNeqInt)678 TEST(MatchProbe, doubleRoundNeqInt)
679 {
680 nlohmann::json j = R"(124.7)"_json;
681 DBusValueVariant v = int32_t(124);
682 EXPECT_FALSE(matchProbe(j, v));
683 }
TEST(MatchProbe,doubleEqDouble)684 TEST(MatchProbe, doubleEqDouble)
685 {
686 nlohmann::json j = R"(-124.2)"_json;
687 DBusValueVariant v = double(-124.2);
688 EXPECT_TRUE(matchProbe(j, v));
689 }
690
TEST(MatchProbe,doubleNeqDouble)691 TEST(MatchProbe, doubleNeqDouble)
692 {
693 nlohmann::json j = R"(-124.3)"_json;
694 DBusValueVariant v = double(-124.2);
695 EXPECT_FALSE(matchProbe(j, v));
696 }
697
TEST(MatchProbe,doubleNeqEmpty)698 TEST(MatchProbe, doubleNeqEmpty)
699 {
700 nlohmann::json j = R"(-11.0)"_json;
701 DBusValueVariant v;
702 EXPECT_FALSE(matchProbe(j, v));
703 }
704
TEST(MatchProbe,doubleNeqArray)705 TEST(MatchProbe, doubleNeqArray)
706 {
707 nlohmann::json j = R"(-11.2)"_json;
708 DBusValueVariant v = std::vector<uint8_t>{11};
709 EXPECT_FALSE(matchProbe(j, v));
710 }
711
TEST(MatchProbe,arrayNeqString)712 TEST(MatchProbe, arrayNeqString)
713 {
714 nlohmann::json j = R"([1, 2])"_json;
715 DBusValueVariant v = "hello"s;
716 EXPECT_FALSE(matchProbe(j, v));
717 }
718
TEST(MatchProbe,arrayNeqFalse)719 TEST(MatchProbe, arrayNeqFalse)
720 {
721 nlohmann::json j = R"([1, 2])"_json;
722 DBusValueVariant v = false;
723 EXPECT_FALSE(matchProbe(j, v));
724 }
725
TEST(MatchProbe,arrayNeqTrue)726 TEST(MatchProbe, arrayNeqTrue)
727 {
728 nlohmann::json j = R"([1, 2])"_json;
729 DBusValueVariant v = true;
730 EXPECT_FALSE(matchProbe(j, v));
731 }
732
TEST(MatchProbe,arrayNeqUint8)733 TEST(MatchProbe, arrayNeqUint8)
734 {
735 nlohmann::json j = R"([1, 2])"_json;
736 DBusValueVariant v = uint8_t(1);
737 EXPECT_FALSE(matchProbe(j, v));
738 }
739
TEST(MatchProbe,arrayNeqInt32)740 TEST(MatchProbe, arrayNeqInt32)
741 {
742 nlohmann::json j = R"([1, 2])"_json;
743 DBusValueVariant v = int32_t(-1);
744 EXPECT_FALSE(matchProbe(j, v));
745 }
746
TEST(MatchProbe,arrayNeqDouble)747 TEST(MatchProbe, arrayNeqDouble)
748 {
749 nlohmann::json j = R"([1, 2])"_json;
750 DBusValueVariant v = double(1.1);
751 EXPECT_FALSE(matchProbe(j, v));
752 }
753
TEST(MatchProbe,arrayEqArray)754 TEST(MatchProbe, arrayEqArray)
755 {
756 nlohmann::json j = R"([1, 2])"_json;
757 DBusValueVariant v = std::vector<uint8_t>{1, 2};
758 EXPECT_TRUE(matchProbe(j, v));
759 }
760
TEST(MatchProbe,arrayNeqArrayDiffSize1)761 TEST(MatchProbe, arrayNeqArrayDiffSize1)
762 {
763 nlohmann::json j = R"([1, 2, 3])"_json;
764 DBusValueVariant v = std::vector<uint8_t>{1, 2};
765 EXPECT_FALSE(matchProbe(j, v));
766 }
767
TEST(MatchProbe,arrayNeqArrayDiffSize2)768 TEST(MatchProbe, arrayNeqArrayDiffSize2)
769 {
770 nlohmann::json j = R"([1, 2])"_json;
771 DBusValueVariant v = std::vector<uint8_t>{1, 2, 3};
772 EXPECT_FALSE(matchProbe(j, v));
773 }
774
TEST(MatchProbe,emptyArrayEqEmptyArray)775 TEST(MatchProbe, emptyArrayEqEmptyArray)
776 {
777 nlohmann::json j = R"([])"_json;
778 DBusValueVariant v = std::vector<uint8_t>{};
779 EXPECT_TRUE(matchProbe(j, v));
780 }
781
TEST(MatchProbe,emptyArrayNeqArray)782 TEST(MatchProbe, emptyArrayNeqArray)
783 {
784 nlohmann::json j = R"([])"_json;
785 DBusValueVariant v = std::vector<uint8_t>{1};
786 EXPECT_FALSE(matchProbe(j, v));
787 }
788
TEST(MatchProbe,arrayNeqEmptyArray)789 TEST(MatchProbe, arrayNeqEmptyArray)
790 {
791 nlohmann::json j = R"([1])"_json;
792 DBusValueVariant v = std::vector<uint8_t>{};
793 EXPECT_FALSE(matchProbe(j, v));
794 }
795
TEST(MatchProbe,objNeqString)796 TEST(MatchProbe, objNeqString)
797 {
798 nlohmann::json j = R"({"foo": "bar"})"_json;
799 DBusValueVariant v = "hello"s;
800 EXPECT_FALSE(matchProbe(j, v));
801 }
802
TEST(MatchProbe,objNeqFalse)803 TEST(MatchProbe, objNeqFalse)
804 {
805 nlohmann::json j = R"({"foo": "bar"})"_json;
806 DBusValueVariant v = false;
807 EXPECT_FALSE(matchProbe(j, v));
808 }
809
TEST(MatchProbe,objNeqTrue)810 TEST(MatchProbe, objNeqTrue)
811 {
812 nlohmann::json j = R"({"foo": "bar"})"_json;
813 DBusValueVariant v = true;
814 EXPECT_FALSE(matchProbe(j, v));
815 }
816
TEST(MatchProbe,objNeqUint8)817 TEST(MatchProbe, objNeqUint8)
818 {
819 nlohmann::json j = R"({"foo": "bar"})"_json;
820 DBusValueVariant v = uint8_t(1);
821 EXPECT_FALSE(matchProbe(j, v));
822 }
823
TEST(MatchProbe,objNeqInt32)824 TEST(MatchProbe, objNeqInt32)
825 {
826 nlohmann::json j = R"({"foo": "bar"})"_json;
827 DBusValueVariant v = int32_t(-1);
828 EXPECT_FALSE(matchProbe(j, v));
829 }
830
TEST(MatchProbe,objNeqDouble)831 TEST(MatchProbe, objNeqDouble)
832 {
833 nlohmann::json j = R"({"foo": "bar"})"_json;
834 DBusValueVariant v = double(1.1);
835 EXPECT_FALSE(matchProbe(j, v));
836 }
837
TEST(MatchProbe,objNeqArray)838 TEST(MatchProbe, objNeqArray)
839 {
840 nlohmann::json j = R"({"foo": "bar"})"_json;
841 DBusValueVariant v = std::vector<uint8_t>{1, 2};
842 EXPECT_FALSE(matchProbe(j, v));
843 }
844
TEST(MatchProbe,nullNeqString)845 TEST(MatchProbe, nullNeqString)
846 {
847 nlohmann::json j = R"(null)"_json;
848 DBusValueVariant v = "hello"s;
849 EXPECT_FALSE(matchProbe(j, v));
850 }
851
TEST(MatchProbe,nullNeqFalse)852 TEST(MatchProbe, nullNeqFalse)
853 {
854 nlohmann::json j = R"(null)"_json;
855 DBusValueVariant v = false;
856 EXPECT_FALSE(matchProbe(j, v));
857 }
858
TEST(MatchProbe,nullNeqTrue)859 TEST(MatchProbe, nullNeqTrue)
860 {
861 nlohmann::json j = R"(null)"_json;
862 DBusValueVariant v = true;
863 EXPECT_FALSE(matchProbe(j, v));
864 }
865
TEST(MatchProbe,nullNeqUint8)866 TEST(MatchProbe, nullNeqUint8)
867 {
868 nlohmann::json j = R"(null)"_json;
869 DBusValueVariant v = uint8_t(1);
870 EXPECT_FALSE(matchProbe(j, v));
871 }
872
TEST(MatchProbe,nullNeqInt32)873 TEST(MatchProbe, nullNeqInt32)
874 {
875 nlohmann::json j = R"(null)"_json;
876 DBusValueVariant v = int32_t(-1);
877 EXPECT_FALSE(matchProbe(j, v));
878 }
879
TEST(MatchProbe,nullNeqDouble)880 TEST(MatchProbe, nullNeqDouble)
881 {
882 nlohmann::json j = R"(null)"_json;
883 DBusValueVariant v = double(1.1);
884 EXPECT_FALSE(matchProbe(j, v));
885 }
886
TEST(MatchProbe,nullNeqArray)887 TEST(MatchProbe, nullNeqArray)
888 {
889 nlohmann::json j = R"(null)"_json;
890 DBusValueVariant v = std::vector<uint8_t>{};
891 EXPECT_FALSE(matchProbe(j, v));
892 }
893