JsonArrayTests.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "CppUnitTest.h"
  2. #include "JsonArray.h"
  3. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  4. namespace JsonGeneratorTests
  5. {
  6. TEST_CLASS(JsonArrayTests)
  7. {
  8. JsonArray<2> arr;
  9. public:
  10. TEST_METHOD(EmptyArray)
  11. {
  12. AssertJsonIs("[]");
  13. }
  14. TEST_METHOD(OneString)
  15. {
  16. arr.add("hello");
  17. AssertJsonIs("['hello']");
  18. }
  19. TEST_METHOD(TwoStrings)
  20. {
  21. arr.add("hello");
  22. arr.add("world");
  23. AssertJsonIs("['hello','world']");
  24. }
  25. TEST_METHOD(OverCapacity)
  26. {
  27. arr.add("hello");
  28. arr.add("world");
  29. arr.add("lost");
  30. AssertJsonIs("['hello','world']");
  31. }
  32. void AssertJsonIs(const char* expected)
  33. {
  34. char buffer[256];
  35. arr.writeTo(buffer, sizeof(buffer));
  36. Assert::AreEqual(expected, buffer);
  37. }
  38. };
  39. }