2014-08-25 10:42:00 +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 10:55:09 +02:00
|
|
|
TEST_CLASS(Indented_Array_Tests)
|
2014-08-25 10:42:00 +02:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
size_t returnValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
TEST_METHOD(EmptyArray)
|
|
|
|
{
|
|
|
|
whenInputIs("[]");
|
|
|
|
outputMustBe("[]");
|
|
|
|
}
|
|
|
|
|
2014-08-25 10:55:09 +02:00
|
|
|
TEST_METHOD(OneElement)
|
|
|
|
{
|
|
|
|
whenInputIs("[1]");
|
|
|
|
outputMustBe(
|
|
|
|
"[\n"
|
|
|
|
" 1\n"
|
|
|
|
"]");
|
|
|
|
}
|
|
|
|
|
2014-08-25 10:42:00 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
void whenInputIs(const char input[])
|
|
|
|
{
|
|
|
|
StringBuilder sb(buffer, sizeof(buffer));
|
|
|
|
IndentedPrintDecorator decorator(sb);
|
|
|
|
|
|
|
|
returnValue = decorator.print(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
void outputMustBe(const char* expected)
|
|
|
|
{
|
|
|
|
Assert::AreEqual(expected, buffer);
|
|
|
|
Assert::AreEqual(strlen(expected), returnValue);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|