copyTo.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonArray::copyTo()") {
  7. DynamicJsonArray array;
  8. SECTION("BiggerOneDimensionIntegerArray") {
  9. char json[] = "[1,2,3]";
  10. bool success = deserializeJson(array, json);
  11. REQUIRE(success == true);
  12. int destination[4] = {0};
  13. size_t result = array.copyTo(destination);
  14. REQUIRE(3 == result);
  15. REQUIRE(1 == destination[0]);
  16. REQUIRE(2 == destination[1]);
  17. REQUIRE(3 == destination[2]);
  18. REQUIRE(0 == destination[3]);
  19. }
  20. SECTION("SmallerOneDimensionIntegerArray") {
  21. char json[] = "[1,2,3]";
  22. bool success = deserializeJson(array, json);
  23. REQUIRE(success == true);
  24. int destination[2] = {0};
  25. size_t result = array.copyTo(destination);
  26. REQUIRE(2 == result);
  27. REQUIRE(1 == destination[0]);
  28. REQUIRE(2 == destination[1]);
  29. }
  30. SECTION("TwoOneDimensionIntegerArray") {
  31. char json[] = "[[1,2],[3],[4]]";
  32. bool success = deserializeJson(array, json);
  33. REQUIRE(success == true);
  34. int destination[3][2] = {{0}};
  35. array.copyTo(destination);
  36. REQUIRE(1 == destination[0][0]);
  37. REQUIRE(2 == destination[0][1]);
  38. REQUIRE(3 == destination[1][0]);
  39. REQUIRE(0 == destination[1][1]);
  40. REQUIRE(4 == destination[2][0]);
  41. REQUIRE(0 == destination[2][1]);
  42. }
  43. }