JsonObjectIteratorTests.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "CppUnitTest.h"
  2. #include "JsonParser.h"
  3. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  4. using namespace ArduinoJson::Parser;
  5. namespace JsonParserTests
  6. {
  7. TEST_CLASS(JsonObjectIteratorTests)
  8. {
  9. public:
  10. TEST_METHOD(EmptyObject)
  11. {
  12. char json [] = "{}";
  13. JsonParser<1> parser;
  14. JsonHashTable a = parser.parse(json);
  15. int loopCount = 0;
  16. for (auto i : a)
  17. {
  18. loopCount++;
  19. }
  20. Assert::AreEqual(0, loopCount);
  21. }
  22. TEST_METHOD(EmptyJson)
  23. {
  24. char json[] = "";
  25. JsonParser<1> parser;
  26. JsonHashTable a = parser.parse(json);
  27. int loopCount = 0;
  28. for (auto i : a)
  29. {
  30. loopCount++;
  31. }
  32. Assert::AreEqual(0, loopCount);
  33. }
  34. TEST_METHOD(ThreeStrings)
  35. {
  36. char json[] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
  37. char* expectedKeys[] = { "key1", "key2", "key3" };
  38. char* expectedValues[] = { "value1", "value2", "value3" };
  39. JsonParser<7> parser;
  40. JsonHashTable a = parser.parse(json);
  41. int index = 0;
  42. for (auto i : a)
  43. {
  44. Assert::AreEqual(expectedKeys[index], i.key());
  45. Assert::AreEqual(expectedValues[index], (const char*) i.value());
  46. index++;
  47. }
  48. }
  49. };
  50. }