Files
ArduinoJson/JsonGeneratorTests/Intented_Object_Tests.cpp

74 lines
1.7 KiB
C++
Raw Normal View History

2014-08-25 09:17:32 +02:00
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "IndentedPrintDecorator.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
2014-08-25 09:19:26 +02:00
TEST_CLASS(IntentedPrintTests)
{
char buffer[1024];
size_t returnValue;
public:
2014-08-25 09:17:32 +02:00
2014-08-25 09:23:41 +02:00
TEST_METHOD(EmptyObject)
{
whenInputIs("{}");
outputMustBe("{}");
}
TEST_METHOD(OneMember)
2014-08-25 09:52:42 +02:00
{
whenInputIs("{\"key\":\"value\"}");
outputMustBe(
"{\n"
" \"key\": \"value\"\n"
2014-08-25 09:52:42 +02:00
"}");
}
2014-08-25 09:24:31 +02:00
TEST_METHOD(TwoMembers)
2014-08-25 10:22:42 +02:00
{
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
outputMustBe(
"{\n"
" \"key1\": \"value1\",\n"
" \"key2\": \"value2\"\n"
2014-08-25 10:22:42 +02:00
"}");
}
TEST_METHOD(EmptyNestedObjects)
2014-08-25 10:36:25 +02:00
{
whenInputIs("{\"key1\":{},\"key2\":{}}");
outputMustBe(
"{\n"
" \"key1\": {},\n"
" \"key2\": {}\n"
"}");
}
2014-08-25 09:17:32 +02:00
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrintDecorator decorator(sb);
2014-08-25 09:19:26 +02:00
returnValue = decorator.print(input);
2014-08-25 09:17:32 +02:00
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
2014-08-25 09:19:26 +02:00
Assert::AreEqual(strlen(expected), returnValue);
2014-08-25 09:17:32 +02:00
}
2014-08-25 09:19:26 +02:00
};
2014-08-25 09:17:32 +02:00
}