From 8f0b22e3fe082c2b5c75a7fe3435f56a38cbc5a2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 14 Nov 2022 13:59:57 +0100 Subject: entity: more work --- test/entity.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/entity.cpp b/test/entity.cpp index 50d5e34b..80032b6f 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -2,34 +2,29 @@ #include "compat/assert.hpp" #include "src/entity.hpp" -namespace { +using namespace floormat; +using namespace floormat::entities; struct TestAccessors { - int foo = 111; int bar() const { return _bar; } void set_bar(int value) { _bar = value; } - int _baz = 333; -private: - int _bar = 222; + int foo; + int _bar; + int _baz; }; -} // namespace +using entity = Entity; +static constexpr auto m_foo = entity::type::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo}; +static constexpr auto m_bar = entity::type::field{"bar"_s, &TestAccessors::bar, &TestAccessors::set_bar}; +static constexpr auto r_baz = [](const TestAccessors& x) { return x._baz; }; +static constexpr auto w_baz = [](TestAccessors& x, int v) { x._baz = v; }; +static constexpr auto m_baz = entity::type::field("baz"_s, r_baz, w_baz); namespace floormat { -using namespace floormat::entities; - static void test_accessors() { - using Test = ::TestAccessors; - using Entity = entity; - constexpr auto m_foo = Entity::Field::make("foo"_s, &Test::foo, &Test::foo); - constexpr auto m_bar = Entity::Field::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::make("baz"_s, r_baz, w_baz); - - auto x = Test{}; + auto x = TestAccessors{111, 222, 333}; { auto a = m_foo.read(x), b = m_bar.read(x), c = m_baz.read(x); @@ -45,11 +40,6 @@ static void test_accessors() } } -static void test_() -{ - -} - void test_app::test_entity() { test_accessors(); -- cgit v1.2.3