diff options
Diffstat (limited to 'test/entity.cpp')
| -rw-r--r-- | test/entity.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/test/entity.cpp b/test/entity.cpp index 80032b6f..21783e24 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -1,13 +1,14 @@ #include "app.hpp" #include "compat/assert.hpp" #include "src/entity.hpp" +#include <tuple> using namespace floormat; using namespace floormat::entities; struct TestAccessors { - int bar() const { return _bar; } - void set_bar(int value) { _bar = value; } + constexpr int bar() const { return _bar; } + constexpr void set_bar(int value) { _bar = value; } int foo; int _bar; int _baz; @@ -22,7 +23,7 @@ static constexpr auto m_baz = entity::type<int>::field("baz"_s, r_baz, w_baz); namespace floormat { -static void test_accessors() +static constexpr bool test_accessors() { auto x = TestAccessors{111, 222, 333}; @@ -38,11 +39,30 @@ static void test_accessors() auto a = m_foo.read(x), b = m_bar.read(x), c = m_baz.read(x); fm_assert(a == 1111 && b == 2222 && c == 3333); } + return true; +} + +static constexpr bool test_visitor() +{ + { + int ret = 0; + visit_tuple([&](auto x) { ret += x; }, + std::tuple<int, short, char, long>{ 1, 2, 3, 4 }); + fm_assert(ret == 1 + 2 + 3 + 4); + } + { + int ret = 0; + visit_tuple([&] { ret++; }, std::tuple<>{}); + fm_assert(ret == 0); + } + + return true; } void test_app::test_entity() { - test_accessors(); + static_assert(test_accessors()); + static_assert(test_visitor()); } } // namespace floormat |
