IntegrationTests.cpp 5.1 KB

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