JsonObject_Indexer_Tests.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #include "CppUnitTest.h"
  6. #include "JsonArray.h"
  7. #include "JsonObject.h"
  8. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  9. using namespace ArduinoJson::Generator;
  10. namespace JsonGeneratorTests
  11. {
  12. TEST_CLASS(JsonObject_Indexer_Tests)
  13. {
  14. JsonObject<2> object;
  15. public:
  16. TEST_METHOD(Empty)
  17. {
  18. mustNotContain("key");
  19. }
  20. TEST_METHOD(OneString)
  21. {
  22. object["key"] = "value";
  23. mustContain("key", "value");
  24. }
  25. private:
  26. void mustContain(const char* key, const char* expected)
  27. {
  28. Assert::IsTrue(object.containsKey(key));
  29. const char* actual = object[key];
  30. Assert::AreEqual(expected, actual);
  31. }
  32. void mustNotContain(const char* key)
  33. {
  34. Assert::IsFalse(object.containsKey(key));
  35. const char* actual = object[key];
  36. Assert::IsNull(actual);
  37. }
  38. };
  39. }