xref: /openbmc/entity-manager/test/entity_manager/test_entity-manager.cpp (revision 83c8e49400667e88453e25636128a8a61b878b81)
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(HandleLeftOverTemplateVars,replaceLeftOverTemplateVarObj)253 TEST(HandleLeftOverTemplateVars, replaceLeftOverTemplateVarObj)
254 {
255     nlohmann::json::object_t j = {{"foo", "the Test $TEST is $TESTED"}};
256 
257     em_utils::handleLeftOverTemplateVars(j);
258 
259     nlohmann::json expected = "the Test  is ";
260     EXPECT_EQ(expected, j["foo"]);
261 }
262 
TEST(HandleLeftOverTemplateVars,replaceLeftOverTemplateVarArr)263 TEST(HandleLeftOverTemplateVars, replaceLeftOverTemplateVarArr)
264 {
265     nlohmann::json::array_t j = {{{"foo", "the Test $TEST is $TESTED"}}};
266 
267     em_utils::handleLeftOverTemplateVars(j);
268 
269     nlohmann::json expected = "the Test  is ";
270     EXPECT_EQ(expected, j[0]["foo"]);
271 }
272 
TEST(HandleLeftOverTemplateVars,replaceLeftOverTemplateVarString)273 TEST(HandleLeftOverTemplateVars, replaceLeftOverTemplateVarString)
274 {
275     std::string s = "the Test $TEST is $TESTED";
276 
277     em_utils::handleLeftOverTemplateVars(s);
278 
279     nlohmann::json expected = "the Test  is ";
280     EXPECT_EQ(expected, s);
281 }
282 
TEST(MatchProbe,stringEqString)283 TEST(MatchProbe, stringEqString)
284 {
285     nlohmann::json j = R"("foo")"_json;
286     DBusValueVariant v = "foo"s;
287     EXPECT_TRUE(matchProbe(j, v));
288 }
289 
TEST(MatchProbe,stringRegexEqString)290 TEST(MatchProbe, stringRegexEqString)
291 {
292     nlohmann::json j = R"("foo*")"_json;
293     DBusValueVariant v = "foobar"s;
294     EXPECT_TRUE(matchProbe(j, v));
295 }
296 
TEST(MatchProbe,stringNeqString)297 TEST(MatchProbe, stringNeqString)
298 {
299     nlohmann::json j = R"("foobar")"_json;
300     DBusValueVariant v = "foo"s;
301     EXPECT_FALSE(matchProbe(j, v));
302 }
303 
TEST(MatchProbe,stringRegexError)304 TEST(MatchProbe, stringRegexError)
305 {
306     nlohmann::json j = R"("foo[")"_json;
307     DBusValueVariant v = "foobar"s;
308     EXPECT_FALSE(matchProbe(j, v));
309 }
310 
TEST(MatchProbe,stringRegexNotPrefix)311 TEST(MatchProbe, stringRegexNotPrefix)
312 {
313     nlohmann::json j = R"("foo(?!bar)...foo")"_json;
314     DBusValueVariant v1 = "foobarfoo"s;
315     DBusValueVariant v2 = "foofoofoo"s;
316     EXPECT_FALSE(matchProbe(j, v1));
317     EXPECT_TRUE(matchProbe(j, v2));
318 }
319 
TEST(MatchProbe,stringZeroNeqFalse)320 TEST(MatchProbe, stringZeroNeqFalse)
321 {
322     nlohmann::json j = R"("0")"_json;
323     DBusValueVariant v = false;
324     EXPECT_FALSE(matchProbe(j, v));
325 }
326 
TEST(MatchProbe,stringOneNeqTrue)327 TEST(MatchProbe, stringOneNeqTrue)
328 {
329     nlohmann::json j = R"("1")"_json;
330     DBusValueVariant v = true;
331     EXPECT_FALSE(matchProbe(j, v));
332 }
333 
TEST(MatchProbe,stringElevenNeqTrue)334 TEST(MatchProbe, stringElevenNeqTrue)
335 {
336     nlohmann::json j = R"("11")"_json;
337     DBusValueVariant v = true;
338     EXPECT_FALSE(matchProbe(j, v));
339 }
340 
TEST(MatchProbe,stringFalseNeqFalse)341 TEST(MatchProbe, stringFalseNeqFalse)
342 {
343     nlohmann::json j = R"("false")"_json;
344     DBusValueVariant v = false;
345     EXPECT_FALSE(matchProbe(j, v));
346 }
347 
TEST(MatchProbe,stringTrueNeqTrue)348 TEST(MatchProbe, stringTrueNeqTrue)
349 {
350     nlohmann::json j = R"("true")"_json;
351     DBusValueVariant v = true;
352     EXPECT_FALSE(matchProbe(j, v));
353 }
354 
TEST(MatchProbe,stringFalseNeqTrue)355 TEST(MatchProbe, stringFalseNeqTrue)
356 {
357     nlohmann::json j = R"("false")"_json;
358     DBusValueVariant v = true;
359     EXPECT_FALSE(matchProbe(j, v));
360 }
361 
TEST(MatchProbe,stringNeqUint8)362 TEST(MatchProbe, stringNeqUint8)
363 {
364     nlohmann::json j = R"("255")"_json;
365     DBusValueVariant v = uint8_t(255);
366     EXPECT_FALSE(matchProbe(j, v));
367 }
368 
TEST(MatchProbe,stringNeqUint8Overflow)369 TEST(MatchProbe, stringNeqUint8Overflow)
370 {
371     nlohmann::json j = R"("65535")"_json;
372     DBusValueVariant v = uint8_t(255);
373     EXPECT_FALSE(matchProbe(j, v));
374 }
375 
TEST(MatchProbe,stringFalseNeqUint8Zero)376 TEST(MatchProbe, stringFalseNeqUint8Zero)
377 {
378     nlohmann::json j = R"("false")"_json;
379     DBusValueVariant v = uint8_t(0);
380     EXPECT_FALSE(matchProbe(j, v));
381 }
382 
TEST(MatchProbe,stringTrueNeqUint8Zero)383 TEST(MatchProbe, stringTrueNeqUint8Zero)
384 {
385     nlohmann::json j = R"("true")"_json;
386     DBusValueVariant v = uint8_t(1);
387     EXPECT_FALSE(matchProbe(j, v));
388 }
389 
TEST(MatchProbe,stringNeqUint32)390 TEST(MatchProbe, stringNeqUint32)
391 {
392     nlohmann::json j = R"("11")"_json;
393     DBusValueVariant v = uint32_t(11);
394     EXPECT_FALSE(matchProbe(j, v));
395 }
396 
TEST(MatchProbe,stringNeqInt32)397 TEST(MatchProbe, stringNeqInt32)
398 {
399     nlohmann::json j = R"("-11")"_json;
400     DBusValueVariant v = int32_t(-11);
401     EXPECT_FALSE(matchProbe(j, v));
402 }
403 
TEST(MatchProbe,stringRegexNeqInt32)404 TEST(MatchProbe, stringRegexNeqInt32)
405 {
406     nlohmann::json j = R"("1*4")"_json;
407     DBusValueVariant v = int32_t(124);
408     EXPECT_FALSE(matchProbe(j, v));
409 }
410 
TEST(MatchProbe,stringNeqUint64)411 TEST(MatchProbe, stringNeqUint64)
412 {
413     nlohmann::json j = R"("foo")"_json;
414     DBusValueVariant v = uint64_t(65535);
415     EXPECT_FALSE(matchProbe(j, v));
416 }
417 
TEST(MatchProbe,stringNeqDouble)418 TEST(MatchProbe, stringNeqDouble)
419 {
420     nlohmann::json j = R"("123.4")"_json;
421     DBusValueVariant v = double(123.4);
422     EXPECT_FALSE(matchProbe(j, v));
423 }
424 
TEST(MatchProbe,stringNeqEmpty)425 TEST(MatchProbe, stringNeqEmpty)
426 {
427     nlohmann::json j = R"("-123.4")"_json;
428     DBusValueVariant v;
429     EXPECT_FALSE(matchProbe(j, v));
430 }
431 
TEST(MatchProbe,stringNeqArray)432 TEST(MatchProbe, stringNeqArray)
433 {
434     nlohmann::json j = R"("-123.4")"_json;
435     DBusValueVariant v = std::vector<uint8_t>{1, 2};
436     EXPECT_FALSE(matchProbe(j, v));
437 }
438 
TEST(MatchProbe,boolNeqString)439 TEST(MatchProbe, boolNeqString)
440 {
441     nlohmann::json j = R"(false)"_json;
442     DBusValueVariant v = "false"s;
443     EXPECT_FALSE(matchProbe(j, v));
444 }
445 
TEST(MatchProbe,trueEqTrue)446 TEST(MatchProbe, trueEqTrue)
447 {
448     nlohmann::json j = R"(true)"_json;
449     DBusValueVariant v = true;
450     EXPECT_TRUE(matchProbe(j, v));
451 }
452 
TEST(MatchProbe,falseEqFalse)453 TEST(MatchProbe, falseEqFalse)
454 {
455     nlohmann::json j = R"(false)"_json;
456     DBusValueVariant v = false;
457     EXPECT_TRUE(matchProbe(j, v));
458 }
459 
TEST(MatchProbe,trueNeqFalse)460 TEST(MatchProbe, trueNeqFalse)
461 {
462     nlohmann::json j = R"(true)"_json;
463     DBusValueVariant v = false;
464     EXPECT_FALSE(matchProbe(j, v));
465 }
466 
TEST(MatchProbe,trueNeqInt32Zero)467 TEST(MatchProbe, trueNeqInt32Zero)
468 {
469     nlohmann::json j = R"(true)"_json;
470     DBusValueVariant v = int32_t(0);
471     EXPECT_FALSE(matchProbe(j, v));
472 }
473 
TEST(MatchProbe,trueNeqInt32NegativeOne)474 TEST(MatchProbe, trueNeqInt32NegativeOne)
475 {
476     nlohmann::json j = R"(true)"_json;
477     DBusValueVariant v = int32_t(-1);
478     EXPECT_FALSE(matchProbe(j, v));
479 }
480 
TEST(MatchProbe,falseNeqUint32One)481 TEST(MatchProbe, falseNeqUint32One)
482 {
483     nlohmann::json j = R"(false)"_json;
484     DBusValueVariant v = uint32_t(1);
485     EXPECT_FALSE(matchProbe(j, v));
486 }
487 
TEST(MatchProbe,falseNeqUint32Zero)488 TEST(MatchProbe, falseNeqUint32Zero)
489 {
490     nlohmann::json j = R"(false)"_json;
491     DBusValueVariant v = uint32_t(0);
492     EXPECT_FALSE(matchProbe(j, v));
493 }
494 
TEST(MatchProbe,trueNeqDoubleNegativeOne)495 TEST(MatchProbe, trueNeqDoubleNegativeOne)
496 {
497     nlohmann::json j = R"(true)"_json;
498     DBusValueVariant v = double(-1.1);
499     EXPECT_FALSE(matchProbe(j, v));
500 }
501 
TEST(MatchProbe,trueNeqDoubleOne)502 TEST(MatchProbe, trueNeqDoubleOne)
503 {
504     nlohmann::json j = R"(true)"_json;
505     DBusValueVariant v = double(1.0);
506     EXPECT_FALSE(matchProbe(j, v));
507 }
508 
TEST(MatchProbe,falseNeqDoubleOne)509 TEST(MatchProbe, falseNeqDoubleOne)
510 {
511     nlohmann::json j = R"(false)"_json;
512     DBusValueVariant v = double(1.0);
513     EXPECT_FALSE(matchProbe(j, v));
514 }
515 
TEST(MatchProbe,falseNeqDoubleZero)516 TEST(MatchProbe, falseNeqDoubleZero)
517 {
518     nlohmann::json j = R"(false)"_json;
519     DBusValueVariant v = double(0.0);
520     EXPECT_FALSE(matchProbe(j, v));
521 }
522 
TEST(MatchProbe,falseNeqEmpty)523 TEST(MatchProbe, falseNeqEmpty)
524 {
525     nlohmann::json j = R"(false)"_json;
526     DBusValueVariant v;
527     EXPECT_FALSE(matchProbe(j, v));
528 }
529 
TEST(MatchProbe,trueNeqEmpty)530 TEST(MatchProbe, trueNeqEmpty)
531 {
532     nlohmann::json j = R"(true)"_json;
533     DBusValueVariant v;
534     EXPECT_FALSE(matchProbe(j, v));
535 }
536 
TEST(MatchProbe,trueNeqArray)537 TEST(MatchProbe, trueNeqArray)
538 {
539     nlohmann::json j = R"(true)"_json;
540     DBusValueVariant v = std::vector<uint8_t>{1, 2};
541     EXPECT_FALSE(matchProbe(j, v));
542 }
543 
TEST(MatchProbe,uintNeqString)544 TEST(MatchProbe, uintNeqString)
545 {
546     nlohmann::json j = R"(11)"_json;
547     DBusValueVariant v = "11"s;
548     EXPECT_FALSE(matchProbe(j, v));
549 }
550 
TEST(MatchProbe,uintNeqTrue)551 TEST(MatchProbe, uintNeqTrue)
552 {
553     nlohmann::json j = R"(1)"_json;
554     DBusValueVariant v = true;
555     EXPECT_FALSE(matchProbe(j, v));
556 }
557 
TEST(MatchProbe,uintNeqFalse)558 TEST(MatchProbe, uintNeqFalse)
559 {
560     nlohmann::json j = R"(0)"_json;
561     DBusValueVariant v = false;
562     EXPECT_FALSE(matchProbe(j, v));
563 }
564 
TEST(MatchProbe,uintEqUint8)565 TEST(MatchProbe, uintEqUint8)
566 {
567     nlohmann::json j = R"(11)"_json;
568     DBusValueVariant v = uint8_t(11);
569     EXPECT_TRUE(matchProbe(j, v));
570 }
571 
TEST(MatchProbe,uintNeqUint8)572 TEST(MatchProbe, uintNeqUint8)
573 {
574     nlohmann::json j = R"(11)"_json;
575     DBusValueVariant v = uint8_t(12);
576     EXPECT_FALSE(matchProbe(j, v));
577 }
578 
TEST(MatchProbe,uintNeqUint8Overflow)579 TEST(MatchProbe, uintNeqUint8Overflow)
580 {
581     nlohmann::json j = R"(65535)"_json;
582     DBusValueVariant v = uint8_t(255);
583     EXPECT_FALSE(matchProbe(j, v));
584 }
585 
TEST(MatchProbe,uintEqInt8)586 TEST(MatchProbe, uintEqInt8)
587 {
588     nlohmann::json j = R"(11)"_json;
589     DBusValueVariant v = int8_t(11);
590     EXPECT_TRUE(matchProbe(j, v));
591 }
592 
TEST(MatchProbe,uintEqDouble)593 TEST(MatchProbe, uintEqDouble)
594 {
595     nlohmann::json j = R"(11)"_json;
596     DBusValueVariant v = double(11.0);
597     EXPECT_TRUE(matchProbe(j, v));
598 }
599 
TEST(MatchProbe,uintNeqDouble)600 TEST(MatchProbe, uintNeqDouble)
601 {
602     nlohmann::json j = R"(11)"_json;
603     DBusValueVariant v = double(11.7);
604     EXPECT_FALSE(matchProbe(j, v));
605 }
606 
TEST(MatchProbe,uintNeqEmpty)607 TEST(MatchProbe, uintNeqEmpty)
608 {
609     nlohmann::json j = R"(11)"_json;
610     DBusValueVariant v;
611     EXPECT_FALSE(matchProbe(j, v));
612 }
613 
TEST(MatchProbe,uintNeqArray)614 TEST(MatchProbe, uintNeqArray)
615 {
616     nlohmann::json j = R"(11)"_json;
617     DBusValueVariant v = std::vector<uint8_t>{11};
618     EXPECT_FALSE(matchProbe(j, v));
619 }
620 
TEST(MatchProbe,intNeqString)621 TEST(MatchProbe, intNeqString)
622 {
623     nlohmann::json j = R"(-11)"_json;
624     DBusValueVariant v = "-11"s;
625     EXPECT_FALSE(matchProbe(j, v));
626 }
627 
TEST(MatchProbe,intNeqTrue)628 TEST(MatchProbe, intNeqTrue)
629 {
630     nlohmann::json j = R"(-1)"_json;
631     DBusValueVariant v = true;
632     EXPECT_FALSE(matchProbe(j, v));
633 }
634 
TEST(MatchProbe,intNeqUint8)635 TEST(MatchProbe, intNeqUint8)
636 {
637     nlohmann::json j = R"(-11)"_json;
638     DBusValueVariant v = uint8_t(11);
639     EXPECT_FALSE(matchProbe(j, v));
640 }
641 
TEST(MatchProbe,intEqInt8)642 TEST(MatchProbe, intEqInt8)
643 {
644     nlohmann::json j = R"(-11)"_json;
645     DBusValueVariant v = int8_t(-11);
646     EXPECT_TRUE(matchProbe(j, v));
647 }
648 
TEST(MatchProbe,intNeqDouble)649 TEST(MatchProbe, intNeqDouble)
650 {
651     nlohmann::json j = R"(-124)"_json;
652     DBusValueVariant v = double(-123.0);
653     EXPECT_FALSE(matchProbe(j, v));
654 }
655 
TEST(MatchProbe,intEqDouble)656 TEST(MatchProbe, intEqDouble)
657 {
658     nlohmann::json j = R"(-11)"_json;
659     DBusValueVariant v = double(-11.0);
660     EXPECT_TRUE(matchProbe(j, v));
661 }
662 
TEST(MatchProbe,intNeqDoubleRound)663 TEST(MatchProbe, intNeqDoubleRound)
664 {
665     nlohmann::json j = R"(-11)"_json;
666     DBusValueVariant v = double(-11.7);
667     EXPECT_FALSE(matchProbe(j, v));
668 }
669 
TEST(MatchProbe,intNeqEmpty)670 TEST(MatchProbe, intNeqEmpty)
671 {
672     nlohmann::json j = R"(-11)"_json;
673     DBusValueVariant v;
674     EXPECT_FALSE(matchProbe(j, v));
675 }
676 
TEST(MatchProbe,intNeqArray)677 TEST(MatchProbe, intNeqArray)
678 {
679     nlohmann::json j = R"(-11)"_json;
680     DBusValueVariant v = std::vector<uint8_t>{11};
681     EXPECT_FALSE(matchProbe(j, v));
682 }
683 
TEST(MatchProbe,doubleNeqString)684 TEST(MatchProbe, doubleNeqString)
685 {
686     nlohmann::json j = R"(0.0)"_json;
687     DBusValueVariant v = "0.0"s;
688     EXPECT_FALSE(matchProbe(j, v));
689 }
690 
TEST(MatchProbe,doubleNeqFalse)691 TEST(MatchProbe, doubleNeqFalse)
692 {
693     nlohmann::json j = R"(0.0)"_json;
694     DBusValueVariant v = false;
695     EXPECT_FALSE(matchProbe(j, v));
696 }
697 
TEST(MatchProbe,doubleNeqTrue)698 TEST(MatchProbe, doubleNeqTrue)
699 {
700     nlohmann::json j = R"(1.0)"_json;
701     DBusValueVariant v = true;
702     EXPECT_FALSE(matchProbe(j, v));
703 }
704 
TEST(MatchProbe,doubleEqInt32)705 TEST(MatchProbe, doubleEqInt32)
706 {
707     nlohmann::json j = R"(-124.0)"_json;
708     DBusValueVariant v = int32_t(-124);
709     EXPECT_TRUE(matchProbe(j, v));
710 }
711 
TEST(MatchProbe,doubleNeqInt32)712 TEST(MatchProbe, doubleNeqInt32)
713 {
714     nlohmann::json j = R"(-124.0)"_json;
715     DBusValueVariant v = int32_t(-123);
716     EXPECT_FALSE(matchProbe(j, v));
717 }
718 
TEST(MatchProbe,doubleRoundNeqInt)719 TEST(MatchProbe, doubleRoundNeqInt)
720 {
721     nlohmann::json j = R"(124.7)"_json;
722     DBusValueVariant v = int32_t(124);
723     EXPECT_FALSE(matchProbe(j, v));
724 }
TEST(MatchProbe,doubleEqDouble)725 TEST(MatchProbe, doubleEqDouble)
726 {
727     nlohmann::json j = R"(-124.2)"_json;
728     DBusValueVariant v = double(-124.2);
729     EXPECT_TRUE(matchProbe(j, v));
730 }
731 
TEST(MatchProbe,doubleNeqDouble)732 TEST(MatchProbe, doubleNeqDouble)
733 {
734     nlohmann::json j = R"(-124.3)"_json;
735     DBusValueVariant v = double(-124.2);
736     EXPECT_FALSE(matchProbe(j, v));
737 }
738 
TEST(MatchProbe,doubleNeqEmpty)739 TEST(MatchProbe, doubleNeqEmpty)
740 {
741     nlohmann::json j = R"(-11.0)"_json;
742     DBusValueVariant v;
743     EXPECT_FALSE(matchProbe(j, v));
744 }
745 
TEST(MatchProbe,doubleNeqArray)746 TEST(MatchProbe, doubleNeqArray)
747 {
748     nlohmann::json j = R"(-11.2)"_json;
749     DBusValueVariant v = std::vector<uint8_t>{11};
750     EXPECT_FALSE(matchProbe(j, v));
751 }
752 
TEST(MatchProbe,arrayNeqString)753 TEST(MatchProbe, arrayNeqString)
754 {
755     nlohmann::json j = R"([1, 2])"_json;
756     DBusValueVariant v = "hello"s;
757     EXPECT_FALSE(matchProbe(j, v));
758 }
759 
TEST(MatchProbe,arrayNeqFalse)760 TEST(MatchProbe, arrayNeqFalse)
761 {
762     nlohmann::json j = R"([1, 2])"_json;
763     DBusValueVariant v = false;
764     EXPECT_FALSE(matchProbe(j, v));
765 }
766 
TEST(MatchProbe,arrayNeqTrue)767 TEST(MatchProbe, arrayNeqTrue)
768 {
769     nlohmann::json j = R"([1, 2])"_json;
770     DBusValueVariant v = true;
771     EXPECT_FALSE(matchProbe(j, v));
772 }
773 
TEST(MatchProbe,arrayNeqUint8)774 TEST(MatchProbe, arrayNeqUint8)
775 {
776     nlohmann::json j = R"([1, 2])"_json;
777     DBusValueVariant v = uint8_t(1);
778     EXPECT_FALSE(matchProbe(j, v));
779 }
780 
TEST(MatchProbe,arrayNeqInt32)781 TEST(MatchProbe, arrayNeqInt32)
782 {
783     nlohmann::json j = R"([1, 2])"_json;
784     DBusValueVariant v = int32_t(-1);
785     EXPECT_FALSE(matchProbe(j, v));
786 }
787 
TEST(MatchProbe,arrayNeqDouble)788 TEST(MatchProbe, arrayNeqDouble)
789 {
790     nlohmann::json j = R"([1, 2])"_json;
791     DBusValueVariant v = double(1.1);
792     EXPECT_FALSE(matchProbe(j, v));
793 }
794 
TEST(MatchProbe,arrayEqArray)795 TEST(MatchProbe, arrayEqArray)
796 {
797     nlohmann::json j = R"([1, 2])"_json;
798     DBusValueVariant v = std::vector<uint8_t>{1, 2};
799     EXPECT_TRUE(matchProbe(j, v));
800 }
801 
TEST(MatchProbe,arrayNeqArrayDiffSize1)802 TEST(MatchProbe, arrayNeqArrayDiffSize1)
803 {
804     nlohmann::json j = R"([1, 2, 3])"_json;
805     DBusValueVariant v = std::vector<uint8_t>{1, 2};
806     EXPECT_FALSE(matchProbe(j, v));
807 }
808 
TEST(MatchProbe,arrayNeqArrayDiffSize2)809 TEST(MatchProbe, arrayNeqArrayDiffSize2)
810 {
811     nlohmann::json j = R"([1, 2])"_json;
812     DBusValueVariant v = std::vector<uint8_t>{1, 2, 3};
813     EXPECT_FALSE(matchProbe(j, v));
814 }
815 
TEST(MatchProbe,emptyArrayEqEmptyArray)816 TEST(MatchProbe, emptyArrayEqEmptyArray)
817 {
818     nlohmann::json j = R"([])"_json;
819     DBusValueVariant v = std::vector<uint8_t>{};
820     EXPECT_TRUE(matchProbe(j, v));
821 }
822 
TEST(MatchProbe,emptyArrayNeqArray)823 TEST(MatchProbe, emptyArrayNeqArray)
824 {
825     nlohmann::json j = R"([])"_json;
826     DBusValueVariant v = std::vector<uint8_t>{1};
827     EXPECT_FALSE(matchProbe(j, v));
828 }
829 
TEST(MatchProbe,arrayNeqEmptyArray)830 TEST(MatchProbe, arrayNeqEmptyArray)
831 {
832     nlohmann::json j = R"([1])"_json;
833     DBusValueVariant v = std::vector<uint8_t>{};
834     EXPECT_FALSE(matchProbe(j, v));
835 }
836 
TEST(MatchProbe,objNeqString)837 TEST(MatchProbe, objNeqString)
838 {
839     nlohmann::json j = R"({"foo": "bar"})"_json;
840     DBusValueVariant v = "hello"s;
841     EXPECT_FALSE(matchProbe(j, v));
842 }
843 
TEST(MatchProbe,objNeqFalse)844 TEST(MatchProbe, objNeqFalse)
845 {
846     nlohmann::json j = R"({"foo": "bar"})"_json;
847     DBusValueVariant v = false;
848     EXPECT_FALSE(matchProbe(j, v));
849 }
850 
TEST(MatchProbe,objNeqTrue)851 TEST(MatchProbe, objNeqTrue)
852 {
853     nlohmann::json j = R"({"foo": "bar"})"_json;
854     DBusValueVariant v = true;
855     EXPECT_FALSE(matchProbe(j, v));
856 }
857 
TEST(MatchProbe,objNeqUint8)858 TEST(MatchProbe, objNeqUint8)
859 {
860     nlohmann::json j = R"({"foo": "bar"})"_json;
861     DBusValueVariant v = uint8_t(1);
862     EXPECT_FALSE(matchProbe(j, v));
863 }
864 
TEST(MatchProbe,objNeqInt32)865 TEST(MatchProbe, objNeqInt32)
866 {
867     nlohmann::json j = R"({"foo": "bar"})"_json;
868     DBusValueVariant v = int32_t(-1);
869     EXPECT_FALSE(matchProbe(j, v));
870 }
871 
TEST(MatchProbe,objNeqDouble)872 TEST(MatchProbe, objNeqDouble)
873 {
874     nlohmann::json j = R"({"foo": "bar"})"_json;
875     DBusValueVariant v = double(1.1);
876     EXPECT_FALSE(matchProbe(j, v));
877 }
878 
TEST(MatchProbe,objNeqArray)879 TEST(MatchProbe, objNeqArray)
880 {
881     nlohmann::json j = R"({"foo": "bar"})"_json;
882     DBusValueVariant v = std::vector<uint8_t>{1, 2};
883     EXPECT_FALSE(matchProbe(j, v));
884 }
885 
TEST(MatchProbe,nullNeqString)886 TEST(MatchProbe, nullNeqString)
887 {
888     nlohmann::json j = R"(null)"_json;
889     DBusValueVariant v = "hello"s;
890     EXPECT_FALSE(matchProbe(j, v));
891 }
892 
TEST(MatchProbe,nullNeqFalse)893 TEST(MatchProbe, nullNeqFalse)
894 {
895     nlohmann::json j = R"(null)"_json;
896     DBusValueVariant v = false;
897     EXPECT_FALSE(matchProbe(j, v));
898 }
899 
TEST(MatchProbe,nullNeqTrue)900 TEST(MatchProbe, nullNeqTrue)
901 {
902     nlohmann::json j = R"(null)"_json;
903     DBusValueVariant v = true;
904     EXPECT_FALSE(matchProbe(j, v));
905 }
906 
TEST(MatchProbe,nullNeqUint8)907 TEST(MatchProbe, nullNeqUint8)
908 {
909     nlohmann::json j = R"(null)"_json;
910     DBusValueVariant v = uint8_t(1);
911     EXPECT_FALSE(matchProbe(j, v));
912 }
913 
TEST(MatchProbe,nullNeqInt32)914 TEST(MatchProbe, nullNeqInt32)
915 {
916     nlohmann::json j = R"(null)"_json;
917     DBusValueVariant v = int32_t(-1);
918     EXPECT_FALSE(matchProbe(j, v));
919 }
920 
TEST(MatchProbe,nullNeqDouble)921 TEST(MatchProbe, nullNeqDouble)
922 {
923     nlohmann::json j = R"(null)"_json;
924     DBusValueVariant v = double(1.1);
925     EXPECT_FALSE(matchProbe(j, v));
926 }
927 
TEST(MatchProbe,nullNeqArray)928 TEST(MatchProbe, nullNeqArray)
929 {
930     nlohmann::json j = R"(null)"_json;
931     DBusValueVariant v = std::vector<uint8_t>{};
932     EXPECT_FALSE(matchProbe(j, v));
933 }
934