Added missing newline at end-of-file (issue #24)

This commit is contained in:
Benoit Blanchon
2014-09-27 21:24:29 +02:00
parent 18f93b4eb6
commit cc19266470
58 changed files with 3699 additions and 3698 deletions

View File

@@ -1,95 +1,95 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "EscapedString.h"
#include "StringBuilder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(EscapedStringTests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(Null)
{
whenInputIs(0);
outputMustBe("null");
}
TEST_METHOD(EmptyString)
{
whenInputIs("");
outputMustBe("\"\"");
}
TEST_METHOD(QuotationMark)
{
whenInputIs("\"");
outputMustBe("\"\\\"\"");
}
TEST_METHOD(ReverseSolidus)
{
whenInputIs("\\");
outputMustBe("\"\\\\\"");
}
TEST_METHOD(Solidus)
{
whenInputIs("/");
outputMustBe("\"/\""); // but the JSON format allows \/
}
TEST_METHOD(Backspace)
{
whenInputIs("\b");
outputMustBe("\"\\b\"");
}
TEST_METHOD(Formfeed)
{
whenInputIs("\f");
outputMustBe("\"\\f\"");
}
TEST_METHOD(Newline)
{
whenInputIs("\n");
outputMustBe("\"\\n\"");
}
TEST_METHOD(CarriageReturn)
{
whenInputIs("\r");
outputMustBe("\"\\r\"");
}
TEST_METHOD(HorizontalTab)
{
whenInputIs("\t");
outputMustBe("\"\\t\"");
}
private:
void whenInputIs(const char* input)
{
StringBuilder sb(buffer, sizeof(buffer));
returnValue = EscapedString::printTo(input, sb);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "EscapedString.h"
#include "StringBuilder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(EscapedStringTests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(Null)
{
whenInputIs(0);
outputMustBe("null");
}
TEST_METHOD(EmptyString)
{
whenInputIs("");
outputMustBe("\"\"");
}
TEST_METHOD(QuotationMark)
{
whenInputIs("\"");
outputMustBe("\"\\\"\"");
}
TEST_METHOD(ReverseSolidus)
{
whenInputIs("\\");
outputMustBe("\"\\\\\"");
}
TEST_METHOD(Solidus)
{
whenInputIs("/");
outputMustBe("\"/\""); // but the JSON format allows \/
}
TEST_METHOD(Backspace)
{
whenInputIs("\b");
outputMustBe("\"\\b\"");
}
TEST_METHOD(Formfeed)
{
whenInputIs("\f");
outputMustBe("\"\\f\"");
}
TEST_METHOD(Newline)
{
whenInputIs("\n");
outputMustBe("\"\\n\"");
}
TEST_METHOD(CarriageReturn)
{
whenInputIs("\r");
outputMustBe("\"\\r\"");
}
TEST_METHOD(HorizontalTab)
{
whenInputIs("\t");
outputMustBe("\"\\t\"");
}
private:
void whenInputIs(const char* input)
{
StringBuilder sb(buffer, sizeof(buffer));
returnValue = EscapedString::printTo(input, sb);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}

View File

@@ -1,73 +1,73 @@
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(Issue10)
{
struct Person {
int id;
char name[32];
};
Person persons[2];
public:
TEST_METHOD_INITIALIZE(Initialize)
{
Person boss;
boss.id = 1;
strcpy(boss.name, "Jeff");
Person employee;
employee.id = 2;
strcpy(employee.name, "John");
persons[0] = boss;
persons[1] = employee;
}
TEST_METHOD(WrongWayToAddObjectInAnArray)
{
JsonArray<2> json;
for (int i = 0; i < 2; i++)
{
JsonObject<2> object;
object["id"] = persons[i].id;
object["name"] = persons[i].name;
json.add(object); // <- Adding a reference to a temporary variable
}
char buffer[256];
json.printTo(buffer, sizeof(buffer));
// the same values are repeated, that's normal
Assert::AreEqual("[{\"id\":2,\"name\":\"John\"},{\"id\":2,\"name\":\"John\"}]", buffer);
}
TEST_METHOD(RightWayToAddObjectInAnArray)
{
JsonArray<2> json;
JsonObject<2> object[2];
for (int i = 0; i < 2; i++)
{
object[i]["id"] = persons[i].id;
object[i]["name"] = persons[i].name;
json.add(object[i]);
}
char buffer[256];
json.printTo(buffer, sizeof(buffer));
Assert::AreEqual("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer);
}
};
}
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(Issue10)
{
struct Person {
int id;
char name[32];
};
Person persons[2];
public:
TEST_METHOD_INITIALIZE(Initialize)
{
Person boss;
boss.id = 1;
strcpy(boss.name, "Jeff");
Person employee;
employee.id = 2;
strcpy(employee.name, "John");
persons[0] = boss;
persons[1] = employee;
}
TEST_METHOD(WrongWayToAddObjectInAnArray)
{
JsonArray<2> json;
for (int i = 0; i < 2; i++)
{
JsonObject<2> object;
object["id"] = persons[i].id;
object["name"] = persons[i].name;
json.add(object); // <- Adding a reference to a temporary variable
}
char buffer[256];
json.printTo(buffer, sizeof(buffer));
// the same values are repeated, that's normal
Assert::AreEqual("[{\"id\":2,\"name\":\"John\"},{\"id\":2,\"name\":\"John\"}]", buffer);
}
TEST_METHOD(RightWayToAddObjectInAnArray)
{
JsonArray<2> json;
JsonObject<2> object[2];
for (int i = 0; i < 2; i++)
{
object[i]["id"] = persons[i].id;
object[i]["name"] = persons[i].name;
json.add(object[i]);
}
char buffer[256];
json.printTo(buffer, sizeof(buffer));
Assert::AreEqual("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer);
}
};
}

View File

@@ -1,162 +1,162 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonArrayTests)
{
JsonArray<2> array;
char buffer[256];
public:
TEST_METHOD(Empty)
{
outputMustBe("[]");
}
TEST_METHOD(Null)
{
array.add((char*) 0);
outputMustBe("[null]");
}
TEST_METHOD(OneString)
{
array.add("hello");
outputMustBe("[\"hello\"]");
}
TEST_METHOD(TwoStrings)
{
array.add("hello");
array.add("world");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_METHOD(OneStringOverCapacity)
{
array.add("hello");
array.add("world");
array.add("lost");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_METHOD(OneDoubleDefaultDigits)
{
array.add(3.14159265358979323846);
outputMustBe("[3.14]");
}
TEST_METHOD(OneDoubleFourDigits)
{
array.add<4>(3.14159265358979323846);
outputMustBe("[3.1416]");
}
TEST_METHOD(OneInteger)
{
array.add(1);
outputMustBe("[1]");
}
TEST_METHOD(TwoIntegers)
{
array.add(1);
array.add(2);
outputMustBe("[1,2]");
}
TEST_METHOD(OneIntegerOverCapacity)
{
array.add(1);
array.add(2);
array.add(3);
outputMustBe("[1,2]");
}
TEST_METHOD(OneTrue)
{
array.add(true);
outputMustBe("[true]");
}
TEST_METHOD(OneFalse)
{
array.add(false);
outputMustBe("[false]");
}
TEST_METHOD(TwoBooleans)
{
array.add(false);
array.add(true);
outputMustBe("[false,true]");
}
TEST_METHOD(OneBooleanOverCapacity)
{
array.add(false);
array.add(true);
array.add(false);
outputMustBe("[false,true]");
}
TEST_METHOD(OneEmptyNestedArray)
{
JsonArray<1> nestedArray;
array.add(nestedArray);
outputMustBe("[[]]");
}
TEST_METHOD(OneEmptyNestedHash)
{
JsonObject<1> nestedObject;
array.add(nestedObject);
outputMustBe("[{}]");
}
TEST_METHOD(OneNestedArrayWithOneInteger)
{
JsonArray<1> nestedArray;
nestedArray.add(1);
array.add(nestedArray);
outputMustBe("[[1]]");
}
private:
void outputMustBe(const char* expected)
{
size_t n = array.printTo(buffer, sizeof(buffer));
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), n);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonArrayTests)
{
JsonArray<2> array;
char buffer[256];
public:
TEST_METHOD(Empty)
{
outputMustBe("[]");
}
TEST_METHOD(Null)
{
array.add((char*) 0);
outputMustBe("[null]");
}
TEST_METHOD(OneString)
{
array.add("hello");
outputMustBe("[\"hello\"]");
}
TEST_METHOD(TwoStrings)
{
array.add("hello");
array.add("world");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_METHOD(OneStringOverCapacity)
{
array.add("hello");
array.add("world");
array.add("lost");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_METHOD(OneDoubleDefaultDigits)
{
array.add(3.14159265358979323846);
outputMustBe("[3.14]");
}
TEST_METHOD(OneDoubleFourDigits)
{
array.add<4>(3.14159265358979323846);
outputMustBe("[3.1416]");
}
TEST_METHOD(OneInteger)
{
array.add(1);
outputMustBe("[1]");
}
TEST_METHOD(TwoIntegers)
{
array.add(1);
array.add(2);
outputMustBe("[1,2]");
}
TEST_METHOD(OneIntegerOverCapacity)
{
array.add(1);
array.add(2);
array.add(3);
outputMustBe("[1,2]");
}
TEST_METHOD(OneTrue)
{
array.add(true);
outputMustBe("[true]");
}
TEST_METHOD(OneFalse)
{
array.add(false);
outputMustBe("[false]");
}
TEST_METHOD(TwoBooleans)
{
array.add(false);
array.add(true);
outputMustBe("[false,true]");
}
TEST_METHOD(OneBooleanOverCapacity)
{
array.add(false);
array.add(true);
array.add(false);
outputMustBe("[false,true]");
}
TEST_METHOD(OneEmptyNestedArray)
{
JsonArray<1> nestedArray;
array.add(nestedArray);
outputMustBe("[[]]");
}
TEST_METHOD(OneEmptyNestedHash)
{
JsonObject<1> nestedObject;
array.add(nestedObject);
outputMustBe("[{}]");
}
TEST_METHOD(OneNestedArrayWithOneInteger)
{
JsonArray<1> nestedArray;
nestedArray.add(1);
array.add(nestedArray);
outputMustBe("[[1]]");
}
private:
void outputMustBe(const char* expected)
{
size_t n = array.printTo(buffer, sizeof(buffer));
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), n);
}
};
}

View File

@@ -1,73 +1,73 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonObject_Indexer_Tests)
{
JsonObject<2> object;
public:
TEST_METHOD(Empty)
{
mustNotContain("key");
}
TEST_METHOD(TwoStrings)
{
object["key1"] = "value1";
object["key2"] = "value2";
mustContain("key1", "value1");
mustContain("key2", "value2");
}
TEST_METHOD(RemoveFirst)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key1");
mustNotContain("key1");
mustContain("key2", "value2");
}
TEST_METHOD(RemoveLast)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key2");
mustContain("key1", "value1");
mustNotContain("key2");
}
private:
void mustContain(const char* key, const char* expected)
{
Assert::IsTrue(object.containsKey(key));
const char* actual = object[key];
Assert::AreEqual(expected, actual);
}
void mustNotContain(const char* key)
{
Assert::IsFalse(object.containsKey(key));
const char* actual = object[key];
Assert::IsNull(actual);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonObject_Indexer_Tests)
{
JsonObject<2> object;
public:
TEST_METHOD(Empty)
{
mustNotContain("key");
}
TEST_METHOD(TwoStrings)
{
object["key1"] = "value1";
object["key2"] = "value2";
mustContain("key1", "value1");
mustContain("key2", "value2");
}
TEST_METHOD(RemoveFirst)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key1");
mustNotContain("key1");
mustContain("key2", "value2");
}
TEST_METHOD(RemoveLast)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key2");
mustContain("key1", "value1");
mustNotContain("key2");
}
private:
void mustContain(const char* key, const char* expected)
{
Assert::IsTrue(object.containsKey(key));
const char* actual = object[key];
Assert::AreEqual(expected, actual);
}
void mustNotContain(const char* key)
{
Assert::IsFalse(object.containsKey(key));
const char* actual = object[key];
Assert::IsNull(actual);
}
};
}

View File

@@ -1,152 +1,152 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonObject_PrintTo_Tests)
{
JsonObject<2> object;
public:
TEST_METHOD(Empty)
{
outputMustBe("{}");
}
TEST_METHOD(OneString)
{
object["key"] = "value";
outputMustBe("{\"key\":\"value\"}");
}
TEST_METHOD(TwoStrings)
{
object["key1"] = "value1";
object["key2"] = "value2";
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(RemoveFirst)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key1");
outputMustBe("{\"key2\":\"value2\"}");
}
TEST_METHOD(RemoveLast)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key2");
outputMustBe("{\"key1\":\"value1\"}");
}
TEST_METHOD(RemoveUnexistingKey)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key3");
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(ReplaceExistingKey)
{
object["key"] = "value1";
object["key"] = "value2";
outputMustBe("{\"key\":\"value2\"}");
}
TEST_METHOD(OneStringOverCapacity)
{
object["key1"] = "value1";
object["key2"] = "value2";
object["key3"] = "value3";
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(OneInteger)
{
object["key"] = 1;
outputMustBe("{\"key\":1}");
}
TEST_METHOD(OneDoubleFourDigits)
{
object["key"].set<4>(3.14159265358979323846);
outputMustBe("{\"key\":3.1416}");
}
TEST_METHOD(OneDoubleDefaultDigits)
{
object["key"] = 3.14159265358979323846;
outputMustBe("{\"key\":3.14}");
}
TEST_METHOD(OneNull)
{
object["key"] = (char*) 0;
outputMustBe("{\"key\":null}");
}
TEST_METHOD(OneTrue)
{
object["key"] = true;
outputMustBe("{\"key\":true}");
}
TEST_METHOD(OneFalse)
{
object["key"] = false;
outputMustBe("{\"key\":false}");
}
TEST_METHOD(OneEmptyNestedArray)
{
auto nestedArray = JsonArray<1>();
object["key"] = nestedArray;
outputMustBe("{\"key\":[]}");
}
TEST_METHOD(OneEmptyNestedObject)
{
auto nestedObject = JsonObject<1>();
object["key"] = nestedObject;
outputMustBe("{\"key\":{}}");
}
private:
void outputMustBe(const char* expected)
{
char buffer[256];
size_t result;
result = object.printTo(buffer, sizeof(buffer));
Assert::AreEqual(strlen(expected), result);
Assert::AreEqual(expected, buffer);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonArray.h"
#include "JsonObject.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonObject_PrintTo_Tests)
{
JsonObject<2> object;
public:
TEST_METHOD(Empty)
{
outputMustBe("{}");
}
TEST_METHOD(OneString)
{
object["key"] = "value";
outputMustBe("{\"key\":\"value\"}");
}
TEST_METHOD(TwoStrings)
{
object["key1"] = "value1";
object["key2"] = "value2";
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(RemoveFirst)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key1");
outputMustBe("{\"key2\":\"value2\"}");
}
TEST_METHOD(RemoveLast)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key2");
outputMustBe("{\"key1\":\"value1\"}");
}
TEST_METHOD(RemoveUnexistingKey)
{
object["key1"] = "value1";
object["key2"] = "value2";
object.remove("key3");
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(ReplaceExistingKey)
{
object["key"] = "value1";
object["key"] = "value2";
outputMustBe("{\"key\":\"value2\"}");
}
TEST_METHOD(OneStringOverCapacity)
{
object["key1"] = "value1";
object["key2"] = "value2";
object["key3"] = "value3";
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
TEST_METHOD(OneInteger)
{
object["key"] = 1;
outputMustBe("{\"key\":1}");
}
TEST_METHOD(OneDoubleFourDigits)
{
object["key"].set<4>(3.14159265358979323846);
outputMustBe("{\"key\":3.1416}");
}
TEST_METHOD(OneDoubleDefaultDigits)
{
object["key"] = 3.14159265358979323846;
outputMustBe("{\"key\":3.14}");
}
TEST_METHOD(OneNull)
{
object["key"] = (char*) 0;
outputMustBe("{\"key\":null}");
}
TEST_METHOD(OneTrue)
{
object["key"] = true;
outputMustBe("{\"key\":true}");
}
TEST_METHOD(OneFalse)
{
object["key"] = false;
outputMustBe("{\"key\":false}");
}
TEST_METHOD(OneEmptyNestedArray)
{
auto nestedArray = JsonArray<1>();
object["key"] = nestedArray;
outputMustBe("{\"key\":[]}");
}
TEST_METHOD(OneEmptyNestedObject)
{
auto nestedObject = JsonObject<1>();
object["key"] = nestedObject;
outputMustBe("{\"key\":{}}");
}
private:
void outputMustBe(const char* expected)
{
char buffer[256];
size_t result;
result = object.printTo(buffer, sizeof(buffer));
Assert::AreEqual(strlen(expected), result);
Assert::AreEqual(expected, buffer);
}
};
}

View File

@@ -1,78 +1,78 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
#include "JsonValue.h"
#include "JsonArray.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonValue_Cast_Tests)
{
JsonValue value;
public:
TEST_METHOD(Bool)
{
setValueAndCheckCast(true);
setValueAndCheckCast(false);
}
TEST_METHOD(Double)
{
setValueAndCheckCast(3.14156);
}
TEST_METHOD(Float)
{
setValueAndCheckCast(3.14f);
}
TEST_METHOD(Integer)
{
setValueAndCheckCast(42);
}
TEST_METHOD(Long)
{
setValueAndCheckCast(42L);
}
TEST_METHOD(Array)
{
JsonArray<2> array;
setValueAndCheckCast(array);
}
TEST_METHOD(String)
{
setValueAndCheckCast("hello");
}
private:
template<typename T>
void setValueAndCheckCast(T expected)
{
value = expected;
T actual = value;
Assert::AreEqual(expected, actual);
}
template<int N>
void setValueAndCheckCast(JsonArray<N>& expected)
{
value = expected;
const Printable& actual = value;
Assert::AreEqual((void*) &expected, (void*) &actual);
}
};
}
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
#include "JsonValue.h"
#include "JsonArray.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonValue_Cast_Tests)
{
JsonValue value;
public:
TEST_METHOD(Bool)
{
setValueAndCheckCast(true);
setValueAndCheckCast(false);
}
TEST_METHOD(Double)
{
setValueAndCheckCast(3.14156);
}
TEST_METHOD(Float)
{
setValueAndCheckCast(3.14f);
}
TEST_METHOD(Integer)
{
setValueAndCheckCast(42);
}
TEST_METHOD(Long)
{
setValueAndCheckCast(42L);
}
TEST_METHOD(Array)
{
JsonArray<2> array;
setValueAndCheckCast(array);
}
TEST_METHOD(String)
{
setValueAndCheckCast("hello");
}
private:
template<typename T>
void setValueAndCheckCast(T expected)
{
value = expected;
T actual = value;
Assert::AreEqual(expected, actual);
}
template<int N>
void setValueAndCheckCast(JsonArray<N>& expected)
{
value = expected;
const Printable& actual = value;
Assert::AreEqual((void*) &expected, (void*) &actual);
}
};
}

