Test casting a JsonValue to a JsonArray

This commit is contained in:
Benoit Blanchon
2014-08-01 15:06:31 +02:00
parent 6384bc414a
commit 1a01800782
2 changed files with 20 additions and 0 deletions

View File

@ -89,6 +89,11 @@ namespace ArduinoJson
return content.asLong;
}
operator Printable&()
{
return *content.asPrintable;
}
size_t printTo(Print& p) const
{
// handmade polymorphism

View File

@ -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<int N>
void setValueAndCheckCast(JsonArray<N>& expected)
{
value = expected;
Printable& actual = value;
Assert::AreEqual((void*) &expected, (void*) &actual);
}
};
}