| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include "CppUnitTest.h"
- #include "JsonArray.h"
- using namespace Microsoft::VisualStudio::CppUnitTestFramework;
- namespace JsonGeneratorTests
- {
- TEST_CLASS(JsonArrayTests)
- {
- JsonArray<2> arr;
-
- public:
-
- TEST_METHOD(EmptyArray)
- {
- AssertJsonIs("[]");
- }
- TEST_METHOD(AddOneString)
- {
- arr.add("hello");
- AssertJsonIs("['hello']");
- }
- TEST_METHOD(AddTwoStrings)
- {
- arr.add("hello");
- arr.add("world");
- AssertJsonIs("['hello','world']");
- }
- TEST_METHOD(AddOneStringOverCapacity)
- {
- arr.add("hello");
- arr.add("world");
- arr.add("lost");
- AssertJsonIs("['hello','world']");
- }
- TEST_METHOD(AddOneNumber)
- {
- arr.add(3.14);
- AssertJsonIs("[3.14]");
- }
- TEST_METHOD(AddTwoNumbers)
- {
- arr.add(3.14);
- arr.add(2.72);
- AssertJsonIs("[3.14,2.72]");
- }
- void AssertJsonIs(const char* expected)
- {
- char buffer[256];
- arr.writeTo(buffer, sizeof(buffer));
- Assert::AreEqual(expected, buffer);
- }
- };
- }
|