extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { DynamicJsonBuffer jsonBuffer; memstream json(data, size); JsonVariant variant = jsonBuffer.parse(json); if (variant.success()) { variant.as<std::string>(); // <- serialize to JSON } return 0; }
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenInvalidArray) { JsonVariant variant = JsonArray::invalid(); EXPECT_FALSE(variant.success()); }
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenInvalidObject) { JsonVariant variant = JsonObject::invalid(); EXPECT_FALSE(variant.success()); }
TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenEmptyObject) { DynamicJsonBuffer jsonBuffer; JsonVariant variant = jsonBuffer.createObject(); EXPECT_TRUE(variant.success()); }
TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenInteger) { JsonVariant variant = 0; EXPECT_TRUE(variant.success()); }
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenUndefined) { JsonVariant variant; EXPECT_FALSE(variant.success()); }
// Copyright Benoit Blanchon 2014-2017 // MIT License // // Arduino JSON library // https://bblanchon.github.io/ArduinoJson/ // If you like this project, please add a star! #include <ArduinoJson.h> #include <catch.hpp> TEST_CASE("JsonVariant::success()") { SECTION("ReturnsFalse_WhenUndefined") { JsonVariant variant; REQUIRE(false == variant.success()); } SECTION("ReturnsTrue_WhenInteger") { JsonVariant variant = 0; REQUIRE(true == variant.success()); } SECTION("ReturnsTrue_WhenEmptyArray") { DynamicJsonBuffer jsonBuffer; JsonVariant variant = jsonBuffer.createArray(); REQUIRE(true == variant.success()); } SECTION("ReturnsTrue_WhenEmptyObject") { DynamicJsonBuffer jsonBuffer;
// // Arduino JSON library // https://bblanchon.github.io/ArduinoJson/ // If you like this project, please add a star! #include <ArduinoJson.h> #include <catch.hpp> using namespace Catch::Matchers; TEST_CASE("JsonBuffer::parse()") { DynamicJsonBuffer jb; SECTION("EmptyObject") { JsonVariant variant = jb.parse("{}"); REQUIRE(variant.success()); REQUIRE(variant.is<JsonObject>()); } SECTION("EmptyArray") { JsonVariant variant = jb.parse("[]"); REQUIRE(variant.success()); REQUIRE(variant.is<JsonArray>()); } SECTION("Integer") { JsonVariant variant = jb.parse("-42"); REQUIRE(variant.success()); REQUIRE(variant.is<int>()); REQUIRE_FALSE(variant.is<bool>()); REQUIRE(variant == -42);