IntegrationTests.cpp 5.2 KB

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