// ArduinoJson - https://arduinojson.org // Copyright Benoit Blanchon 2014-2021 // MIT License #include #include template void shouldBeOk(TIn value) { StaticJsonDocument<1> doc; JsonVariant var = doc.to(); var.set(value); REQUIRE(var.as() == TOut(value)); } template void shouldOverflow(TIn value) { StaticJsonDocument<1> doc; JsonVariant var = doc.to(); var.set(value); REQUIRE(var.as() == 0); REQUIRE(var.is() == false); } TEST_CASE("Handle integer overflow in stored integer") { SECTION("int8_t") { // ok shouldBeOk(-128); shouldBeOk(42.0); shouldBeOk(127); // too low shouldOverflow(-128.1); shouldOverflow(-129); // too high shouldOverflow(128); shouldOverflow(127.1); } SECTION("int16_t") { // ok shouldBeOk(-32768); shouldBeOk(-32767.9); shouldBeOk(32766.9); shouldBeOk(32767); // too low shouldOverflow(-32768.1); shouldOverflow(-32769); // too high shouldOverflow(32767.1); shouldOverflow(32768); } SECTION("uint8_t") { // ok shouldBeOk(1); shouldBeOk(42.0); shouldBeOk(255); // too low shouldOverflow(-1); shouldOverflow(-0.1); // to high shouldOverflow(255.1); shouldOverflow(256); shouldOverflow(257); } }