summaryrefslogtreecommitdiff
path: root/asl/tests
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-11-19 23:30:55 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commitf5ef1937eafb3d96b3683d92639a193694210c70 (patch)
tree0edcffc7447c42fe8467e2b788ee8f65f96b7fe2 /asl/tests
parent3bddc19f5854857788330f11993336f645c414ab (diff)
More work on asl::box
Diffstat (limited to 'asl/tests')
-rw-r--r--asl/tests/box_tests.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp
index 6c4d543..f1a35f3 100644
--- a/asl/tests/box_tests.cpp
+++ b/asl/tests/box_tests.cpp
@@ -1,6 +1,62 @@
#include "asl/box.hpp"
#include "asl/testing/testing.hpp"
+#include "asl/tests/test_types.hpp"
static_assert(sizeof(asl::box<int>) == sizeof(int*));
+static_assert(asl::default_constructible<asl::box<int>>);
+static_assert(!asl::copyable<asl::box<int>>);
+static_assert(asl::moveable<asl::box<int>>);
+static_assert(asl::default_constructible<asl::box<NonMoveConstructible>>);
+ASL_TEST(destructor)
+{
+ bool d = false;
+
+ {
+ asl::box<DestructorObserver> box2;
+
+ {
+ auto box = asl::make_box<DestructorObserver>(&d);
+ ASL_TEST_ASSERT(!d);
+
+
+ auto box3 = ASL_MOVE(box);
+ ASL_TEST_ASSERT(!d);
+
+ box2 = ASL_MOVE(box3);
+ ASL_TEST_ASSERT(!d);
+ }
+
+ ASL_TEST_ASSERT(!d);
+ }
+
+ ASL_TEST_ASSERT(d);
+}
+
+ASL_TEST(value)
+{
+ auto b = asl::make_box<int>(24);
+ ASL_TEST_EXPECT(*b == 24);
+
+ auto b2 = ASL_MOVE(b);
+ ASL_TEST_EXPECT(*b2 == 24);
+}
+
+ASL_TEST(ptr)
+{
+ auto b = asl::make_box<int>(24);
+ auto* ptr1 = b.get();
+
+ auto b2 = ASL_MOVE(b);
+ auto* ptr2 = b2.get();
+ ASL_TEST_EXPECT(ptr1 == ptr2);
+}
+
+struct Struct { int a; };
+
+ASL_TEST(arrow)
+{
+ auto b = asl::make_box<Struct>(45);
+ ASL_TEST_EXPECT(b->a == 45);
+}