destination_types.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("serialize MsgPack to various destination types") {
  7. DynamicJsonDocument doc(4096);
  8. JsonObject object = doc.to<JsonObject>();
  9. object["hello"] = "world";
  10. const char *expected_result = "\x81\xA5hello\xA5world";
  11. const size_t expected_length = 13;
  12. SECTION("std::string") {
  13. std::string result;
  14. size_t len = serializeMsgPack(object, result);
  15. REQUIRE(expected_result == result);
  16. REQUIRE(expected_length == len);
  17. }
  18. /* SECTION("std::vector<char>") {
  19. std::vector<char> result;
  20. size_t len = serializeMsgPack(object, result);
  21. REQUIRE(std::vector<char>(expected_result, expected_result + 13) ==
  22. result);
  23. REQUIRE(expected_length == len);
  24. } */
  25. SECTION("char[]") {
  26. char result[64];
  27. size_t len = serializeMsgPack(object, result);
  28. REQUIRE(std::string(expected_result) == result);
  29. REQUIRE(expected_length == len);
  30. }
  31. SECTION("char*") {
  32. char result[64];
  33. size_t len = serializeMsgPack(object, result, 64);
  34. REQUIRE(std::string(expected_result) == result);
  35. REQUIRE(expected_length == len);
  36. }
  37. }