IntegrationTests.cpp 5.2 KB

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