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