diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-13 18:53:14 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-13 20:43:16 +0100 |
commit | f6f16968a703dda7f66212e1527ba177dde26939 (patch) | |
tree | 5c480810b6b92f4511be49ed93448f250991433f | |
parent | 4cd305a0420f1acc75a8f81ff15264a99581f9d0 (diff) |
test stuff
-rw-r--r-- | src/entity.hpp | 10 | ||||
-rw-r--r-- | test/app.hpp | 4 | ||||
-rw-r--r-- | test/entity.cpp | 16 | ||||
-rw-r--r-- | test/main.cpp | 3 | ||||
-rw-r--r-- | test/serializer.cpp | 12 |
5 files changed, 20 insertions, 25 deletions
diff --git a/src/entity.hpp b/src/entity.hpp index b63d13e8..7d55bfd6 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -74,17 +74,17 @@ struct read_field<Obj, Type, Type Obj::*> { }; template<typename Obj, typename FieldType, typename Writer> struct write_field { - static FieldType write(const Obj& x, Writer w, move_qualified<FieldType> value) { return w(x, value); } + static void write(Obj& x, Writer w, move_qualified<FieldType> value) { w(x, value); } }; template<typename Obj, typename Type> -struct write_field<Obj, Type, void(Type::*)(move_qualified<Type>)> { - static Type write(const Obj& x, void(Type::*w)(Type&&), move_qualified<Type> value) { return (x.*w)(value); } +struct write_field<Obj, Type, void(Obj::*)(move_qualified<Type>)> { + static void write(Obj& x, void(Obj::*w)(move_qualified<Type>), move_qualified<Type> value) { (x.*w)(value); } }; template<typename Obj, typename Type> struct write_field<Obj, Type, Type Obj::*> { - static Type write(const Obj& x, Type Obj::* w, move_qualified<Type> value) { return x.*w = value; } + static void write(Obj& x, Type Obj::* w, move_qualified<Type> value) { x.*w = value; } }; template<typename Obj, typename FieldType, FieldReader<Obj, FieldType> R, FieldWriter<Obj, FieldType> W> @@ -100,7 +100,7 @@ struct field { constexpr field(StringView name, Reader r, Writer w) noexcept : name{name}, reader{r}, writer{w} {} decltype(auto) read(const Obj& x) const { return read_field<Obj, FieldType, R>::read(x, reader); } - void write(Obj& x, move_qualified<FieldType> v) const { return write_field<Obj, FieldType, R>::write(x, v); } + void write(Obj& x, move_qualified<FieldType> v) const { write_field<Obj, FieldType, W>::write(x, writer, v); } }; template<typename Obj> diff --git a/test/app.hpp b/test/app.hpp index 89753ead..76cbab18 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -22,7 +22,7 @@ struct test_app final : private FM_APPLICATION static bool test_json(); static bool test_tile_iter(); static bool test_const_math(); - static bool test_serializer(); - static bool test_entity(); + static void test_serializer(); + static void test_entity(); }; } // namespace floormat diff --git a/test/entity.cpp b/test/entity.cpp index 9cf0e617..618fb4aa 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -6,7 +6,7 @@ namespace floormat { using namespace floormat::entities; -static void test() +void test_app::test_entity() { struct Test { int foo = 111; @@ -18,18 +18,20 @@ static void test() }; using Entity = entity<Test>; - constexpr auto m_foo = Entity::Field<int>::make{ "foo"_s, &Test::foo, &Test::foo, }; - constexpr auto m_bar = Entity::Field<int>::make{ "bar"_s, &Test::bar, &Test::set_bar, }; - constexpr auto r_baz = [](const Test& x) { return x._baz; }; - constexpr auto w_baz = [](Test& x, int v) { x._baz = v; }; - constexpr auto m_baz = Entity::Field<int>::make{ "baz"_s, r_baz, w_baz }; + constexpr const auto m_foo = Entity::Field<int>::make{ "foo"_s, &Test::foo, &Test::foo, }; + constexpr const auto m_bar = Entity::Field<int>::make{ "bar"_s, &Test::bar, &Test::set_bar, }; + constexpr const auto r_baz = [](const Test& x) { return x._baz; }; + constexpr const auto w_baz = [](Test& x, int v) { x._baz = v; }; + constexpr const auto m_baz = Entity::Field<int>::make{ "baz"_s, r_baz, w_baz }; auto x = Test{}; fm_assert(m_foo.read(x) == 111); fm_assert(m_bar.read(x) == 222); fm_assert(m_baz.read(x) == 333); - return true; + m_foo.write(x, 1111); + m_bar.write(x, 2222); + m_baz.write(x, 3333); } } // namespace floormat diff --git a/test/main.cpp b/test/main.cpp index 2fcc5715..dbf4a10e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -22,7 +22,8 @@ int test_app::exec() fm_assert(test_json()); fm_assert(test_tile_iter()); fm_assert(test_const_math()); - fm_assert(test_serializer()); + test_serializer(); + test_entity(); return 0; } diff --git a/test/serializer.cpp b/test/serializer.cpp index 2e24cd0f..568d0217 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -36,7 +36,7 @@ static bool chunks_equal(const chunk& a, const chunk& b) return true; } -static bool test_serializer1() +void test_app::test_serializer() { constexpr auto filename = "../test/test-serializer1.dat"; if (Path::exists(filename)) @@ -47,15 +47,7 @@ static bool test_serializer1() w.serialize(filename); auto w2 = world::deserialize(filename); auto &c1 = w[coord], &c2 = w2[coord]; - bool ret = chunks_equal(c1, c2); - return ret; -} - -bool test_app::test_serializer() -{ - bool ret = true; - ret &= test_serializer1(); - return ret; + fm_assert(chunks_equal(c1, c2)); } } // namespace floormat |