mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
Moved ancillary files to extras/
(fixes #1011)
This commit is contained in:
19
extras/tests/IntegrationTests/CMakeLists.txt
Normal file
19
extras/tests/IntegrationTests/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# MIT License
|
||||
|
||||
add_executable(IntegrationTests
|
||||
gbathree.cpp
|
||||
issue772.cpp
|
||||
round_trip.cpp
|
||||
)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(IntegrationTests
|
||||
PUBLIC
|
||||
-fsingle-precision-constant # issue 544
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(IntegrationTests catch)
|
||||
add_test(IntegrationTests IntegrationTests)
|
210
extras/tests/IntegrationTests/gbathree.cpp
Normal file
210
extras/tests/IntegrationTests/gbathree.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("Gbathree") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
DeserializationError error = deserializeJson(
|
||||
doc,
|
||||
"{\"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,"
|
||||
"\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_"
|
||||
"baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":"
|
||||
"10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":"
|
||||
"255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],"
|
||||
"\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,"
|
||||
"34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],"
|
||||
"\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,"
|
||||
"15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],"
|
||||
"[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}");
|
||||
JsonObject root = doc.as<JsonObject>();
|
||||
|
||||
SECTION("Success") {
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
}
|
||||
|
||||
SECTION("ProtocolName") {
|
||||
REQUIRE("fluorescence" == root["protocol_name"]);
|
||||
}
|
||||
|
||||
SECTION("Repeats") {
|
||||
REQUIRE(1 == root["repeats"]);
|
||||
}
|
||||
|
||||
SECTION("Wait") {
|
||||
REQUIRE(0 == root["wait"]);
|
||||
}
|
||||
|
||||
SECTION("Measurements") {
|
||||
REQUIRE(3 == root["measurements"]);
|
||||
}
|
||||
|
||||
SECTION("Meas2_Light") {
|
||||
REQUIRE(15 == root["meas2_light"]);
|
||||
}
|
||||
|
||||
SECTION("Meas1_Baseline") {
|
||||
REQUIRE(0 == root["meas1_baseline"]);
|
||||
}
|
||||
|
||||
SECTION("Act_Light") {
|
||||
REQUIRE(20 == root["act_light"]);
|
||||
}
|
||||
|
||||
SECTION("Pulsesize") {
|
||||
REQUIRE(25 == root["pulsesize"]);
|
||||
}
|
||||
|
||||
SECTION("Pulsedistance") {
|
||||
REQUIRE(10000 == root["pulsedistance"]);
|
||||
}
|
||||
|
||||
SECTION("Actintensity1") {
|
||||
REQUIRE(50 == root["actintensity1"]);
|
||||
}
|
||||
|
||||
SECTION("Actintensity2") {
|
||||
REQUIRE(255 == root["actintensity2"]);
|
||||
}
|
||||
|
||||
SECTION("Measintensity") {
|
||||
REQUIRE(255 == root["measintensity"]);
|
||||
}
|
||||
|
||||
SECTION("Calintensity") {
|
||||
REQUIRE(255 == root["calintensity"]);
|
||||
}
|
||||
|
||||
SECTION("Pulses") {
|
||||
// "pulses":[50,50,50]
|
||||
|
||||
JsonArray array = root["pulses"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(3 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
REQUIRE(50 == array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Act") {
|
||||
// "act":[2,1,2,2]
|
||||
|
||||
JsonArray array = root["act"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(4 == array.size());
|
||||
REQUIRE(2 == array[0]);
|
||||
REQUIRE(1 == array[1]);
|
||||
REQUIRE(2 == array[2]);
|
||||
REQUIRE(2 == array[3]);
|
||||
}
|
||||
|
||||
SECTION("Detectors") {
|
||||
// "detectors":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]]
|
||||
|
||||
JsonArray array = root["detectors"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
JsonArray nestedArray = array[i];
|
||||
REQUIRE(4 == nestedArray.size());
|
||||
|
||||
for (size_t j = 0; j < 4; j++) {
|
||||
REQUIRE(34 == nestedArray[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Alta") {
|
||||
// alta:[2,2,2,2]
|
||||
|
||||
JsonArray array = root["alta"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
REQUIRE(2 == array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Altb") {
|
||||
// altb:[2,2,2,2]
|
||||
|
||||
JsonArray array = root["altb"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
REQUIRE(2 == array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Measlights") {
|
||||
// "measlights":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
|
||||
|
||||
JsonArray array = root["measlights"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
JsonArray nestedArray = array[i];
|
||||
|
||||
REQUIRE(4 == nestedArray.size());
|
||||
|
||||
for (size_t j = 0; j < 4; j++) {
|
||||
REQUIRE(15 == nestedArray[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Measlights2") {
|
||||
// "measlights2":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
|
||||
|
||||
JsonArray array = root["measlights2"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
JsonArray nestedArray = array[i];
|
||||
REQUIRE(4 == nestedArray.size());
|
||||
|
||||
for (size_t j = 0; j < 4; j++) {
|
||||
REQUIRE(15 == nestedArray[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Altc") {
|
||||
// altc:[2,2,2,2]
|
||||
|
||||
JsonArray array = root["altc"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
REQUIRE(2 == array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Altd") {
|
||||
// altd:[2,2,2,2]
|
||||
|
||||
JsonArray array = root["altd"];
|
||||
REQUIRE(array.isNull() == false);
|
||||
|
||||
REQUIRE(4 == array.size());
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
REQUIRE(2 == array[i]);
|
||||
}
|
||||
}
|
||||
}
|
28
extras/tests/IntegrationTests/issue772.cpp
Normal file
28
extras/tests/IntegrationTests/issue772.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
// https://github.com/bblanchon/ArduinoJson/issues/772
|
||||
|
||||
TEST_CASE("Issue772") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err;
|
||||
std::string data =
|
||||
"{\"state\":{\"reported\":{\"timestamp\":\"2018-07-02T09:40:12Z\","
|
||||
"\"mac\":\"2C3AE84FC076\",\"firmwareVersion\":\"v0.2.7-5-gf4d4d78\","
|
||||
"\"visibleLight\":261,\"infraRed\":255,\"ultraViolet\":0.02,"
|
||||
"\"Temperature\":26.63,\"Pressure\":101145.7,\"Humidity\":54.79883,"
|
||||
"\"Vbat\":4.171261,\"soilMoisture\":0,\"ActB\":0}}}";
|
||||
err = deserializeJson(doc1, data);
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
||||
data = "";
|
||||
serializeMsgPack(doc1, data);
|
||||
err = deserializeMsgPack(doc2, data);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
82
extras/tests/IntegrationTests/round_trip.cpp
Normal file
82
extras/tests/IntegrationTests/round_trip.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
void check(std::string originalJson) {
|
||||
DynamicJsonDocument doc(16384);
|
||||
|
||||
std::string prettyJson;
|
||||
deserializeJson(doc, originalJson);
|
||||
serializeJsonPretty(doc, prettyJson);
|
||||
|
||||
std::string finalJson;
|
||||
deserializeJson(doc, originalJson);
|
||||
serializeJson(doc, finalJson);
|
||||
|
||||
REQUIRE(originalJson == finalJson);
|
||||
}
|
||||
|
||||
TEST_CASE("Round Trip: parse -> prettyPrint -> parse -> print") {
|
||||
SECTION("OpenWeatherMap") {
|
||||
check(
|
||||
"{\"coord\":{\"lon\":145.77,\"lat\":-16.92},\"sys\":{\"type\":1,\"id\":"
|
||||
"8166,\"message\":0.1222,\"country\":\"AU\",\"sunrise\":1414784325,"
|
||||
"\"sunset\":1414830137},\"weather\":[{\"id\":801,\"main\":\"Clouds\","
|
||||
"\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"cmc "
|
||||
"stations\",\"main\":{\"temp\":296.15,\"pressure\":1014,\"humidity\":"
|
||||
"83,\"temp_min\":296.15,\"temp_max\":296.15},\"wind\":{\"speed\":2.22,"
|
||||
"\"deg\":114.501},\"clouds\":{\"all\":20},\"dt\":1414846800,\"id\":"
|
||||
"2172797,\"name\":\"Cairns\",\"cod\":200}");
|
||||
}
|
||||
|
||||
SECTION("YahooQueryLanguage") {
|
||||
check(
|
||||
"{\"query\":{\"count\":40,\"created\":\"2014-11-01T14:16:49Z\","
|
||||
"\"lang\":\"fr-FR\",\"results\":{\"item\":[{\"title\":\"Burkina army "
|
||||
"backs Zida as interim leader\"},{\"title\":\"British jets intercept "
|
||||
"Russian bombers\"},{\"title\":\"Doubts chip away at nation's most "
|
||||
"trusted agencies\"},{\"title\":\"Cruise ship stuck off Norway, no "
|
||||
"damage\"},{\"title\":\"U.S. military launches 10 air strikes in "
|
||||
"Syria, Iraq\"},{\"title\":\"Blackout hits Bangladesh as line from "
|
||||
"India fails\"},{\"title\":\"Burkina Faso president in Ivory Coast "
|
||||
"after ouster\"},{\"title\":\"Kurds in Turkey rally to back city "
|
||||
"besieged by IS\"},{\"title\":\"A majority of Scots would vote for "
|
||||
"independence now:poll\"},{\"title\":\"Tunisia elections possible "
|
||||
"model for region\"},{\"title\":\"Islamic State kills 85 more members "
|
||||
"of Iraqi tribe\"},{\"title\":\"Iraqi officials:IS extremists line "
|
||||
"up, kill 50\"},{\"title\":\"Burkina Faso army backs presidential "
|
||||
"guard official to lead transition\"},{\"title\":\"Kurdish peshmerga "
|
||||
"arrive with weapons in Syria's Kobani\"},{\"title\":\"Driver sought "
|
||||
"in crash that killed 3 on Halloween\"},{\"title\":\"Ex-Marine arrives "
|
||||
"in US after release from Mexico jail\"},{\"title\":\"UN panel "
|
||||
"scrambling to finish climate report\"},{\"title\":\"Investigators, "
|
||||
"Branson go to spacecraft crash site\"},{\"title\":\"Soldiers vie for "
|
||||
"power after Burkina Faso president quits\"},{\"title\":\"For a man "
|
||||
"without a party, turnout is big test\"},{\"title\":\"'We just had a "
|
||||
"hunch':US marshals nab Eric Frein\"},{\"title\":\"Boko Haram leader "
|
||||
"threatens to kill German hostage\"},{\"title\":\"Nurse free to move "
|
||||
"about as restrictions eased\"},{\"title\":\"Former Burkina president "
|
||||
"Compaore arrives in Ivory Coast:sources\"},{\"title\":\"Libyan port "
|
||||
"rebel leader refuses to hand over oil ports to rival "
|
||||
"group\"},{\"title\":\"Iraqi peshmerga fighters prepare for Syria "
|
||||
"battle\"},{\"title\":\"1 Dem Senate candidate welcoming Obama's "
|
||||
"help\"},{\"title\":\"Bikers cancel party after police recover "
|
||||
"bar\"},{\"title\":\"New question in Texas:Can Davis survive "
|
||||
"defeat?\"},{\"title\":\"Ukraine rebels to hold election, despite "
|
||||
"criticism\"},{\"title\":\"Iraqi officials say Islamic State group "
|
||||
"lines up, kills 50 tribesmen, women in Anbar "
|
||||
"province\"},{\"title\":\"James rebounds, leads Cavaliers past "
|
||||
"Bulls\"},{\"title\":\"UK warns travelers they could be terror "
|
||||
"targets\"},{\"title\":\"Hello Kitty celebrates 40th "
|
||||
"birthday\"},{\"title\":\"A look at people killed during space "
|
||||
"missions\"},{\"title\":\"Nigeria's purported Boko Haram leader says "
|
||||
"has 'married off' girls:AFP\"},{\"title\":\"Mexico orders immediate "
|
||||
"release of Marine veteran\"},{\"title\":\"As election closes in, "
|
||||
"Obama on center stage\"},{\"title\":\"Body of Zambian president "
|
||||
"arrives home\"},{\"title\":\"South Africa arrests 2 Vietnamese for "
|
||||
"poaching\"}]}}}");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user