forked from bblanchon/ArduinoJson
Test casting a JsonValue to an int
This commit is contained in:
@ -64,6 +64,11 @@ namespace ArduinoJson
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator int()
|
||||||
|
{
|
||||||
|
return content.asLong;
|
||||||
|
}
|
||||||
|
|
||||||
size_t printTo(Print& p) const
|
size_t printTo(Print& p) const
|
||||||
{
|
{
|
||||||
// handmade polymorphism
|
// handmade polymorphism
|
||||||
|
@ -21,15 +21,22 @@ namespace JsonGeneratorTests
|
|||||||
|
|
||||||
TEST_METHOD(String)
|
TEST_METHOD(String)
|
||||||
{
|
{
|
||||||
value = "hello";
|
setValueAndCheckCast("hello");
|
||||||
mustCastTo("hello");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Integer)
|
||||||
|
{
|
||||||
|
setValueAndCheckCast(42);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void mustCastTo(const char* expected)
|
template<typename T>
|
||||||
|
void setValueAndCheckCast(T expected)
|
||||||
{
|
{
|
||||||
const char* actual = value;
|
value = expected;
|
||||||
|
T actual = value;
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user