diff --git a/test/data/json_roundtrip/roundtrip01.json.ubjson b/test/data/json_roundtrip/roundtrip01.json.ubjson new file mode 100644 index 000000000..b9f6852d1 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip01.json.ubjson @@ -0,0 +1 @@ +[Z] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip02.json.ubjson b/test/data/json_roundtrip/roundtrip02.json.ubjson new file mode 100644 index 000000000..f9ca78f58 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip02.json.ubjson @@ -0,0 +1 @@ +[T] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip03.json.ubjson b/test/data/json_roundtrip/roundtrip03.json.ubjson new file mode 100644 index 000000000..e454e6ae7 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip03.json.ubjson @@ -0,0 +1 @@ +[F] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip04.json.ubjson b/test/data/json_roundtrip/roundtrip04.json.ubjson new file mode 100644 index 000000000..150ad07d9 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip04.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip05.json.ubjson b/test/data/json_roundtrip/roundtrip05.json.ubjson new file mode 100644 index 000000000..8a3655bf0 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip05.json.ubjson @@ -0,0 +1 @@ +[Sifoo] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip06.json.ubjson b/test/data/json_roundtrip/roundtrip06.json.ubjson new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/test/data/json_roundtrip/roundtrip06.json.ubjson @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip07.json.ubjson b/test/data/json_roundtrip/roundtrip07.json.ubjson new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/test/data/json_roundtrip/roundtrip07.json.ubjson @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip08.json.ubjson b/test/data/json_roundtrip/roundtrip08.json.ubjson new file mode 100644 index 000000000..1274f060f Binary files /dev/null and b/test/data/json_roundtrip/roundtrip08.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip09.json.ubjson b/test/data/json_roundtrip/roundtrip09.json.ubjson new file mode 100644 index 000000000..8f0d59cf2 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip09.json.ubjson @@ -0,0 +1 @@ +{ifooSibar} \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip10.json.ubjson b/test/data/json_roundtrip/roundtrip10.json.ubjson new file mode 100644 index 000000000..116f7ca4e --- /dev/null +++ b/test/data/json_roundtrip/roundtrip10.json.ubjson @@ -0,0 +1 @@ +{iaZifooSibar} \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip11.json.ubjson b/test/data/json_roundtrip/roundtrip11.json.ubjson new file mode 100644 index 000000000..201775363 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip11.json.ubjson @@ -0,0 +1 @@ +[i] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip12.json.ubjson b/test/data/json_roundtrip/roundtrip12.json.ubjson new file mode 100644 index 000000000..1a39d1b1e Binary files /dev/null and b/test/data/json_roundtrip/roundtrip12.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip13.json.ubjson b/test/data/json_roundtrip/roundtrip13.json.ubjson new file mode 100644 index 000000000..d1b43667e --- /dev/null +++ b/test/data/json_roundtrip/roundtrip13.json.ubjson @@ -0,0 +1 @@ +[L ~] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip14.json.ubjson b/test/data/json_roundtrip/roundtrip14.json.ubjson new file mode 100644 index 000000000..65a415a07 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip14.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip15.json.ubjson b/test/data/json_roundtrip/roundtrip15.json.ubjson new file mode 100644 index 000000000..cd5790015 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip15.json.ubjson @@ -0,0 +1 @@ +[i] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip16.json.ubjson b/test/data/json_roundtrip/roundtrip16.json.ubjson new file mode 100644 index 000000000..d3494df17 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip16.json.ubjson @@ -0,0 +1 @@ +[l] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip17.json.ubjson b/test/data/json_roundtrip/roundtrip17.json.ubjson new file mode 100644 index 000000000..dbc1b2c1e Binary files /dev/null and b/test/data/json_roundtrip/roundtrip17.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip18.json.ubjson b/test/data/json_roundtrip/roundtrip18.json.ubjson new file mode 100644 index 000000000..2b1778d54 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip18.json.ubjson @@ -0,0 +1 @@ +[L"}] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip19.json.ubjson b/test/data/json_roundtrip/roundtrip19.json.ubjson new file mode 100644 index 000000000..ec62b0599 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip19.json.ubjson @@ -0,0 +1 @@ +[L] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip20.json.ubjson b/test/data/json_roundtrip/roundtrip20.json.ubjson new file mode 100644 index 000000000..b2aab5209 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip20.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip21.json.ubjson b/test/data/json_roundtrip/roundtrip21.json.ubjson new file mode 100644 index 000000000..9c9eefc2f Binary files /dev/null and b/test/data/json_roundtrip/roundtrip21.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip22.json.ubjson b/test/data/json_roundtrip/roundtrip22.json.ubjson new file mode 100644 index 000000000..ef3134968 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip22.json.ubjson @@ -0,0 +1 @@ +[D?n] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip23.json.ubjson b/test/data/json_roundtrip/roundtrip23.json.ubjson new file mode 100644 index 000000000..14ee7f2d2 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip23.json.ubjson @@ -0,0 +1 @@ +[Dn] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip24.json.ubjson b/test/data/json_roundtrip/roundtrip24.json.ubjson new file mode 100644 index 000000000..32965e3f2 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip24.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip25.json.ubjson b/test/data/json_roundtrip/roundtrip25.json.ubjson new file mode 100644 index 000000000..7361cea36 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip25.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip26.json.ubjson b/test/data/json_roundtrip/roundtrip26.json.ubjson new file mode 100644 index 000000000..ef4769319 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip26.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip27.json.ubjson b/test/data/json_roundtrip/roundtrip27.json.ubjson new file mode 100644 index 000000000..5b5ddd56f --- /dev/null +++ b/test/data/json_roundtrip/roundtrip27.json.ubjson @@ -0,0 +1 @@ +[D] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip28.json.ubjson b/test/data/json_roundtrip/roundtrip28.json.ubjson new file mode 100644 index 000000000..32965e3f2 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip28.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip29.json.ubjson b/test/data/json_roundtrip/roundtrip29.json.ubjson new file mode 100644 index 000000000..82ab8dd9f Binary files /dev/null and b/test/data/json_roundtrip/roundtrip29.json.ubjson differ diff --git a/test/data/json_roundtrip/roundtrip30.json.ubjson b/test/data/json_roundtrip/roundtrip30.json.ubjson new file mode 100644 index 000000000..23f39bccb --- /dev/null +++ b/test/data/json_roundtrip/roundtrip30.json.ubjson @@ -0,0 +1 @@ +[D9 ] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip31.json.ubjson b/test/data/json_roundtrip/roundtrip31.json.ubjson new file mode 100644 index 000000000..cc714de1f --- /dev/null +++ b/test/data/json_roundtrip/roundtrip31.json.ubjson @@ -0,0 +1 @@ +[DF/)U] \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip32.json.ubjson b/test/data/json_roundtrip/roundtrip32.json.ubjson new file mode 100644 index 000000000..cc714de1f --- /dev/null +++ b/test/data/json_roundtrip/roundtrip32.json.ubjson @@ -0,0 +1 @@ +[DF/)U] \ No newline at end of file diff --git a/test/src/unit-ubjson.cpp b/test/src/unit-ubjson.cpp index a8bfe6915..a1830d628 100644 --- a/test/src/unit-ubjson.cpp +++ b/test/src/unit-ubjson.cpp @@ -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") + { + // parse MessagePack file + std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary); + std::vector packed( + (std::istreambuf_iterator(f_ubjson)), + std::istreambuf_iterator()); + 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 packed( + (std::istreambuf_iterator(f_ubjson)), + std::istreambuf_iterator()); + 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 packed( + (std::istreambuf_iterator(f_ubjson)), + std::istreambuf_iterator()); + + SECTION("std::vector") + { + std::vector vec; + json::to_ubjson(j1, vec); + CHECK(vec == packed); + } + } + } + } +}