misc.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <ArduinoJson.h>
  2. #include <catch.hpp>
  3. #include <limits>
  4. template <typename T>
  5. void check(T value, const std::string& expected) {
  6. DynamicJsonDocument doc(4096);
  7. doc.to<JsonVariant>().set(value);
  8. char buffer[256] = "";
  9. size_t returnValue = serializeMsgPack(doc, buffer, sizeof(buffer));
  10. REQUIRE(expected == buffer);
  11. REQUIRE(expected.size() == returnValue);
  12. }
  13. TEST_CASE("serializeMsgPack(MemberProxy)") {
  14. DynamicJsonDocument doc(4096);
  15. deserializeJson(doc, "{\"hello\":42}");
  16. JsonObject obj = doc.as<JsonObject>();
  17. std::string result;
  18. serializeMsgPack(obj["hello"], result);
  19. REQUIRE(result == "*");
  20. }
  21. TEST_CASE("serializeMsgPack(ElementProxy)") {
  22. DynamicJsonDocument doc(4096);
  23. deserializeJson(doc, "[42]");
  24. JsonArray arr = doc.as<JsonArray>();
  25. std::string result;
  26. serializeMsgPack(arr[0], result);
  27. REQUIRE(result == "*");
  28. }
  29. TEST_CASE("serializeMsgPack(JsonVariantSubscript)") {
  30. DynamicJsonDocument doc(4096);
  31. deserializeJson(doc, "[42]");
  32. JsonVariant var = doc.as<JsonVariant>();
  33. std::string result;
  34. serializeMsgPack(var[0], result);
  35. REQUIRE(result == "*");
  36. }