get.cpp 892 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace Catch::Matchers;
  7. TEST_CASE("JsonObject::get()") {
  8. DynamicJsonDocument doc;
  9. JsonObject obj = doc.to<JsonObject>();
  10. SECTION("get<const char*>(const char*)") {
  11. obj.set("hello", "world");
  12. const char* value = obj.get<const char*>("hello");
  13. REQUIRE_THAT(value, Equals("world"));
  14. }
  15. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  16. SECTION("get<const char*>(VLA)") {
  17. obj.set("hello", "world");
  18. int i = 16;
  19. char vla[i];
  20. strcpy(vla, "hello");
  21. REQUIRE(std::string("world") == obj.get<char*>(vla));
  22. }
  23. #endif
  24. SECTION("works on JsonObjectConst") {
  25. obj.set("hello", "world");
  26. const char* value =
  27. static_cast<JsonObjectConst>(obj).get<const char*>("hello");
  28. REQUIRE_THAT(value, Equals("world"));
  29. }
  30. }