round_trip.cpp 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. void check(std::string originalJson) {
  7. DynamicJsonDocument doc(16384);
  8. std::string prettyJson;
  9. deserializeJson(doc, originalJson);
  10. serializeJsonPretty(doc, prettyJson);
  11. std::string finalJson;
  12. deserializeJson(doc, originalJson);
  13. serializeJson(doc, finalJson);
  14. REQUIRE(originalJson == finalJson);
  15. }
  16. TEST_CASE("Round Trip: parse -> prettyPrint -> parse -> print") {
  17. SECTION("OpenWeatherMap") {
  18. check(
  19. "{\"coord\":{\"lon\":145.77,\"lat\":-16.92},\"sys\":{\"type\":1,\"id\":"
  20. "8166,\"message\":0.1222,\"country\":\"AU\",\"sunrise\":1414784325,"
  21. "\"sunset\":1414830137},\"weather\":[{\"id\":801,\"main\":\"Clouds\","
  22. "\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"cmc "
  23. "stations\",\"main\":{\"temp\":296.15,\"pressure\":1014,\"humidity\":"
  24. "83,\"temp_min\":296.15,\"temp_max\":296.15},\"wind\":{\"speed\":2.22,"
  25. "\"deg\":114.501},\"clouds\":{\"all\":20},\"dt\":1414846800,\"id\":"
  26. "2172797,\"name\":\"Cairns\",\"cod\":200}");
  27. }
  28. SECTION("YahooQueryLanguage") {
  29. check(
  30. "{\"query\":{\"count\":40,\"created\":\"2014-11-01T14:16:49Z\","
  31. "\"lang\":\"fr-FR\",\"results\":{\"item\":[{\"title\":\"Burkina army "
  32. "backs Zida as interim leader\"},{\"title\":\"British jets intercept "
  33. "Russian bombers\"},{\"title\":\"Doubts chip away at nation's most "
  34. "trusted agencies\"},{\"title\":\"Cruise ship stuck off Norway, no "
  35. "damage\"},{\"title\":\"U.S. military launches 10 air strikes in "
  36. "Syria, Iraq\"},{\"title\":\"Blackout hits Bangladesh as line from "
  37. "India fails\"},{\"title\":\"Burkina Faso president in Ivory Coast "
  38. "after ouster\"},{\"title\":\"Kurds in Turkey rally to back city "
  39. "besieged by IS\"},{\"title\":\"A majority of Scots would vote for "
  40. "independence now:poll\"},{\"title\":\"Tunisia elections possible "
  41. "model for region\"},{\"title\":\"Islamic State kills 85 more members "
  42. "of Iraqi tribe\"},{\"title\":\"Iraqi officials:IS extremists line "
  43. "up, kill 50\"},{\"title\":\"Burkina Faso army backs presidential "
  44. "guard official to lead transition\"},{\"title\":\"Kurdish peshmerga "
  45. "arrive with weapons in Syria's Kobani\"},{\"title\":\"Driver sought "
  46. "in crash that killed 3 on Halloween\"},{\"title\":\"Ex-Marine arrives "
  47. "in US after release from Mexico jail\"},{\"title\":\"UN panel "
  48. "scrambling to finish climate report\"},{\"title\":\"Investigators, "
  49. "Branson go to spacecraft crash site\"},{\"title\":\"Soldiers vie for "
  50. "power after Burkina Faso president quits\"},{\"title\":\"For a man "
  51. "without a party, turnout is big test\"},{\"title\":\"'We just had a "
  52. "hunch':US marshals nab Eric Frein\"},{\"title\":\"Boko Haram leader "
  53. "threatens to kill German hostage\"},{\"title\":\"Nurse free to move "
  54. "about as restrictions eased\"},{\"title\":\"Former Burkina president "
  55. "Compaore arrives in Ivory Coast:sources\"},{\"title\":\"Libyan port "
  56. "rebel leader refuses to hand over oil ports to rival "
  57. "group\"},{\"title\":\"Iraqi peshmerga fighters prepare for Syria "
  58. "battle\"},{\"title\":\"1 Dem Senate candidate welcoming Obama's "
  59. "help\"},{\"title\":\"Bikers cancel party after police recover "
  60. "bar\"},{\"title\":\"New question in Texas:Can Davis survive "
  61. "defeat?\"},{\"title\":\"Ukraine rebels to hold election, despite "
  62. "criticism\"},{\"title\":\"Iraqi officials say Islamic State group "
  63. "lines up, kills 50 tribesmen, women in Anbar "
  64. "province\"},{\"title\":\"James rebounds, leads Cavaliers past "
  65. "Bulls\"},{\"title\":\"UK warns travelers they could be terror "
  66. "targets\"},{\"title\":\"Hello Kitty celebrates 40th "
  67. "birthday\"},{\"title\":\"A look at people killed during space "
  68. "missions\"},{\"title\":\"Nigeria's purported Boko Haram leader says "
  69. "has 'married off' girls:AFP\"},{\"title\":\"Mexico orders immediate "
  70. "release of Marine veteran\"},{\"title\":\"As election closes in, "
  71. "Obama on center stage\"},{\"title\":\"Body of Zambian president "
  72. "arrives home\"},{\"title\":\"South Africa arrests 2 Vietnamese for "
  73. "poaching\"}]}}}");
  74. }
  75. }