JsonObject_ContainsKey_Tests.cpp 891 B

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