forked from bblanchon/ArduinoJson
Fixed enums serialized as booleans (fixes #1197)
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
enum ErrorCode { ERROR_01 = 1, ERROR_10 = 10 };
|
||||
|
||||
TEST_CASE("JsonVariant and strings") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
@ -91,6 +93,15 @@ TEST_CASE("JsonVariant and strings") {
|
||||
|
||||
REQUIRE(variant == "hello");
|
||||
}
|
||||
|
||||
SECTION("stores an enum as an integer") {
|
||||
ErrorCode code = ERROR_10;
|
||||
|
||||
variant.set(code);
|
||||
|
||||
REQUIRE(variant.is<int>() == true);
|
||||
REQUIRE(variant.as<int>() == 10);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant with not enough memory") {
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
class EmptyClass {};
|
||||
enum EmptyEnum {};
|
||||
|
||||
TEST_CASE("Polyfills/type_traits") {
|
||||
SECTION("is_base_of") {
|
||||
REQUIRE_FALSE(
|
||||
@ -48,6 +51,30 @@ TEST_CASE("Polyfills/type_traits") {
|
||||
CHECK(is_unsigned<double>::value == false);
|
||||
}
|
||||
|
||||
SECTION("is_convertible") {
|
||||
CHECK((is_convertible<short, int>::value == true));
|
||||
CHECK((is_convertible<int, int>::value == true));
|
||||
CHECK((is_convertible<EmptyEnum, int>::value == true));
|
||||
CHECK((is_convertible<int*, int>::value == false));
|
||||
CHECK((is_convertible<EmptyClass, int>::value == false));
|
||||
}
|
||||
|
||||
SECTION("is_class") {
|
||||
CHECK((is_class<int>::value == false));
|
||||
CHECK((is_class<EmptyEnum>::value == false));
|
||||
CHECK((is_class<int*>::value == false));
|
||||
CHECK((is_class<EmptyClass>::value == true));
|
||||
}
|
||||
|
||||
SECTION("is_enum") {
|
||||
CHECK(is_enum<int>::value == false);
|
||||
CHECK(is_enum<EmptyEnum>::value == true);
|
||||
CHECK(is_enum<int*>::value == false);
|
||||
CHECK(is_enum<EmptyClass>::value == false);
|
||||
CHECK(is_enum<bool>::value == false);
|
||||
CHECK(is_enum<double>::value == false);
|
||||
}
|
||||
|
||||
SECTION("IsVisitable") {
|
||||
CHECK(IsVisitable<DeserializationError>::value == false);
|
||||
CHECK(IsVisitable<JsonPair>::value == false);
|
||||
|
Reference in New Issue
Block a user