View File

@@ -1,109 +1,109 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
#include "JsonValue.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonValue_PrintTo_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(String)
{
setValueTo("hello");
outputMustBe("\"hello\"");
}
TEST_METHOD(ZeroFloat)
{
setValueTo(0.0f);
outputMustBe("0.0");
}
TEST_METHOD(Float)
{
setValueTo(3.1415f);
outputMustBe("3.14");
}
TEST_METHOD(DoubleZeroDigits)
{
setValueTo<0>(3.14159265358979323846);
outputMustBe("3");
}
TEST_METHOD(DoubleOneDigit)
{
setValueTo<1>(3.14159265358979323846);
outputMustBe("3.1");
}
TEST_METHOD(DoubleTwoDigits)
{
setValueTo<2>(3.14159265358979323846);
outputMustBe("3.14");
}
TEST_METHOD(Integer)
{
setValueTo(314);
outputMustBe("314");
}
TEST_METHOD(Char)
{
setValueTo('A');
outputMustBe("65");
}
TEST_METHOD(Short)
{
setValueTo((short)314);
outputMustBe("314");
}
TEST_METHOD(Long)
{
setValueTo(314159265L);
outputMustBe("314159265");
}
private:
template<int DIGITS>
void setValueTo(double value)
{
StringBuilder sb(buffer, sizeof(buffer));
JsonValue jsonValue;
jsonValue.set<DIGITS>(value);
returnValue = jsonValue.printTo(sb);
}
template<typename T>
void setValueTo(T value)
{
StringBuilder sb(buffer, sizeof(buffer));
JsonValue jsonValue;
jsonValue = value;
returnValue = jsonValue.printTo(sb);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
#include "JsonValue.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonValue_PrintTo_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(String)
{
setValueTo("hello");
outputMustBe("\"hello\"");
}
TEST_METHOD(ZeroFloat)
{
setValueTo(0.0f);
outputMustBe("0.0");
}
TEST_METHOD(Float)
{
setValueTo(3.1415f);
outputMustBe("3.14");
}
TEST_METHOD(DoubleZeroDigits)
{
setValueTo<0>(3.14159265358979323846);
outputMustBe("3");
}
TEST_METHOD(DoubleOneDigit)
{
setValueTo<1>(3.14159265358979323846);
outputMustBe("3.1");
}
TEST_METHOD(DoubleTwoDigits)
{
setValueTo<2>(3.14159265358979323846);
outputMustBe("3.14");
}
TEST_METHOD(Integer)
{
setValueTo(314);
outputMustBe("314");
}
TEST_METHOD(Char)
{
setValueTo('A');
outputMustBe("65");
}
TEST_METHOD(Short)
{
setValueTo((short)314);
outputMustBe("314");
}
TEST_METHOD(Long)
{
setValueTo(314159265L);
outputMustBe("314159265");
}
private:
template<int DIGITS>
void setValueTo(double value)
{
StringBuilder sb(buffer, sizeof(buffer));
JsonValue jsonValue;
jsonValue.set<DIGITS>(value);
returnValue = jsonValue.printTo(sb);
}
template<typename T>
void setValueTo(T value)
{
StringBuilder sb(buffer, sizeof(buffer));
JsonValue jsonValue;
jsonValue = value;
returnValue = jsonValue.printTo(sb);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}

View File

@@ -1,91 +1,91 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_Array_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyArray)
{
whenInputIs("[]");
outputMustBe("[]");
}
TEST_METHOD(OneElement)
{
whenInputIs("[1]");
outputMustBe(
"[\r\n"
" 1\r\n"
"]");
}
TEST_METHOD(TwoElements)
{
whenInputIs("[1,2]");
outputMustBe(
"[\r\n"
" 1,\r\n"
" 2\r\n"
"]");
}
TEST_METHOD(EmptyNestedArrays)
{
whenInputIs("[[],[]]");
outputMustBe(
"[\r\n"
" [],\r\n"
" []\r\n"
"]");
}
TEST_METHOD(NestedArrays)
{
whenInputIs("[[1,2],[3,4]]");
outputMustBe(
"[\r\n"
" [\r\n"
" 1,\r\n"
" 2\r\n"
" ],\r\n"
" [\r\n"
" 3,\r\n"
" 4\r\n"
" ]\r\n"
"]");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_Array_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyArray)
{
whenInputIs("[]");
outputMustBe("[]");
}
TEST_METHOD(OneElement)
{
whenInputIs("[1]");
outputMustBe(
"[\r\n"
" 1\r\n"
"]");
}
TEST_METHOD(TwoElements)
{
whenInputIs("[1,2]");
outputMustBe(
"[\r\n"
" 1,\r\n"
" 2\r\n"
"]");
}
TEST_METHOD(EmptyNestedArrays)
{
whenInputIs("[[],[]]");
outputMustBe(
"[\r\n"
" [],\r\n"
" []\r\n"
"]");
}
TEST_METHOD(NestedArrays)
{
whenInputIs("[[1,2],[3,4]]");
outputMustBe(
"[\r\n"
" [\r\n"
" 1,\r\n"
" 2\r\n"
" ],\r\n"
" [\r\n"
" 3,\r\n"
" 4\r\n"
" ]\r\n"
"]");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}

