Files
ArduinoJson/test/JsonSerializer/JsonVariant.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

// ArduinoJson - arduinojson.org
2018-01-05 09:20:01 +01:00
// Copyright Benoit Blanchon 2014-2018
2014-11-11 17:26:51 +01:00
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
#include <limits>
2014-11-11 17:26:51 +01:00
void check(JsonVariant variant, const std::string &expected) {
char buffer[256] = "";
size_t returnValue = serializeJson(variant, buffer, sizeof(buffer));
REQUIRE(expected == buffer);
REQUIRE(expected.size() == returnValue);
}
2014-11-11 17:26:51 +01:00
TEST_CASE("serializeJson(JsonVariant)") {
SECTION("Undefined") {
check(JsonVariant(), "null");
2014-11-11 17:26:51 +01:00
}
SECTION("Null string") {
check(static_cast<char *>(0), "null");
}
2014-11-11 17:26:51 +01:00
SECTION("String") {
check("hello", "\"hello\"");
}
2014-11-11 17:26:51 +01:00
SECTION("Double") {
check(3.1415927, "3.1415927");
}
SECTION("Integer") {
check(42, "42");
}
2014-11-11 17:26:51 +01:00
SECTION("NegativeLong") {
check(-42, "-42");
}
2014-11-11 17:26:51 +01:00
SECTION("UnsignedLong") {
check(4294967295UL, "4294967295");
}
SECTION("True") {
check(true, "true");
}
2014-11-11 17:26:51 +01:00
SECTION("OneFalse") {
check(false, "false");
}
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
SECTION("NegativeInt64") {
check(-9223372036854775807 - 1, "-9223372036854775808");
}
SECTION("PositiveInt64") {
check(9223372036854775807, "9223372036854775807");
}
SECTION("UInt64") {
2017-05-02 21:32:19 +02:00
check(18446744073709551615U, "18446744073709551615");
}
#endif
}