JsonObject_ContainsKey_Tests.cpp 939 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright Benoit Blanchon 2014-2016
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. // If you like this project, please add a star!
  7. #include <gtest/gtest.h>
  8. #include <ArduinoJson.h>
  9. #define TEST_(name) TEST(JsonObject_Basic_Tests, name)
  10. TEST_(ContainsKeyReturnsFalseForNonExistingKey) {
  11. DynamicJsonBuffer _jsonBuffer;
  12. JsonObject& _object = _jsonBuffer.createObject();
  13. _object.set("hello", 42);
  14. EXPECT_FALSE(_object.containsKey("world"));
  15. }
  16. TEST_(ContainsKeyReturnsTrueForDefinedValue) {
  17. DynamicJsonBuffer _jsonBuffer;
  18. JsonObject& _object = _jsonBuffer.createObject();
  19. _object.set("hello", 42);
  20. EXPECT_TRUE(_object.containsKey("hello"));
  21. }
  22. TEST_(ContainsKeyReturnsFalseAfterRemove) {
  23. DynamicJsonBuffer _jsonBuffer;
  24. JsonObject& _object = _jsonBuffer.createObject();
  25. _object.set("hello", 42);
  26. _object.remove("hello");
  27. EXPECT_FALSE(_object.containsKey("hello"));
  28. }