View File

@@ -1,89 +1,89 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_Object_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyObject)
{
whenInputIs("{}");
outputMustBe("{}");
}
TEST_METHOD(OneMember)
{
whenInputIs("{\"key\":\"value\"}");
outputMustBe(
"{\r\n"
" \"key\": \"value\"\r\n"
"}");
}
TEST_METHOD(TwoMembers)
{
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
outputMustBe(
"{\r\n"
" \"key1\": \"value1\",\r\n"
" \"key2\": \"value2\"\r\n"
"}");
}
TEST_METHOD(EmptyNestedObjects)
{
whenInputIs("{\"key1\":{},\"key2\":{}}");
outputMustBe(
"{\r\n"
" \"key1\": {},\r\n"
" \"key2\": {}\r\n"
"}");
}
TEST_METHOD(NestedObjects)
{
whenInputIs("{\"key1\":{\"a\":1},\"key2\":{\"b\":2}}");
outputMustBe(
"{\r\n"
" \"key1\": {\r\n"
" \"a\": 1\r\n"
" },\r\n"
" \"key2\": {\r\n"
" \"b\": 2\r\n"
" }\r\n"
"}");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_Object_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyObject)
{
whenInputIs("{}");
outputMustBe("{}");
}
TEST_METHOD(OneMember)
{
whenInputIs("{\"key\":\"value\"}");
outputMustBe(
"{\r\n"
" \"key\": \"value\"\r\n"
"}");
}
TEST_METHOD(TwoMembers)
{
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
outputMustBe(
"{\r\n"
" \"key1\": \"value1\",\r\n"
" \"key2\": \"value2\"\r\n"
"}");
}
TEST_METHOD(EmptyNestedObjects)
{
whenInputIs("{\"key1\":{},\"key2\":{}}");
outputMustBe(
"{\r\n"
" \"key1\": {},\r\n"
" \"key2\": {}\r\n"
"}");
}
TEST_METHOD(NestedObjects)
{
whenInputIs("{\"key1\":{\"a\":1},\"key2\":{\"b\":2}}");
outputMustBe(
"{\r\n"
" \"key1\": {\r\n"
" \"a\": 1\r\n"
" },\r\n"
" \"key2\": {\r\n"
" \"b\": 2\r\n"
" }\r\n"
"}");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}

