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