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