summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-14 07:33:47 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-14 07:33:47 +0100
commitdc5e66b5a29fd7de8ddf59852ceefd982289b7c3 (patch)
tree18bf0a274f1595d6d2d6cfb32a3b3825d843e315 /test
parent29bdd5f2170b9d46a8b3b0973c4c0845d6a2b61e (diff)
a
Diffstat (limited to 'test')
-rw-r--r--test/app.hpp7
-rw-r--r--test/entity.cpp5
-rw-r--r--test/main.cpp2
-rw-r--r--test/serializer.cpp33
4 files changed, 32 insertions, 15 deletions
diff --git a/test/app.hpp b/test/app.hpp
index 894401c8..2152e2e5 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "src/world.hpp"
#include <Magnum/Magnum.h>
#ifdef __APPLE__
@@ -22,13 +23,15 @@ struct test_app final : private FM_APPLICATION
explicit test_app(const Arguments& arguments);
~test_app();
int exec() override;
- static chunk make_test_chunk();
+ chunk& make_test_chunk(chunk_coords ch);
static void test_json();
static void test_tile_iter();
static void test_const_math();
- static void test_serializer();
+ void test_serializer();
static void test_entity();
static void test_loader();
static void test_bitmask();
+
+ world w;
};
} // namespace floormat
diff --git a/test/entity.cpp b/test/entity.cpp
index a7810863..c1489723 100644
--- a/test/entity.cpp
+++ b/test/entity.cpp
@@ -96,6 +96,7 @@ constexpr bool test_visitor()
}
void test_fun2() {
+ using entity = Entity<TestAccessors>;
static constexpr auto read_fn = [](const TestAccessors& x) constexpr { return x.bar(); };
static constexpr auto write_fn = [](TestAccessors& x, int value) constexpr { x.set_bar(value); };
constexpr auto read_bar = fu2::function_view<int(const TestAccessors&) const>{read_fn};
@@ -156,6 +157,7 @@ void test_type_name()
[[maybe_unused]] constexpr void test_null_writer()
{
+ using entity = Entity<TestAccessors>;
constexpr auto foo = entity::type<int>::field{"foo"_s, &TestAccessors::foo, nullptr};
static_assert(foo.writer == nullptr);
static_assert(!foo.can_write);
@@ -164,6 +166,7 @@ void test_type_name()
void test_predicate()
{
+ using entity = Entity<TestAccessors>;
constexpr TestAccessors x{0, 0, 0};
constexpr auto foo = entity::type<int>::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo,
[](const TestAccessors&) { return field_status::hidden; }};
@@ -199,6 +202,7 @@ constexpr bool test_names()
constexpr void test_constraints()
{
+ using entity = Entity<TestAccessors>;
constexpr auto x = TestAccessors{};
constexpr auto foo = entity::type<int>::field {
"foo"_s, &TestAccessors::foo, &TestAccessors::foo,
@@ -226,6 +230,7 @@ constexpr void test_constraints()
void test_erased_constraints()
{
+ using entity = Entity<TestAccessors>;
static constexpr auto foo = entity::type<int>::field{
"foo"_s, &TestAccessors::foo, &TestAccessors::foo,
constantly(constraints::max_length{42}),
diff --git a/test/main.cpp b/test/main.cpp
index 0d7ddf84..05ecd7fe 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -24,10 +24,10 @@ int test_app::exec()
test_json();
test_tile_iter();
test_const_math();
- test_serializer();
test_entity();
test_loader();
test_bitmask();
+ test_serializer();
return 0;
}
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 71b1a3f1..c74f4ddf 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -9,40 +9,50 @@ namespace floormat {
namespace Path = Corrade::Utility::Path;
-chunk test_app::make_test_chunk()
+chunk& test_app::make_test_chunk(chunk_coords ch)
{
+ chunk& c = w[ch];
+ c.mark_modified();
auto metal1 = loader.tile_atlas("metal1", {2, 2}, pass_mode::pass),
metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked),
tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass);
constexpr auto N = TILE_MAX_DIM;
- chunk c;
for (auto [x, k, pt] : c)
x.ground() = { tiles, variant_t(k % tiles->num_tiles()) };
auto door = loader.scenery("door1"),
table = loader.scenery("table1"),
control_panel = loader.scenery("control panel (wall) 1");
- control_panel.frame.r = rotation::W;
+ control_panel.r = rotation::W;
constexpr auto K = N/2;
c[{K, K }].wall_north() = { metal1, 0 };
c[{K, K }].wall_west() = { metal2, 0 };
c[{K, K+1}].wall_north() = { metal1, 0 };
c[{K+1, K }].wall_west() = { metal2, 0 };
- c[{K+3, K+1}].scenery() = door;
- c[{ 3, 4 }].scenery() = table;
- c[{K, K+1}].scenery() = control_panel;
- c[{K, K+1}].scenery().frame.bbox_size = {99, 88};
- c.mark_modified();
+ w.make_entity<scenery>({ch, {K+3, K+1}}, door);
+ w.make_entity<scenery>({ch, {3, 4}}, table);
+ w.make_entity<scenery>({ch, {K, K+1}}, control_panel);
return c;
}
static bool chunks_equal(const chunk& a, const chunk& b)
{
+ if (a.entities().size() != b.entities().size())
+ return false;
+
for (auto i = 0_uz; i < TILE_COUNT; i++)
{
const auto &a1 = a[i], &b1 = b[i];
if (a1 != b1)
return false;
}
+
+ for (auto i = 0_uz; i < a.entities().size(); i++)
+ {
+ auto &ae = *a.entities()[i], &be = *b.entities()[i];
+ if (entity_proto(ae) != entity_proto(be))
+ return false;
+ }
+
return true;
}
@@ -51,13 +61,12 @@ void test_app::test_serializer()
constexpr auto filename = "../test/test-serializer1.dat";
if (Path::exists(filename))
Path::remove(filename);
- world w;
const chunk_coords coord{1, 1};
- w[coord] = make_test_chunk();
+ auto& c = make_test_chunk(coord);
w.serialize(filename);
auto w2 = world::deserialize(filename);
- auto &c1 = w[coord], &c2 = w2[coord];
- fm_assert(chunks_equal(c1, c2));
+ auto& c2 = w2[coord];
+ fm_assert(chunks_equal(c, c2));
}
} // namespace floormat