Merge branch 'master' into 6.x

This commit is contained in:
Benoit Blanchon
2018-06-04 17:44:10 +02:00
12 changed files with 104 additions and 14 deletions

View File

@ -152,4 +152,15 @@ TEST_CASE("JsonObject::operator[]") {
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 12;
REQUIRE(expectedSize <= doc.memoryUsage());
}
SECTION("should ignore null key") {
// object must have a value to make a call to strcmp()
obj["dummy"] = 42;
const char* null = 0;
obj[null] = 666;
REQUIRE(obj.size() == 1);
REQUIRE(obj[null] == 0);
}
}

View File

@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <catch.hpp>
static const char* null = 0;
template <typename T>
void checkEquals(JsonVariant a, T b) {
REQUIRE(b == a);
@ -96,38 +98,69 @@ TEST_CASE("JsonVariant comparisons") {
checkComparisons<unsigned short>(122, 123, 124);
}
SECTION("null") {
JsonVariant variant = null;
REQUIRE(variant == variant);
REQUIRE_FALSE(variant != variant);
REQUIRE(variant == null);
REQUIRE_FALSE(variant != null);
REQUIRE(variant != "null");
REQUIRE_FALSE(variant == "null");
}
SECTION("StringLiteral") {
DynamicJsonDocument doc;
deserializeJson(doc, "\"hello\"");
JsonVariant variant = doc.as<JsonVariant>();
REQUIRE(variant == variant);
REQUIRE_FALSE(variant != variant);
REQUIRE(variant == "hello");
REQUIRE_FALSE(variant != "hello");
REQUIRE(variant != "world");
REQUIRE_FALSE(variant == "world");
REQUIRE(variant != null);
REQUIRE_FALSE(variant == null);
REQUIRE("hello" == variant);
REQUIRE_FALSE("hello" != variant);
REQUIRE("world" != variant);
REQUIRE_FALSE("world" == variant);
REQUIRE(null != variant);
REQUIRE_FALSE(null == variant);
}
SECTION("String") {
JsonVariant variant = "hello";
REQUIRE(variant == variant);
REQUIRE_FALSE(variant != variant);
REQUIRE(variant == std::string("hello"));
REQUIRE_FALSE(variant != std::string("hello"));
REQUIRE(variant != std::string("world"));
REQUIRE_FALSE(variant == std::string("world"));
REQUIRE(variant != null);
REQUIRE_FALSE(variant == null);
REQUIRE(std::string("hello") == variant);
REQUIRE_FALSE(std::string("hello") != variant);
REQUIRE(std::string("world") != variant);
REQUIRE_FALSE(std::string("world") == variant);
REQUIRE(null != variant);
REQUIRE_FALSE(null == variant);
}
SECTION("IntegerInVariant") {

View File

@ -8,6 +8,7 @@ add_executable(MiscTests
StringTraits.cpp
TypeTraits.cpp
unsigned_char.cpp
version.cpp
vla.cpp
)

16
test/Misc/version.cpp Normal file
View File

@ -0,0 +1,16 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson/version.hpp>
#include <catch.hpp>
#include <sstream>
TEST_CASE("ARDUINOJSON_VERSION") {
std::stringstream version;
version << ARDUINOJSON_VERSION_MAJOR << "." << ARDUINOJSON_VERSION_MINOR
<< "." << ARDUINOJSON_VERSION_REVISION;
REQUIRE(version.str() == ARDUINOJSON_VERSION);
}