Implemented reference semantics for JsonVariant

This commit is contained in:
Benoit Blanchon
2018-08-21 17:56:16 +02:00
parent 0454bd1ef6
commit 9cbc891816
53 changed files with 1196 additions and 839 deletions

View File

@ -6,9 +6,12 @@
#include <catch.hpp>
#include <limits>
void check(JsonVariant variant, const std::string &expected) {
template <typename T>
void check(T value, const std::string &expected) {
DynamicJsonDocument doc;
doc.to<JsonVariant>().set(value);
char buffer[256] = "";
size_t returnValue = serializeJson(variant, buffer, sizeof(buffer));
size_t returnValue = serializeJson(doc, buffer, sizeof(buffer));
REQUIRE(expected == buffer);
REQUIRE(expected.size() == returnValue);
}
@ -22,10 +25,22 @@ TEST_CASE("serializeJson(JsonVariant)") {
check(static_cast<char *>(0), "null");
}
SECTION("String") {
SECTION("const char*") {
check("hello", "\"hello\"");
}
SECTION("string") {
check(std::string("hello"), "\"hello\"");
}
SECTION("SerializedValue<const char*>") {
check(serialized("[1,2]"), "[1,2]");
}
SECTION("SerializedValue<std::string>") {
check(serialized(std::string("[1,2]")), "[1,2]");
}
SECTION("Double") {
check(3.1415927, "3.1415927");
}