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