diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 21:08:23 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 21:08:23 +0100 |
commit | 6aaa28ef62e0ebc2b4c2ced4d457c91d36e8a311 (patch) | |
tree | dbf110cea76add5c3429d62b58d1e0ba0e7cfaa7 /test | |
parent | 0ef4d750d1b3e275c1cb90e18b289d9d4a85da8f (diff) |
test/serializer: add new comprehensive test
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 8 | ||||
-rw-r--r-- | test/app.hpp | 9 | ||||
-rw-r--r-- | test/json.cpp | 1 | ||||
-rw-r--r-- | test/main.cpp | 3 | ||||
-rw-r--r-- | test/save/quicksave - Copy (00).dat (renamed from test/save/quicksave - Copy (3).dat) | bin | 2620 -> 2620 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (02).dat (renamed from test/save/quicksave - Copy (2).dat) | bin | 2547 -> 2547 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (03).dat (renamed from test/save/quicksave - Copy (5).dat) | bin | 2620 -> 2620 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (04).dat (renamed from test/save/quicksave - Copy (4).dat) | bin | 104106 -> 104106 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (05).dat (renamed from test/save/quicksave - Copy.dat) | bin | 2620 -> 2620 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (06).dat (renamed from test/save/quicksave - Copy (6).dat) | bin | 2710 -> 2710 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (07).dat (renamed from test/save/quicksave - Copy (7).dat) | bin | 2741 -> 2741 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (08).dat (renamed from test/save/quicksave - Copy (8).dat) | bin | 3493 -> 3493 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (09).dat (renamed from test/save/quicksave - Copy (9).dat) | bin | 3542 -> 3542 bytes | |||
-rw-r--r-- | test/save/quicksave - Copy (19).dat | bin | 0 -> 4470 bytes | |||
-rw-r--r-- | test/save/quicksave.dat | bin | 812 -> 0 bytes | |||
-rw-r--r-- | test/serializer.cpp | 54 | ||||
-rw-r--r-- | test/tile-iter.cpp | 1 |
17 files changed, 59 insertions, 17 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eae3ffd5..11e3fb09 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,3 +21,11 @@ if(FLOORMAT_PRECOMPILED-HEADERS) target_precompile_headers(${self}_o PRIVATE precomp.hpp) endif() install(TARGETS ${self} RUNTIME DESTINATION bin) + +set(save-dir "${CMAKE_BINARY_DIR}/test/save") +file(REMOVE_RECURSE "${save-dir}") +file(MAKE_DIRECTORY "${save-dir}") +file(GLOB saves "save/*.dat" CONFIGURE_ARGS) +foreach(file ${saves}) + configure_file("${file}" "${save-dir}" COPYONLY) +endforeach() diff --git a/test/app.hpp b/test/app.hpp index 2152e2e5..0b143b71 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -1,5 +1,4 @@ #pragma once -#include "src/world.hpp" #include <Magnum/Magnum.h> #ifdef __APPLE__ @@ -15,7 +14,9 @@ namespace floormat { +struct chunk_coords; struct chunk; +struct world; struct test_app final : private FM_APPLICATION { @@ -23,15 +24,13 @@ struct test_app final : private FM_APPLICATION explicit test_app(const Arguments& arguments); ~test_app(); int exec() override; - chunk& make_test_chunk(chunk_coords ch); static void test_json(); static void test_tile_iter(); static void test_const_math(); - void test_serializer(); + static void test_serializer_1(); + static void test_serializer_2(); static void test_entity(); static void test_loader(); static void test_bitmask(); - - world w; }; } // namespace floormat diff --git a/test/json.cpp b/test/json.cpp index 349219b1..7d01a51b 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -7,6 +7,7 @@ #include "tile-atlas.hpp" #include "tile.hpp" #include "chunk.hpp" +#include "world.hpp" #include "loader/loader.hpp" #include <Corrade/Containers/StringView.h> #include <Corrade/Utility/Path.h> diff --git a/test/main.cpp b/test/main.cpp index 05ecd7fe..6add1844 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -27,7 +27,8 @@ int test_app::exec() test_entity(); test_loader(); test_bitmask(); - test_serializer(); + test_serializer_1(); + test_serializer_2(); return 0; } diff --git a/test/save/quicksave - Copy (3).dat b/test/save/quicksave - Copy (00).dat Binary files differindex 64c9e9dc..64c9e9dc 100644 --- a/test/save/quicksave - Copy (3).dat +++ b/test/save/quicksave - Copy (00).dat diff --git a/test/save/quicksave - Copy (2).dat b/test/save/quicksave - Copy (02).dat Binary files differindex d0062a39..d0062a39 100644 --- a/test/save/quicksave - Copy (2).dat +++ b/test/save/quicksave - Copy (02).dat diff --git a/test/save/quicksave - Copy (5).dat b/test/save/quicksave - Copy (03).dat Binary files differindex 64c9e9dc..64c9e9dc 100644 --- a/test/save/quicksave - Copy (5).dat +++ b/test/save/quicksave - Copy (03).dat diff --git a/test/save/quicksave - Copy (4).dat b/test/save/quicksave - Copy (04).dat Binary files differindex e753b3d3..e753b3d3 100644 --- a/test/save/quicksave - Copy (4).dat +++ b/test/save/quicksave - Copy (04).dat diff --git a/test/save/quicksave - Copy.dat b/test/save/quicksave - Copy (05).dat Binary files differindex 64c9e9dc..64c9e9dc 100644 --- a/test/save/quicksave - Copy.dat +++ b/test/save/quicksave - Copy (05).dat diff --git a/test/save/quicksave - Copy (6).dat b/test/save/quicksave - Copy (06).dat Binary files differindex 67f0193a..67f0193a 100644 --- a/test/save/quicksave - Copy (6).dat +++ b/test/save/quicksave - Copy (06).dat diff --git a/test/save/quicksave - Copy (7).dat b/test/save/quicksave - Copy (07).dat Binary files differindex ef4778ec..ef4778ec 100644 --- a/test/save/quicksave - Copy (7).dat +++ b/test/save/quicksave - Copy (07).dat diff --git a/test/save/quicksave - Copy (8).dat b/test/save/quicksave - Copy (08).dat Binary files differindex b712bd3f..b712bd3f 100644 --- a/test/save/quicksave - Copy (8).dat +++ b/test/save/quicksave - Copy (08).dat diff --git a/test/save/quicksave - Copy (9).dat b/test/save/quicksave - Copy (09).dat Binary files differindex e85af84d..e85af84d 100644 --- a/test/save/quicksave - Copy (9).dat +++ b/test/save/quicksave - Copy (09).dat diff --git a/test/save/quicksave - Copy (19).dat b/test/save/quicksave - Copy (19).dat Binary files differnew file mode 100644 index 00000000..0592c168 --- /dev/null +++ b/test/save/quicksave - Copy (19).dat diff --git a/test/save/quicksave.dat b/test/save/quicksave.dat Binary files differdeleted file mode 100644 index 75a61886..00000000 --- a/test/save/quicksave.dat +++ /dev/null diff --git a/test/serializer.cpp b/test/serializer.cpp index 928fb25b..87f11b4a 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -11,7 +11,9 @@ namespace floormat { namespace Path = Corrade::Utility::Path; -chunk& test_app::make_test_chunk(chunk_coords ch) +namespace { + +chunk& make_test_chunk(world& w, chunk_coords ch) { chunk& c = w[ch]; c.mark_modified(); @@ -43,7 +45,7 @@ chunk& test_app::make_test_chunk(chunk_coords ch) return c; } -static void assert_chunks_equal(const chunk& a, const chunk& b) +void assert_chunks_equal(const chunk& a, const chunk& b) { fm_assert(a.entities().size() == b.entities().size()); @@ -80,17 +82,47 @@ static void assert_chunks_equal(const chunk& a, const chunk& b) } } -void test_app::test_serializer() +void test_serializer(StringView input, StringView tmp) { - constexpr auto filename = "../test/test-serializer1.dat"; - if (Path::exists(filename)) - Path::remove(filename); - const chunk_coords coord{1, 1}; - auto& c = make_test_chunk(coord); - w.serialize(filename); - auto w2 = world::deserialize(filename); + if (Path::exists(tmp)) + Path::remove(tmp); + chunk_coords coord{}; + world w; + if (input) + w = world::deserialize(input); + else + { + coord = {1, 1}; + w = world(); + make_test_chunk(w, coord); + } + w.serialize(tmp); + auto w2 = world::deserialize(tmp); auto& c2 = w2[coord]; - assert_chunks_equal(c, c2); + assert_chunks_equal(w[coord], c2); +} + +} // namespace + +void test_app::test_serializer_1() +{ + constexpr auto tmp_filename = "../test/test-serializer1.dat"_s; + test_serializer({}, tmp_filename); +} + +void test_app::test_serializer_2() +{ + constexpr auto tmp_filename = "../test/test-serializer2.dat"_s; + constexpr auto dir = "../test/save/"_s; + using LF = Path::ListFlag; + auto files = Path::list(dir, LF::SkipDirectories|LF::SkipSpecial|LF::SkipDotAndDotDot); + fm_assert(files); + for (const StringView file : *files) + { + fm_assert(file.hasSuffix(".dat"_s)); + auto path = Path::join(dir, file); + test_serializer(path, tmp_filename); + } } } // namespace floormat diff --git a/test/tile-iter.cpp b/test/tile-iter.cpp index 7b9eafbf..1b6e2fcc 100644 --- a/test/tile-iter.cpp +++ b/test/tile-iter.cpp @@ -1,5 +1,6 @@ #include "app.hpp" #include "chunk.hpp" +#include "world.hpp" namespace floormat { static inline bool always_false() |