View File

@@ -1,76 +1,76 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_String_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyString)
{
whenInputIs("");
outputMustBe("");
}
TEST_METHOD(TrickyCharacters)
{
whenInputIs ("\":\\\"',\"");
outputMustBe("\":\\\"',\"");
}
TEST_METHOD(OpeningCurlyBrace)
{
whenInputIs ("\"{\"");
outputMustBe("\"{\"");
}
TEST_METHOD(OpeningSquareBrace)
{
whenInputIs("\"[\"");
outputMustBe("\"[\"");
}
TEST_METHOD(ClosingCurlyBrace)
{
whenInputIs("\"}\"");
outputMustBe("\"}\"");
}
TEST_METHOD(ClosingSquareBrace)
{
whenInputIs("\"]\"");
outputMustBe("\"]\"");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "JsonPrettyPrint.h"
#include "StringBuilder.h"
using namespace ArduinoJson::Internals;
using namespace ArduinoJson::Generator;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(PrettyPrint_String_Tests)
{
char buffer[1024];
size_t returnValue;
public:
TEST_METHOD(EmptyString)
{
whenInputIs("");
outputMustBe("");
}
TEST_METHOD(TrickyCharacters)
{
whenInputIs ("\":\\\"',\"");
outputMustBe("\":\\\"',\"");
}
TEST_METHOD(OpeningCurlyBrace)
{
whenInputIs ("\"{\"");
outputMustBe("\"{\"");
}
TEST_METHOD(OpeningSquareBrace)
{
whenInputIs("\"[\"");
outputMustBe("\"[\"");
}
TEST_METHOD(ClosingCurlyBrace)
{
whenInputIs("\"}\"");
outputMustBe("\"}\"");
}
TEST_METHOD(ClosingSquareBrace)
{
whenInputIs("\"]\"");
outputMustBe("\"]\"");
}
private:
void whenInputIs(const char input[])
{
StringBuilder sb(buffer, sizeof(buffer));
IndentedPrint indentedPrint(sb);
JsonPrettyPrint decorator(indentedPrint);
returnValue = decorator.print(input);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
Assert::AreEqual(strlen(expected), returnValue);
}
};
}

