JsonObject_Indexer_Tests.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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(TwoStrings)
  21. {
  22. object["key1"] = "value1";
  23. object["key2"] = "value2";
  24. mustContain("key1", "value1");
  25. mustContain("key2", "value2");
  26. }
  27. TEST_METHOD(RemoveFirst)
  28. {
  29. object["key1"] = "value1";
  30. object["key2"] = "value2";
  31. object.remove("key1");
  32. mustNotContain("key1");
  33. mustContain("key2", "value2");
  34. }
  35. TEST_METHOD(RemoveLast)
  36. {
  37. object["key1"] = "value1";
  38. object["key2"] = "value2";
  39. object.remove("key2");
  40. mustContain("key1", "value1");
  41. mustNotContain("key2");
  42. }
  43. private:
  44. void mustContain(const char* key, const char* expected)
  45. {
  46. Assert::IsTrue(object.containsKey(key));
  47. const char* actual = object[key];
  48. Assert::AreEqual(expected, actual);
  49. }
  50. void mustNotContain(const char* key)
  51. {
  52. Assert::IsFalse(object.containsKey(key));
  53. const char* actual = object[key];
  54. Assert::IsNull(actual);
  55. }
  56. };
  57. }