std_string.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("deserializeMsgPack(const std::string&)") {
  7. DynamicJsonDocument doc;
  8. SECTION("should accept const string") {
  9. const std::string input("\x92\x01\x02");
  10. MsgPackError err = deserializeMsgPack(doc, input);
  11. REQUIRE(err == MsgPackError::Ok);
  12. }
  13. SECTION("should accept temporary string") {
  14. MsgPackError err = deserializeMsgPack(doc, std::string("\x92\x01\x02"));
  15. REQUIRE(err == MsgPackError::Ok);
  16. }
  17. SECTION("should duplicate content") {
  18. std::string input("\x91\xA5hello");
  19. MsgPackError err = deserializeMsgPack(doc, input);
  20. input[2] = 'X'; // alter the string tomake sure we made a copy
  21. JsonArray& array = doc.as<JsonArray>();
  22. REQUIRE(err == MsgPackError::Ok);
  23. REQUIRE(std::string("hello") == array[0]);
  24. }
  25. SECTION("should accept a zero in input") {
  26. MsgPackError err = deserializeMsgPack(doc, std::string("\x92\x00\x02", 3));
  27. REQUIRE(err == MsgPackError::Ok);
  28. JsonArray& arr = doc.as<JsonArray>();
  29. REQUIRE(arr[0] == 0);
  30. REQUIRE(arr[1] == 2);
  31. }
  32. }