diff --git a/test/data/json_roundtrip/roundtrip01.json.ubjson b/test/data/json_roundtrip/roundtrip01.json.ubjson new file mode 100644 index 00000000..b9f6852d --- /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 00000000..f9ca78f5 --- /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 00000000..e454e6ae --- /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 00000000..150ad07d 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 00000000..8a3655bf --- /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 00000000..0637a088 --- /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 00000000..9e26dfee --- /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 00000000..1274f060 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 00000000..8f0d59cf --- /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 00000000..116f7ca4 --- /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 00000000..20177536 --- /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 00000000..1a39d1b1 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 00000000..d1b43667 --- /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 00000000..65a415a0 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 00000000..cd579001 --- /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 00000000..d3494df1 --- /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 00000000..dbc1b2c1 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 00000000..2b1778d5 --- /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 00000000..ec62b059 --- /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 00000000..b2aab520 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 00000000..9c9eefc2 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 00000000..ef313496 --- /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 00000000..14ee7f2d --- /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 00000000..32965e3f 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 00000000..7361cea3 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 00000000..ef476931 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 00000000..5b5ddd56 --- /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 00000000..32965e3f 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 00000000..82ab8dd9 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 00000000..23f39bcc --- /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 00000000..cc714de1 --- /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 00000000..cc714de1 --- /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 a8bfe691..a1830d62 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); + } + } + } + } +}