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