✅ added roundtrip tests for UBJSON
This commit is contained in:
parent
1be3935e9d
commit
b0a68f540f
33 changed files with 123 additions and 0 deletions
1
test/data/json_roundtrip/roundtrip01.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip01.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[Z]
|
1
test/data/json_roundtrip/roundtrip02.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip02.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[T]
|
1
test/data/json_roundtrip/roundtrip03.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip03.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[F]
|
BIN
test/data/json_roundtrip/roundtrip04.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip04.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip05.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip05.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[Sifoo]
|
1
test/data/json_roundtrip/roundtrip06.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip06.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
1
test/data/json_roundtrip/roundtrip07.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip07.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
BIN
test/data/json_roundtrip/roundtrip08.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip08.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip09.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip09.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
{ifooSibar}
|
1
test/data/json_roundtrip/roundtrip10.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip10.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
{iaZifooSibar}
|
1
test/data/json_roundtrip/roundtrip11.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip11.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[i˙]
|
BIN
test/data/json_roundtrip/roundtrip12.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip12.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip13.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip13.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[L<><4C><EFBFBD><0B>~<7E>]
|
BIN
test/data/json_roundtrip/roundtrip14.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip14.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip15.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip15.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[i]
|
1
test/data/json_roundtrip/roundtrip16.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip16.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[l<6C><7F><EFBFBD>]
|
BIN
test/data/json_roundtrip/roundtrip17.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip17.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip18.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip18.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[L"Т}И│]
|
1
test/data/json_roundtrip/roundtrip19.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip19.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[L<4C><7F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]
|
BIN
test/data/json_roundtrip/roundtrip20.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip20.json.ubjson
Normal file
Binary file not shown.
BIN
test/data/json_roundtrip/roundtrip21.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip21.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip22.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip22.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[D?óÀƒn—<6E>]
|
1
test/data/json_roundtrip/roundtrip23.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip23.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[D¿óÀƒn—<6E>]
|
BIN
test/data/json_roundtrip/roundtrip24.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip24.json.ubjson
Normal file
Binary file not shown.
BIN
test/data/json_roundtrip/roundtrip25.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip25.json.ubjson
Normal file
Binary file not shown.
BIN
test/data/json_roundtrip/roundtrip26.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip26.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip27.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip27.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[Dο<7F><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]
|
BIN
test/data/json_roundtrip/roundtrip28.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip28.json.ubjson
Normal file
Binary file not shown.
BIN
test/data/json_roundtrip/roundtrip29.json.ubjson
Normal file
BIN
test/data/json_roundtrip/roundtrip29.json.ubjson
Normal file
Binary file not shown.
1
test/data/json_roundtrip/roundtrip30.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip30.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[D9ケ 脉<>]
|
1
test/data/json_roundtrip/roundtrip31.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip31.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[DF/)До±Uе]
|
1
test/data/json_roundtrip/roundtrip32.json.ubjson
Normal file
1
test/data/json_roundtrip/roundtrip32.json.ubjson
Normal file
|
@ -0,0 +1 @@
|
|||
[DF/)До±Uе]
|
|
@ -2105,3 +2105,106 @@ TEST_CASE("all first bytes", "[!throws]")
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
{
|
||||
SECTION("input from self-generated UBJSON files")
|
||||
{
|
||||
for (std::string filename :
|
||||
{
|
||||
"test/data/json_roundtrip/roundtrip01.json",
|
||||
"test/data/json_roundtrip/roundtrip02.json",
|
||||
"test/data/json_roundtrip/roundtrip03.json",
|
||||
"test/data/json_roundtrip/roundtrip04.json",
|
||||
"test/data/json_roundtrip/roundtrip05.json",
|
||||
"test/data/json_roundtrip/roundtrip06.json",
|
||||
"test/data/json_roundtrip/roundtrip07.json",
|
||||
"test/data/json_roundtrip/roundtrip08.json",
|
||||
"test/data/json_roundtrip/roundtrip09.json",
|
||||
"test/data/json_roundtrip/roundtrip10.json",
|
||||
"test/data/json_roundtrip/roundtrip11.json",
|
||||
"test/data/json_roundtrip/roundtrip12.json",
|
||||
"test/data/json_roundtrip/roundtrip13.json",
|
||||
"test/data/json_roundtrip/roundtrip14.json",
|
||||
"test/data/json_roundtrip/roundtrip15.json",
|
||||
"test/data/json_roundtrip/roundtrip16.json",
|
||||
"test/data/json_roundtrip/roundtrip17.json",
|
||||
"test/data/json_roundtrip/roundtrip18.json",
|
||||
"test/data/json_roundtrip/roundtrip19.json",
|
||||
"test/data/json_roundtrip/roundtrip20.json",
|
||||
"test/data/json_roundtrip/roundtrip21.json",
|
||||
"test/data/json_roundtrip/roundtrip22.json",
|
||||
"test/data/json_roundtrip/roundtrip23.json",
|
||||
"test/data/json_roundtrip/roundtrip24.json",
|
||||
"test/data/json_roundtrip/roundtrip25.json",
|
||||
"test/data/json_roundtrip/roundtrip26.json",
|
||||
"test/data/json_roundtrip/roundtrip27.json",
|
||||
"test/data/json_roundtrip/roundtrip28.json",
|
||||
"test/data/json_roundtrip/roundtrip29.json",
|
||||
"test/data/json_roundtrip/roundtrip30.json",
|
||||
"test/data/json_roundtrip/roundtrip31.json",
|
||||
"test/data/json_roundtrip/roundtrip32.json"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename);
|
||||
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
|
||||
SECTION("std::vector<uint8_t>")
|
||||
{
|
||||
// parse MessagePack file
|
||||
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
|
||||
std::vector<uint8_t> packed(
|
||||
(std::istreambuf_iterator<char>(f_ubjson)),
|
||||
std::istreambuf_iterator<char>());
|
||||
json j2;
|
||||
CHECK_NOTHROW(j2 = json::from_ubjson(packed));
|
||||
|
||||
// compare parsed JSON values
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION("std::ifstream")
|
||||
{
|
||||
// parse MessagePack file
|
||||
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
|
||||
json j2;
|
||||
CHECK_NOTHROW(j2 = json::from_ubjson(f_ubjson));
|
||||
|
||||
// compare parsed JSON values
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION("uint8_t* and size")
|
||||
{
|
||||
// parse MessagePack file
|
||||
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
|
||||
std::vector<uint8_t> packed(
|
||||
(std::istreambuf_iterator<char>(f_ubjson)),
|
||||
std::istreambuf_iterator<char>());
|
||||
json j2;
|
||||
CHECK_NOTHROW(j2 = json::from_ubjson({packed.data(), packed.size()}));
|
||||
|
||||
// compare parsed JSON values
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION("output to output adapters")
|
||||
{
|
||||
// parse MessagePack file
|
||||
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
|
||||
std::vector<uint8_t> packed(
|
||||
(std::istreambuf_iterator<char>(f_ubjson)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
SECTION("std::vector<uint8_t>")
|
||||
{
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_ubjson(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue