set.cpp 641 B

123456789101112131415161718192021222324252627282930313233
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2020
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("ElementProxy::set()") {
  8. DynamicJsonDocument doc(4096);
  9. ElementProxy<JsonDocument&> ep = doc[0];
  10. SECTION("set(int)") {
  11. ep.set(42);
  12. REQUIRE(doc.as<std::string>() == "[42]");
  13. }
  14. SECTION("set(const char*)") {
  15. ep.set("world");
  16. REQUIRE(doc.as<std::string>() == "[\"world\"]");
  17. }
  18. SECTION("set(char[])") {
  19. char s[] = "world";
  20. ep.set(s);
  21. strcpy(s, "!!!!!");
  22. REQUIRE(doc.as<std::string>() == "[\"world\"]");
  23. }
  24. }