std_string.cpp 863 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("deserializeJson(const std::string&)") {
  7. DynamicJsonDocument doc;
  8. SECTION("should accept const string") {
  9. const std::string input("[42]");
  10. JsonError err = deserializeJson(doc, input);
  11. REQUIRE(err == JsonError::Ok);
  12. }
  13. SECTION("should accept temporary string") {
  14. JsonError err = deserializeJson(doc, std::string("[42]"));
  15. REQUIRE(err == JsonError::Ok);
  16. }
  17. SECTION("should duplicate content") {
  18. std::string input("[\"hello\"]");
  19. JsonError err = deserializeJson(doc, input);
  20. input[2] = 'X'; // alter the string tomake sure we made a copy
  21. JsonArray &array = doc.as<JsonArray>();
  22. REQUIRE(err == JsonError::Ok);
  23. REQUIRE(std::string("hello") == array[0]);
  24. }
  25. }