View File

@@ -1,85 +1,85 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(StringBuilderTests)
{
char buffer[20];
Print* sb;
size_t returnValue;
public:
TEST_METHOD_INITIALIZE(Initialize)
{
sb = new StringBuilder(buffer, sizeof(buffer));
}
TEST_METHOD(InitialState)
{
outputMustBe("");
}
TEST_METHOD(OverCapacity)
{
print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
resultMustBe(19);
print("ABC");
resultMustBe(0);
outputMustBe("ABCDEFGHIJKLMNOPQRS");
}
TEST_METHOD(EmptyString)
{
print("");
resultMustBe(0);
outputMustBe("");
}
TEST_METHOD(OneString)
{
print("ABCD");
resultMustBe(4);
outputMustBe("ABCD");
}
TEST_METHOD(TwoStrings)
{
print("ABCD");
resultMustBe(4);
print("EFGH");
resultMustBe(4);
outputMustBe("ABCDEFGH");
}
private:
void print(const char* value)
{
returnValue = sb->print(value);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
}
void resultMustBe(size_t expected)
{
Assert::AreEqual(expected, returnValue);
}
};
}
*/
#include "CppUnitTest.h"
#include "StringBuilder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArduinoJson::Internals;
namespace JsonGeneratorTests
{
TEST_CLASS(StringBuilderTests)
{
char buffer[20];
Print* sb;
size_t returnValue;
public:
TEST_METHOD_INITIALIZE(Initialize)
{
sb = new StringBuilder(buffer, sizeof(buffer));
}
TEST_METHOD(InitialState)
{
outputMustBe("");
}
TEST_METHOD(OverCapacity)
{
print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
resultMustBe(19);
print("ABC");
resultMustBe(0);
outputMustBe("ABCDEFGHIJKLMNOPQRS");
}
TEST_METHOD(EmptyString)
{
print("");
resultMustBe(0);
outputMustBe("");
}
TEST_METHOD(OneString)
{
print("ABCD");
resultMustBe(4);
outputMustBe("ABCD");
}
TEST_METHOD(TwoStrings)
{
print("ABCD");
resultMustBe(4);
print("EFGH");
resultMustBe(4);
outputMustBe("ABCDEFGH");
}
private:
void print(const char* value)
{
returnValue = sb->print(value);
}
void outputMustBe(const char* expected)
{
Assert::AreEqual(expected, buffer);
}
void resultMustBe(size_t expected)
{
Assert::AreEqual(expected, returnValue);
}
};
}