2014-06-24 13:19:23 +02:00
|
|
|
#include "CppUnitTest.h"
|
|
|
|
#include "JsonArray.h"
|
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
namespace JsonGeneratorTests
|
|
|
|
{
|
|
|
|
TEST_CLASS(JsonArrayTests)
|
|
|
|
{
|
2014-06-24 13:38:48 +02:00
|
|
|
JsonArray<2> arr;
|
2014-06-24 13:34:55 +02:00
|
|
|
|
2014-06-24 13:19:23 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
TEST_METHOD(EmptyArray)
|
|
|
|
{
|
2014-06-24 13:34:55 +02:00
|
|
|
AssertJsonIs("[]");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(OneString)
|
|
|
|
{
|
|
|
|
arr.add("hello");
|
2014-06-24 13:19:23 +02:00
|
|
|
|
2014-06-24 13:34:55 +02:00
|
|
|
AssertJsonIs("['hello']");
|
|
|
|
}
|
|
|
|
|
2014-06-24 13:36:40 +02:00
|
|
|
TEST_METHOD(TwoStrings)
|
|
|
|
{
|
|
|
|
arr.add("hello");
|
|
|
|
arr.add("world");
|
|
|
|
|
|
|
|
AssertJsonIs("['hello','world']");
|
|
|
|
}
|
|
|
|
|
2014-06-24 13:38:48 +02:00
|
|
|
TEST_METHOD(OverCapacity)
|
|
|
|
{
|
|
|
|
arr.add("hello");
|
|
|
|
arr.add("world");
|
|
|
|
arr.add("lost");
|
|
|
|
|
|
|
|
AssertJsonIs("['hello','world']");
|
|
|
|
}
|
|
|
|
|
2014-06-24 13:34:55 +02:00
|
|
|
void AssertJsonIs(const char* expected)
|
|
|
|
{
|
2014-06-24 13:19:23 +02:00
|
|
|
char buffer[256];
|
2014-06-24 13:34:55 +02:00
|
|
|
|
2014-06-24 13:19:23 +02:00
|
|
|
arr.writeTo(buffer, sizeof(buffer));
|
|
|
|
|
2014-06-24 13:34:55 +02:00
|
|
|
Assert::AreEqual(expected, buffer);
|
2014-06-24 13:19:23 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|