forked from bblanchon/ArduinoJson
Added test of an empty string
This commit is contained in:
@ -7,5 +7,5 @@
|
||||
|
||||
size_t IndentedPrintDecorator::write(uint8_t c)
|
||||
{
|
||||
return print.write(c);
|
||||
return sink.write(c);
|
||||
}
|
@ -13,7 +13,7 @@ class IndentedPrintDecorator : public Print
|
||||
public:
|
||||
|
||||
IndentedPrintDecorator(Print& p)
|
||||
: currentLevel(0), print(p)
|
||||
: currentLevel(0), sink(p)
|
||||
{
|
||||
}
|
||||
|
||||
@ -21,6 +21,6 @@ public:
|
||||
|
||||
private:
|
||||
int currentLevel;
|
||||
Print& print;
|
||||
Print& sink;
|
||||
};
|
||||
|
||||
|
42
JsonGeneratorTests/IntentedPrintTests.cpp
Normal file
42
JsonGeneratorTests/IntentedPrintTests.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
TEST_CLASS(IntentedPrintTests)
|
||||
{
|
||||
char buffer[256];
|
||||
|
||||
public:
|
||||
|
||||
TEST_METHOD(EmptyString)
|
||||
{
|
||||
whenInputIs("");
|
||||
outputMustBe("");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void whenInputIs(const char input[])
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
IndentedPrintDecorator decorator(sb);
|
||||
|
||||
decorator.print(input);
|
||||
}
|
||||
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
}
|
||||
};
|
||||
}
|
@ -85,6 +85,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EscapedStringTests.cpp" />
|
||||
<ClCompile Include="IntentedPrintTests.cpp" />
|
||||
<ClCompile Include="Issue10.cpp" />
|
||||
<ClCompile Include="JsonArrayTests.cpp" />
|
||||
<ClCompile Include="JsonObject_Indexer_Tests.cpp" />
|
||||
|
@ -39,5 +39,8 @@
|
||||
<ClCompile Include="Issue10.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IntentedPrintTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user