add tests for binary type

This commit is contained in:
Niels Lohmann 2020-05-09 14:16:57 +02:00
parent b036ace235
commit 34430994bf
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 33 additions and 0 deletions

View file

@ -851,6 +851,25 @@ TEST_CASE("Incomplete BSON Input")
}
}
TEST_CASE("Negative size of binary value")
{
// invalid BSON: the size of the binary value is -1
std::vector<std::uint8_t> input =
{
0x21, 0x00, 0x00, 0x00, // size (little endian)
0x05, // entry: binary
'e', 'n', 't', 'r', 'y', '\x00',
0xFF, 0xFF, 0xFF, 0xFF, // size of binary (little endian)
0x05, // MD5 binary subtype
0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4,
0x00 // end marker
};
CHECK_THROWS_AS(json::from_bson(input), json::parse_error);
CHECK_THROWS_WITH(json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1");
}
TEST_CASE("Unsupported BSON input")
{
std::vector<std::uint8_t> bson =

View file

@ -1461,6 +1461,20 @@ TEST_CASE("constructors")
CHECK(j == j_new);
}
}
SECTION("binary")
{
{
json j = json::binary_array({1, 2, 3});
json j_new(j.begin(), j.end());
CHECK((j == j_new));
}
{
json j = json::binary_array({1, 2, 3});
json j_new(j.cbegin(), j.cend());
CHECK((j == j_new));
}
}
}
SECTION("construct with two invalid iterators")