From 1a0180078294718cafcab5b4466d59f91a5ff43f Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 1 Aug 2014 15:06:31 +0200 Subject: [PATCH] Test casting a JsonValue to a JsonArray --- JsonGenerator/JsonValue.h | 5 +++++ JsonGeneratorTests/JsonValue_Cast_Tests.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index fc167499..d7202a6b 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -89,6 +89,11 @@ namespace ArduinoJson return content.asLong; } + operator Printable&() + { + return *content.asPrintable; + } + size_t printTo(Print& p) const { // handmade polymorphism diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp index 68c93f9f..edaa2fe8 100644 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp @@ -6,6 +6,7 @@ #include "CppUnitTest.h" #include "StringBuilder.h" #include "JsonValue.h" +#include "JsonArray.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace ArduinoJson::Generator; @@ -45,6 +46,12 @@ namespace JsonGeneratorTests setValueAndCheckCast(42L); } + TEST_METHOD(Array) + { + JsonArray<2> array; + setValueAndCheckCast(array); + } + TEST_METHOD(String) { setValueAndCheckCast("hello"); @@ -59,5 +66,13 @@ namespace JsonGeneratorTests T actual = value; Assert::AreEqual(expected, actual); } + + template + void setValueAndCheckCast(JsonArray& expected) + { + value = expected; + Printable& actual = value; + Assert::AreEqual((void*) &expected, (void*) &actual); + } }; } \ No newline at end of file