improve coverage

parent 96b9877d
...@@ -38,6 +38,84 @@ using nlohmann::json; ...@@ -38,6 +38,84 @@ using nlohmann::json;
#include <test_data.hpp> #include <test_data.hpp>
#include "test_utils.hpp" #include "test_utils.hpp"
namespace
{
class SaxCountdown
{
public:
explicit SaxCountdown(const int count) : events_left(count)
{}
bool null()
{
return events_left-- > 0;
}
bool boolean(bool /*unused*/)
{
return events_left-- > 0;
}
bool number_integer(json::number_integer_t /*unused*/)
{
return events_left-- > 0;
}
bool number_unsigned(json::number_unsigned_t /*unused*/)
{
return events_left-- > 0;
}
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
{
return events_left-- > 0;
}
bool string(std::string& /*unused*/)
{
return events_left-- > 0;
}
bool binary(std::vector<std::uint8_t>& /*unused*/)
{
return events_left-- > 0;
}
bool start_object(std::size_t /*unused*/)
{
return events_left-- > 0;
}
bool key(std::string& /*unused*/)
{
return events_left-- > 0;
}
bool end_object()
{
return events_left-- > 0;
}
bool start_array(std::size_t /*unused*/)
{
return events_left-- > 0;
}
bool end_array()
{
return events_left-- > 0;
}
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
{
return false;
}
private:
int events_left = 0;
};
} // namespace
TEST_CASE("BON8") TEST_CASE("BON8")
{ {
SECTION("individual values") SECTION("individual values")
...@@ -732,4 +810,42 @@ TEST_CASE("BON8") ...@@ -732,4 +810,42 @@ TEST_CASE("BON8")
} }
} }
} }
SECTION("SAX aborts")
{
SECTION("start_array(len)")
{
std::vector<uint8_t> v = {0x80};
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::bon8));
}
SECTION("error in array")
{
std::vector<uint8_t> v = {0x81};
SaxCountdown scp(1000);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::bon8));
}
SECTION("start_object(len)")
{
std::vector<uint8_t> v = {0x86};
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::bon8));
}
SECTION("key()")
{
std::vector<uint8_t> v = {0x87, 'f', 'o', 'o', 0xFF, 0xFA};
SaxCountdown scp(1);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::bon8));
}
SECTION("error in object")
{
std::vector<uint8_t> v = {0x87, 'f', 'o', 'o', 0xFF};
SaxCountdown scp(1000);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::bon8));
}
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment