JsonObjectIteratorTests.cpp 1.6 KB

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