JsonArrayTests.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. TEST_METHOD(OneNumber)
  33. {
  34. arr.add(3.14);
  35. AssertJsonIs("[3.14]");
  36. }
  37. void AssertJsonIs(const char* expected)
  38. {
  39. char buffer[256];
  40. arr.writeTo(buffer, sizeof(buffer));
  41. Assert::AreEqual(expected, buffer);
  42. }
  43. };
  44. }