diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-13 20:00:57 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-13 20:43:16 +0100 |
commit | 3bdd6d8e638ed19973b9df6a894e8b7966731b9c (patch) | |
tree | 71a9296da96fc572f294154da293a5cd2cfa2985 /test | |
parent | ebb301f4d3a99e3cae3de6094231058bcbcee54c (diff) |
entity stuff
Diffstat (limited to 'test')
-rw-r--r-- | test/entity.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/test/entity.cpp b/test/entity.cpp index ae50853c..6789a241 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -2,34 +2,32 @@ #include "compat/assert.hpp" #include "src/entity.hpp" +struct Test { + int foo = 111; + int bar() const { return _bar; } + void set_bar(int value) { _bar = value; } + int _baz = 333; +private: + int _bar = 222; +}; + namespace floormat { using namespace floormat::entities; -void test_app::test_entity() +static void test_accessors() { - struct Test { - int foo = 111; - int bar() const { return _bar; } - void set_bar(int value) { _bar = value; } - int _baz = 333; - private: - int _bar = 222; - }; - using Entity = entity<Test>; - 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 }; + 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); auto x = Test{}; { - auto a = m_foo.read(x); - auto b = m_bar.read(x); - auto c = m_baz.read(x); + auto a = m_foo.read(x), b = m_bar.read(x), c = m_baz.read(x); fm_assert(a == 111 && b == 222 && c == 333); } @@ -37,11 +35,14 @@ void test_app::test_entity() m_foo.write(x, 1111); m_bar.write(x, 2222); m_baz.write(x, 3333); - auto a = m_foo.read(x); - auto b = m_bar.read(x); - auto c = m_baz.read(x); + auto a = m_foo.read(x), b = m_bar.read(x), c = m_baz.read(x); fm_assert(a == 1111 && b == 2222 && c == 3333); } } +void test_app::test_entity() +{ + test_accessors(); +} + } // namespace floormat |