Files
ArduinoJson/JsonGeneratorTests/JsonValue_Cast_Tests.cpp

63 lines
1.2 KiB
C++
Raw Normal View History

2014-08-01 14:47:48 +02:00
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
#include "JsonValue.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonValue_Cast_Tests)
{
JsonValue value;
public:
2014-08-01 14:56:46 +02:00
TEST_METHOD(Bool)
{
setValueAndCheckCast(true);
setValueAndCheckCast(false);
}
TEST_METHOD(Double)
{
setValueAndCheckCast(3.14156);
2014-08-01 14:47:48 +02:00
}
2014-08-01 14:58:16 +02:00
TEST_METHOD(Float)
{
setValueAndCheckCast(3.14f);
}
2014-08-01 14:52:15 +02:00
TEST_METHOD(Integer)
{
setValueAndCheckCast(42);
}
2014-08-01 14:53:05 +02:00
TEST_METHOD(Long)
{
setValueAndCheckCast(42L);
}
2014-08-01 14:52:15 +02:00
2014-08-01 14:56:46 +02:00
TEST_METHOD(String)
2014-08-01 14:54:34 +02:00
{
2014-08-01 14:56:46 +02:00
setValueAndCheckCast("hello");
2014-08-01 14:54:34 +02:00
}
2014-08-01 14:47:48 +02:00
private:
2014-08-01 14:52:15 +02:00
template<typename T>
void setValueAndCheckCast(T expected)
2014-08-01 14:47:48 +02:00
{
2014-08-01 14:52:15 +02:00
value = expected;
T actual = value;
2014-08-01 14:47:48 +02:00
Assert::AreEqual(expected, actual);
}
};
}