forked from bblanchon/ArduinoJson
Allow mixed configuration in compilation units (issue #809)
This commit is contained in:
@ -85,3 +85,4 @@ add_subdirectory(MsgPackDeserializer)
|
||||
add_subdirectory(MsgPackSerializer)
|
||||
add_subdirectory(Numbers)
|
||||
add_subdirectory(StaticMemoryPool)
|
||||
add_subdirectory(MixedConfiguration)
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
static bool isAligned(void* ptr) {
|
||||
const size_t mask = sizeof(void*) - 1;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
struct NoMemoryAllocator {
|
||||
void* allocate(size_t) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("DynamicMemoryPool::size()") {
|
||||
DynamicMemoryPool memoryPool;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("DynamicMemoryPool::startString()") {
|
||||
SECTION("WorksWhenBufferIsBigEnough") {
|
||||
|
@ -18,10 +18,10 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
REQUIRE(false == array[0].is<bool>());
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("long long") {
|
||||
array[0] = 9223372036854775807;
|
||||
REQUIRE(9223372036854775807 == array[0].as<long long>());
|
||||
REQUIRE(9223372036854775807 == array[0].as<int64_t>());
|
||||
REQUIRE(true == array[0].is<int>());
|
||||
REQUIRE(false == array[0].is<bool>());
|
||||
}
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
using namespace Catch::Matchers;
|
||||
|
||||
namespace my {
|
||||
using ARDUINOJSON_NAMESPACE::isinf;
|
||||
using ARDUINOJSON_NAMESPACE::isnan;
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeJson(DynamicJsonDocument&)") {
|
||||
DynamicJsonDocument doc;
|
||||
|
||||
@ -99,28 +104,28 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") {
|
||||
DeserializationError err = deserializeJson(doc, "NaN");
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<float>() == true);
|
||||
REQUIRE(Internals::isnan(doc.as<float>()));
|
||||
REQUIRE(my::isnan(doc.as<float>()));
|
||||
}
|
||||
|
||||
SECTION("Infinity") {
|
||||
DeserializationError err = deserializeJson(doc, "Infinity");
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<float>() == true);
|
||||
REQUIRE(Internals::isinf(doc.as<float>()));
|
||||
REQUIRE(my::isinf(doc.as<float>()));
|
||||
}
|
||||
|
||||
SECTION("+Infinity") {
|
||||
DeserializationError err = deserializeJson(doc, "+Infinity");
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<float>() == true);
|
||||
REQUIRE(Internals::isinf(doc.as<float>()));
|
||||
REQUIRE(my::isinf(doc.as<float>()));
|
||||
}
|
||||
|
||||
SECTION("-Infinity") {
|
||||
DeserializationError err = deserializeJson(doc, "-Infinity");
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<float>() == true);
|
||||
REQUIRE(Internals::isinf(doc.as<float>()));
|
||||
REQUIRE(my::isinf(doc.as<float>()));
|
||||
}
|
||||
|
||||
SECTION("issue #628") {
|
||||
|
@ -69,7 +69,7 @@ TEST_CASE("serializeJson(JsonVariant)") {
|
||||
check(false, "false");
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("NegativeInt64") {
|
||||
check(-9223372036854775807 - 1, "-9223372036854775808");
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ TEST_CASE("JsonVariant::as()") {
|
||||
}
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("Smallest int64 negative") {
|
||||
variant.set("-9223372036854775808");
|
||||
REQUIRE(variant.as<long long>() == -9223372036854775807 - 1);
|
||||
|
@ -39,9 +39,9 @@ void checkNumericType() {
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant set()/get()") {
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("SizeOfJsonInteger") {
|
||||
REQUIRE(8 == sizeof(Internals::JsonInteger));
|
||||
REQUIRE(8 == sizeof(JsonInteger));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -95,7 +95,7 @@ TEST_CASE("JsonVariant set()/get()") {
|
||||
SECTION("UShort") {
|
||||
checkNumericType<unsigned short>();
|
||||
}
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("LongLong") {
|
||||
checkNumericType<unsigned long long>();
|
||||
}
|
||||
@ -122,7 +122,7 @@ TEST_CASE("JsonVariant set()/get()") {
|
||||
SECTION("Uint32") {
|
||||
checkNumericType<uint32_t>();
|
||||
}
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("Int64") {
|
||||
checkNumericType<int64_t>();
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <ArduinoJson/Json/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Serialization/DynamicStringWriter.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename TFloat>
|
||||
void check(TFloat input, const std::string& expected) {
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <ArduinoJson/Json/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Serialization/StaticStringWriter.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
void check(const char* input, std::string expected) {
|
||||
char output[1024];
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Numbers/FloatParts.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("FloatParts<double>") {
|
||||
SECTION("1.7976931348623157E+308") {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename StringWriter>
|
||||
static size_t print(StringWriter& sb, const char* s) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("Polyfills/type_traits") {
|
||||
SECTION("is_base_of") {
|
||||
|
16
test/MixedConfiguration/CMakeLists.txt
Normal file
16
test/MixedConfiguration/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2018
|
||||
# MIT License
|
||||
|
||||
# we need C++11 for 'long long'
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(MixedConfigurationTests
|
||||
use_double_0.cpp
|
||||
use_double_1.cpp
|
||||
use_long_long_0.cpp
|
||||
use_long_long_1.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MixedConfigurationTests catch)
|
||||
add_test(MixedConfiguration MixedConfigurationTests)
|
17
test/MixedConfiguration/use_double_0.cpp
Normal file
17
test/MixedConfiguration/use_double_0.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_DOUBLE 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_DOUBLE == 0") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["pi"] = 3.14;
|
||||
root["e"] = 2.72;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"pi\":3.14,\"e\":2.72}");
|
||||
}
|
17
test/MixedConfiguration/use_double_1.cpp
Normal file
17
test/MixedConfiguration/use_double_1.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_DOUBLE 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_DOUBLE == 1") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["pi"] = 3.14;
|
||||
root["e"] = 2.72;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"pi\":3.14,\"e\":2.72}");
|
||||
}
|
30
test/MixedConfiguration/use_long_long_0.cpp
Normal file
30
test/MixedConfiguration/use_long_long_0.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
template <size_t size_of_long>
|
||||
std::string get_expected_json();
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<4>() {
|
||||
return "{\"A\":2899336981,\"B\":2129924785}";
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<8>() {
|
||||
return "{\"A\":123456789123456789,\"B\":987654321987654321}";
|
||||
}
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 0") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["A"] = 123456789123456789;
|
||||
root["B"] = 987654321987654321;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == get_expected_json<sizeof(long)>());
|
||||
}
|
17
test/MixedConfiguration/use_long_long_1.cpp
Normal file
17
test/MixedConfiguration/use_long_long_1.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 1") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["A"] = 123456789123456789;
|
||||
root["B"] = 987654321987654321;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"A\":123456789123456789,\"B\":987654321987654321}");
|
||||
}
|
@ -63,7 +63,7 @@ TEST_CASE("deserialize MsgPack value") {
|
||||
}
|
||||
|
||||
SECTION("uint 64") {
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
check<uint64_t>("\xCF\x00\x00\x00\x00\x00\x00\x00\x00", 0U);
|
||||
check<uint64_t>("\xCF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
|
||||
0xFFFFFFFFFFFFFFFFU);
|
||||
@ -94,7 +94,7 @@ TEST_CASE("deserialize MsgPack value") {
|
||||
}
|
||||
|
||||
SECTION("int 64") {
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
check<uint64_t>("\xD3\x00\x00\x00\x00\x00\x00\x00\x00", 0U);
|
||||
check<uint64_t>("\xD3\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
|
||||
0xFFFFFFFFFFFFFFFFU);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename T>
|
||||
static void check(const char* input, T expected) {
|
||||
@ -17,7 +17,7 @@ static void check(const char* input, T expected) {
|
||||
CHECK(actual == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Internals::doubleToFloat()") {
|
||||
TEST_CASE("doubleToFloat()") {
|
||||
check("\x40\x09\x21\xCA\xC0\x83\x12\x6F", 3.1415f);
|
||||
check("\x00\x00\x00\x00\x00\x00\x00\x00", 0.0f);
|
||||
check("\x80\x00\x00\x00\x00\x00\x00\x00", -0.0f);
|
||||
|
@ -65,7 +65,7 @@ TEST_CASE("serialize MsgPack value") {
|
||||
check(0xFFFFFFFFU, "\xCE\xFF\xFF\xFF\xFF");
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("uint 64") {
|
||||
check(0x0001000000000000U, "\xCF\x00\x01\x00\x00\x00\x00\x00\x00");
|
||||
check(0x123456789ABCDEF0U, "\xCF\x12\x34\x56\x78\x9A\xBC\xDE\xF0");
|
||||
@ -93,7 +93,7 @@ TEST_CASE("serialize MsgPack value") {
|
||||
check(-2147483647 - 1, "\xD2\x80\x00\x00\x00");
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
SECTION("int 64") {
|
||||
check(int64_t(0xFEDCBA9876543210), "\xD3\xFE\xDC\xBA\x98\x76\x54\x32\x10");
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Numbers/isFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("isFloat()") {
|
||||
SECTION("Input is NULL") {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Numbers/isInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("isInteger()") {
|
||||
SECTION("Null") {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Numbers/parseFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename T>
|
||||
void check(const char* input, T expected) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <ArduinoJson/Numbers/parseInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename T>
|
||||
void check(const char* input, T expected) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Memory/StaticMemoryPool.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
static bool isAligned(void *ptr) {
|
||||
const size_t mask = sizeof(void *) - 1;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson/Memory/StaticMemoryPool.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("StaticMemoryPool::size()") {
|
||||
StaticMemoryPool<64> memoryPool;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("StaticMemoryPool::startString()") {
|
||||
SECTION("WorksWhenBufferIsBigEnough") {
|
||||
|
Reference in New Issue
Block a user