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