summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/app.cpp1
-rw-r--r--test/app.hpp1
-rw-r--r--test/bptr.cpp64
-rw-r--r--test/critter.cpp4
-rw-r--r--test/entity.cpp6
-rw-r--r--test/hole.cpp43
-rw-r--r--test/save.cpp1
-rw-r--r--test/util.cpp45
8 files changed, 158 insertions, 7 deletions
diff --git a/test/app.cpp b/test/app.cpp
index 6ace3ca5..c3ffa8fd 100644
--- a/test/app.cpp
+++ b/test/app.cpp
@@ -58,6 +58,7 @@ int App::exec()
FM_TEST(test_local),
// fast
FM_TEST(test_magnum_math),
+ FM_TEST(test_util),
FM_TEST(test_math),
FM_TEST(test_astar_pool),
FM_TEST(test_coords),
diff --git a/test/app.hpp b/test/app.hpp
index b1995e77..0e4d7a3a 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -41,6 +41,7 @@ void test_rtree();
void test_save();
void test_saves();
void test_script();
+void test_util();
void test_wall_atlas();
void test_wall_atlas2();
diff --git a/test/bptr.cpp b/test/bptr.cpp
index e9d0dff3..7e225a2d 100644
--- a/test/bptr.cpp
+++ b/test/bptr.cpp
@@ -2,7 +2,11 @@
#include "compat/borrowed-ptr.inl"
#include "compat/assert.hpp"
#include "compat/defs.hpp"
+#ifndef FM_NO_WEAK_BPTR
+#include "compat/weak-borrowed-ptr.inl"
+#endif
#include <array>
+#include <cr/Debug.h>
namespace floormat {
@@ -291,7 +295,7 @@ void test8()
p1 = p2;
fm_assert(A_total == 2 && A_alive == 1);
- p2 = move(p1);
+ p2 = move(p1); (void)p2;
fm_assert(A_total == 2 && A_alive == 1);
p1.reset();
@@ -332,7 +336,7 @@ void test9()
fm_assert(p1.use_count() == 0);
fm_assert(p2.use_count() == 0);
fm_assert(A_total == 1 && A_alive == 0);
-};
+}
void test10()
{
@@ -373,10 +377,22 @@ void test11()
auto p1 = bptr<bptr_base>{new Foo{1}};
auto p2 = static_pointer_cast<Foo>(p1);
auto p3 = static_pointer_cast<bptr_base>(p1);
+
fm_assert(p2->x == 1);
fm_assert(p3);
p1.destroy();
fm_assert(!p2); fm_assert(!p3);
+
+ p1.destroy();
+ p1.destroy();
+ p1.destroy();
+ p2.destroy();
+ p2.destroy();
+ p2.destroy();
+ p3.destroy();
+ p3.destroy();
+ p3.destroy();
+ fm_assert(!p1); fm_assert(!p2); fm_assert(!p3);
}
void test12()
@@ -390,6 +406,48 @@ void test12()
fm_assert(p1.use_count() == 1);
}
+void test13()
+{
+#ifndef FM_NO_WEAK_BPTR
+ auto p1 = bptr<Foo>{InPlace, 13};
+ fm_assert_equal(13, p1->x);
+ auto w1 = weak_bptr{p1};
+ fm_assert(p1); fm_assert(w1.lock());
+ fm_assert_equal(1u, p1.use_count());
+ auto p2 = p1;
+ fm_assert_equal(2u, p2.use_count());
+ p1 = {};
+ fm_assert_equal(1u, p2.use_count());
+ fm_assert(!p1); fm_assert(p2);
+ fm_assert(w1.lock());
+ fm_assert_equal(13, w1.lock()->x);
+ p2 = {}; (void)p2;
+ fm_assert(!w1.lock());
+#endif
+}
+
+void test14()
+{
+#ifndef FM_NO_WEAK_BPTR
+ auto p1 = bptr<Foo>{InPlace, 14};
+ auto w1 = weak_bptr{p1};
+ auto w2 = weak_bptr{p1};
+ fm_assert_equal(14, w1.lock()->x);
+ fm_assert_equal(14, w2.lock()->x);
+ fm_assert_equal(1u, p1.use_count());
+ w1 = {};
+ fm_assert(p1);
+ fm_assert_equal(1u, p1.use_count());
+ w2 = {}; (void)w2;
+ fm_assert(p1);
+ fm_assert_equal(1u, p1.use_count());
+ auto w3 = weak_bptr{p1};
+ fm_assert_equal(14, w3.lock()->x);
+ p1 = {}; (void)p1;
+ fm_assert(!w1.lock()); fm_assert(!w2.lock()); fm_assert(!w3.lock());
+#endif
+}
+
} // namespace
void Test::test_bptr()
@@ -406,6 +464,8 @@ void Test::test_bptr()
test10();
test11();
test12();
+ test13();
+ test14();
}
} // namespace floormat
diff --git a/test/critter.cpp b/test/critter.cpp
index 90619ce8..5b7ee52d 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -18,6 +18,8 @@ namespace floormat {
namespace {
+namespace fm_debug = floormat::debug::detail;
+
using enum rotation;
using fu2::function_view;
using Function = function_view<Ns() const>;
@@ -147,7 +149,7 @@ bool run(world& w, const function_view<Ns() const>& make_dt,
if (b) [[likely]]
return false;
else
- fm_emit_assert_fail("false", file, line);
+ fm_debug::emit_abort(file, line, "false");
};
for (i = 0; true; i++)
diff --git a/test/entity.cpp b/test/entity.cpp
index 2bbdf29a..97ffd7a7 100644
--- a/test/entity.cpp
+++ b/test/entity.cpp
@@ -258,7 +258,7 @@ void test_range2()
const auto A = m_foo.erased();
auto r = A.get_range(&x);
auto i = r.convert<int>();
- fm_assert(i.second == rʹ.max);
+ fm_assert(i.second() == rʹ.max);
}
constexpr bool test_range3()
@@ -277,8 +277,8 @@ void test_range4()
constexpr auto rʹ = f.get_range(f.range, TestAccessors{});
const auto A = f.erased();
const auto r = A.get_range(&x).convert<Vector2i>();
- fm_assert(r.first == rʹ.min);
- fm_assert(r.second == rʹ.max);
+ fm_assert(r.first() == rʹ.min);
+ fm_assert(r.second() == rʹ.max);
}
constexpr bool test_enum_range()
diff --git a/test/hole.cpp b/test/hole.cpp
index 7ccc86c3..09395c47 100644
--- a/test/hole.cpp
+++ b/test/hole.cpp
@@ -1,5 +1,7 @@
#include "app.hpp"
#include "src/hole.hpp"
+#include "src/hole-cut.hpp"
+#include "src/tile-constants.hpp"
namespace floormat {
namespace {
@@ -53,6 +55,44 @@ void test1(Vector2i offset)
#endif
}
+auto make_search_predicate(const CutResult<int>& res)
+{
+ return [&](Vector2i min, Vector2i max) -> bool {
+ for (auto i = 0u; i < res.size; i++)
+ if (res.array[i].min == min && res.array[i].max == max)
+ return true;
+ return false;
+ };
+}
+
+void test2()
+{
+ const auto res = CutResult<int>::cut({{}, Vector2ub{tile_size_xy}}, {Vector2i(-tile_size_xy/2), Vector2ub{tile_size_xy}});
+ fm_assert(res.size == 2);
+ const auto has = make_search_predicate(res);
+ fm_assert(has({-32, 0}, {32, 32}));
+ fm_assert(has({0, -32}, {32, 0}));
+}
+
+void test3()
+{
+ constexpr auto h = tile_size_xy/2;
+
+ {
+ const auto res = CutResult<Int>::cut({-h, -1}, {h, 1}, {-2, -100}, {2, 100});
+ fm_assert(res.found());
+ fm_assert_equal(2, (int)res.size);
+ }
+ {
+ const auto res = CutResult<Int>::cut({-h, 0}, {h, 0}, {-2, -100}, {2, 100});
+ fm_assert(res.found());
+ fm_assert_equal(2, (int)res.size);
+ const auto has = make_search_predicate(res);
+ fm_assert(has({-h, 0}, {-2, 0}));
+ fm_assert(has({ 2, 0}, { h, 0}));
+ }
+}
+
} // namespace
void Test::test_hole()
@@ -67,6 +107,9 @@ void Test::test_hole()
for (auto offset : offsets)
test1(offset);
+
+ test2();
+ test3();
}
} // namespace floormat
diff --git a/test/save.cpp b/test/save.cpp
index 04c9810c..76cdd271 100644
--- a/test/save.cpp
+++ b/test/save.cpp
@@ -103,7 +103,6 @@ void assert_chunks_equal(const chunk& a, const chunk& b)
case object_type::COUNT:
fm_assert(false);
case object_type::critter: {
- // todo! remove duplication
const auto& e1 = static_cast<const critter&>(ae);
const auto& e2 = static_cast<const critter&>(be);
const auto p1 = critter_proto(e1), p2 = critter_proto(e2);
diff --git a/test/util.cpp b/test/util.cpp
new file mode 100644
index 00000000..e250b072
--- /dev/null
+++ b/test/util.cpp
@@ -0,0 +1,45 @@
+#include "app.hpp"
+#include "compat/array-size.hpp"
+
+namespace floormat::Test {
+
+namespace {
+
+struct Foo
+{
+ static constexpr std::array<int, 11> Array_1 = {};
+ static constexpr const void* Array_2[22] = {};
+
+ std::array<int, 33> array_3;
+ int array_4[55] = {};
+};
+
+constexpr bool test_array_size()
+{
+ fm_assert(static_array_size<decltype(Foo::Array_1)> == 11);
+ fm_assert(array_size(Foo::Array_1) == 11);
+
+ fm_assert(static_array_size<decltype(Foo::Array_2)> == 22);
+ fm_assert(array_size(&Foo::Array_2) == 22);
+
+ fm_assert(static_array_size<decltype(Foo{}.array_3)> == 33);
+ fm_assert(array_size(Foo{}.array_3) == 33);
+ fm_assert(array_size(&Foo::array_3) == 33);
+
+ fm_assert(static_array_size<const int(&)[44]> == 44);
+
+ fm_assert(static_array_size<decltype(Foo::array_4)> == 55);
+ fm_assert(array_size(&Foo::array_4) == 55);
+ fm_assert(array_size(Foo{}.array_4) == 55);
+
+ return true;
+}
+
+} // namespace
+
+void test_util()
+{
+ static_assert(test_array_size());
+}
+
+} // namespace floormat::Test