|
|
@@ -1,3 +1,8 @@
|
|
|
+/*
|
|
|
+* Arduino JSON library
|
|
|
+* Benoit Blanchon 2014 - MIT License
|
|
|
+*/
|
|
|
+
|
|
|
#include "CppUnitTest.h"
|
|
|
#include "JsonArray.h"
|
|
|
#include "JsonHashTable.h"
|
|
|
@@ -16,83 +21,78 @@ namespace JsonGeneratorTests
|
|
|
|
|
|
TEST_METHOD(Empty)
|
|
|
{
|
|
|
- jsonIs("{}");
|
|
|
+ outputMustBe("{}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneString)
|
|
|
{
|
|
|
- addValue("key", "value");
|
|
|
-
|
|
|
- jsonIs("{\"key\":\"value\"}");
|
|
|
+ add("key", "value");
|
|
|
+ outputMustBe("{\"key\":\"value\"}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(TwoStrings)
|
|
|
{
|
|
|
- addValue("key1", "value1");
|
|
|
- addValue("key2", "value2");
|
|
|
+ add("key1", "value1");
|
|
|
+ add("key2", "value2");
|
|
|
|
|
|
- jsonIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
+ outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneStringOverCapacity)
|
|
|
{
|
|
|
- addValue("key1", "value1");
|
|
|
- addValue("key2", "value2");
|
|
|
- addValue("key3", "value3");
|
|
|
+ add("key1", "value1");
|
|
|
+ add("key2", "value2");
|
|
|
+ add("key3", "value3");
|
|
|
|
|
|
- jsonIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
+ outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneInteger)
|
|
|
{
|
|
|
- addValue("key", 1);
|
|
|
- jsonIs("{\"key\":1}");
|
|
|
+ add("key", 1);
|
|
|
+ outputMustBe("{\"key\":1}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneDoubleFourDigits)
|
|
|
{
|
|
|
- addValue<4>("key", 3.14159265358979323846);
|
|
|
- jsonIs("{\"key\":3.1416}");
|
|
|
+ add<4>("key", 3.14159265358979323846);
|
|
|
+ outputMustBe("{\"key\":3.1416}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneDoubleDefaultDigits)
|
|
|
{
|
|
|
- addValue("key", 3.14159265358979323846);
|
|
|
- jsonIs("{\"key\":3.14}");
|
|
|
+ add("key", 3.14159265358979323846);
|
|
|
+ outputMustBe("{\"key\":3.14}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneNull)
|
|
|
{
|
|
|
- addValue("key", (char*) 0);
|
|
|
- jsonIs("{\"key\":null}");
|
|
|
+ add("key", (char*) 0);
|
|
|
+ outputMustBe("{\"key\":null}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneTrue)
|
|
|
{
|
|
|
- addValue("key", true);
|
|
|
- jsonIs("{\"key\":true}");
|
|
|
+ add("key", true);
|
|
|
+ outputMustBe("{\"key\":true}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneFalse)
|
|
|
{
|
|
|
- addValue("key", false);
|
|
|
- jsonIs("{\"key\":false}");
|
|
|
+ add("key", false);
|
|
|
+ outputMustBe("{\"key\":false}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneEmptyNestedArray)
|
|
|
{
|
|
|
- JsonArray<1> nestedArray;
|
|
|
- addNested("key", nestedArray);
|
|
|
-
|
|
|
- jsonIs("{\"key\":[]}");
|
|
|
+ addNested("key", JsonArray<1>());
|
|
|
+ outputMustBe("{\"key\":[]}");
|
|
|
}
|
|
|
|
|
|
TEST_METHOD(OneEmptyNestedHash)
|
|
|
{
|
|
|
- JsonHashTable<1> nestedHash;
|
|
|
- addNested("key", nestedHash);
|
|
|
-
|
|
|
- jsonIs("{\"key\":{}}");
|
|
|
+ addNested("key", JsonHashTable<1>());
|
|
|
+ outputMustBe("{\"key\":{}}");
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -103,18 +103,18 @@ namespace JsonGeneratorTests
|
|
|
}
|
|
|
|
|
|
template<typename T>
|
|
|
- void addValue(const char* key, T value)
|
|
|
+ void add(const char* key, T value)
|
|
|
{
|
|
|
hash.add(key, value);
|
|
|
}
|
|
|
|
|
|
template<int DIGITS>
|
|
|
- void addValue(const char* key, double value)
|
|
|
+ void add(const char* key, double value)
|
|
|
{
|
|
|
hash.add<DIGITS>(key, value);
|
|
|
}
|
|
|
|
|
|
- void jsonIs(const char* expected)
|
|
|
+ void outputMustBe(const char* expected)
|
|
|
{
|
|
|
size_t actual = hash.printTo(buffer, sizeof(buffer));
|
|
|
Assert::AreEqual(expected, buffer);
|