BSON: unsigned integers
This commit is contained in:
parent
c0d8921a67
commit
83b427ad67
3 changed files with 136 additions and 4 deletions
|
|
@ -279,5 +279,77 @@ TEST_CASE("BSON")
|
|||
CHECK(json::from_bson(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("non-empty object with negative integer (32-bit) member")
|
||||
{
|
||||
json j =
|
||||
{
|
||||
{ "entry", std::int32_t{-1} }
|
||||
};
|
||||
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0x10, 0x00, 0x00, 0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
const auto result = json::to_bson(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_bson(result) == j);
|
||||
CHECK(json::from_bson(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("non-empty object with negative integer (64-bit) member")
|
||||
{
|
||||
json j =
|
||||
{
|
||||
{ "entry", std::int64_t{-1} }
|
||||
};
|
||||
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0x10, 0x00, 0x00, 0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
const auto result = json::to_bson(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_bson(result) == j);
|
||||
CHECK(json::from_bson(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("non-empty object with unsigned integer (64-bit) member")
|
||||
{
|
||||
// directly encoding uint64 is not supported in bson (only for timestamp values)
|
||||
json j =
|
||||
{
|
||||
{ "entry", std::uint64_t{0x1234567804030201} }
|
||||
};
|
||||
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0x14, 0x00, 0x00, 0x00, // size (little endian)
|
||||
0x12, /// entry: int64
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0x01, 0x02, 0x03, 0x04, 0x78, 0x56, 0x34, 0x12,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
const auto result = json::to_bson(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_bson(result) == j);
|
||||
CHECK(json::from_bson(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue