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