deserializeArray.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(JsonArray&)") {
  7. DynamicJsonArray array;
  8. SECTION("not an array") {
  9. const char* input = "\xA0";
  10. MsgPackError error = deserializeMsgPack(array, input);
  11. REQUIRE(error == MsgPackError::NotAnArray);
  12. }
  13. SECTION("fixarray") {
  14. SECTION("empty") {
  15. const char* input = "\x90";
  16. MsgPackError error = deserializeMsgPack(array, input);
  17. REQUIRE(error == MsgPackError::Ok);
  18. REQUIRE(array.size() == 0);
  19. }
  20. SECTION("two integers") {
  21. const char* input = "\x92\x01\x02";
  22. MsgPackError error = deserializeMsgPack(array, input);
  23. REQUIRE(error == MsgPackError::Ok);
  24. REQUIRE(array.size() == 2);
  25. REQUIRE(array[0] == 1);
  26. REQUIRE(array[1] == 2);
  27. }
  28. }
  29. SECTION("array 16") {
  30. SECTION("empty") {
  31. const char* input = "\xDC\x00\x00";
  32. MsgPackError error = deserializeMsgPack(array, input);
  33. REQUIRE(error == MsgPackError::Ok);
  34. REQUIRE(array.size() == 0);
  35. }
  36. SECTION("two strings") {
  37. const char* input = "\xDC\x00\x02\xA5hello\xA5world";
  38. MsgPackError error = deserializeMsgPack(array, input);
  39. REQUIRE(error == MsgPackError::Ok);
  40. REQUIRE(array.size() == 2);
  41. REQUIRE(array[0] == "hello");
  42. REQUIRE(array[1] == "world");
  43. }
  44. }
  45. SECTION("array 32") {
  46. SECTION("empty") {
  47. const char* input = "\xDD\x00\x00\x00\x00";
  48. MsgPackError error = deserializeMsgPack(array, input);
  49. REQUIRE(error == MsgPackError::Ok);
  50. REQUIRE(array.size() == 0);
  51. }
  52. SECTION("two floats") {
  53. const char* input =
  54. "\xDD\x00\x00\x00\x02\xCA\x00\x00\x00\x00\xCA\x40\x48\xF5\xC3";
  55. MsgPackError error = deserializeMsgPack(array, input);
  56. REQUIRE(error == MsgPackError::Ok);
  57. REQUIRE(array.size() == 2);
  58. REQUIRE(array[0] == 0.0f);
  59. REQUIRE(array[1] == 3.14f);
  60. }
  61. }
  62. }