diff options
-rw-r--r-- | serialize/wall-atlas.hpp | 2 | ||||
-rw-r--r-- | test/wall-atlas.cpp | 39 |
2 files changed, 34 insertions, 7 deletions
diff --git a/serialize/wall-atlas.hpp b/serialize/wall-atlas.hpp index 7f578a5d..f531a48e 100644 --- a/serialize/wall-atlas.hpp +++ b/serialize/wall-atlas.hpp @@ -34,7 +34,7 @@ StringView direction_index_to_name(size_t i); Pair<Array<Direction>, std::array<DirArrayIndex, 4>> read_all_directions(const json& jroot); Info read_info_header(const json& jroot); -void write_all_frames(json& jframes, ArrayView<const Frame> array); +void write_all_frames(json& jroot, ArrayView<const Frame> array); void write_group_metadata(json& jgroup, const Group& val); void write_direction_metadata(json& jdir, const Direction& dir); void write_all_directions(json& jroot, const wall_atlas& a); diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp index fd4d6f82..1578e68f 100644 --- a/test/wall-atlas.cpp +++ b/test/wall-atlas.cpp @@ -3,6 +3,7 @@ #include "serialize/wall-atlas.hpp" #include "serialize/json-helper.hpp" #include "loader/loader.hpp" +#include <Corrade/Containers/StringStlView.h> #include <Corrade/Utility/Path.h> namespace floormat::Wall::detail { @@ -37,7 +38,7 @@ void test_read_header(StringView filename) fm_assert(info.depth == 42); } -void test_read_empty_direction(StringView filename) +void test_read_empty_directions(StringView filename) { const auto jroot = json_helper::from_json_(Path::join(json_path(), filename)); test_read_header(filename); @@ -134,10 +135,23 @@ struct wall_atlas_ return atlas; } -void write_to_temp_file() +void write_to_temp_file(const wall_atlas_& atlas) { - const auto filename = temp_filename(); + auto jroot = json{json::value_t::object}; + + write_info_header(jroot, atlas.header); + write_all_frames(jroot, atlas.frames); + + for (const auto [name_, dir] : wall_atlas::directions) + { + std::string_view name = name_; + auto i = (size_t)dir; + if (atlas.directions[i]) + write_direction_metadata(jroot[name], atlas.directions[i]); + } + const auto filename = temp_filename(); + json_helper::to_json_(jroot, filename); } } // namespace @@ -147,7 +161,20 @@ void write_to_temp_file() void floormat::test_app::test_wall_atlas() { using namespace floormat::Wall::detail; - test_read_header("wall-atlas-01_header.json"_s); - test_read_empty_direction("wall-atlas-01_header.json"_s); - test_read_groups("wall-atlas-02_groups.json"_s); + constexpr auto S_01_header_json = "wall-atlas-01_header.json"_s, + S_02_groups_json = "wall-atlas-02_groups.json"_s; + + { test_read_header(S_01_header_json); + test_read_empty_directions(S_01_header_json); + } + + { test_read_header(S_02_groups_json); + test_read_groups(S_02_groups_json); + } + + { auto a = read_from_file(Path::join(json_path(), S_02_groups_json)); + write_to_temp_file(a); + auto b = read_from_file(temp_filename()); + fm_assert(a == b); + } } |