]>
git.saurik.com Git - apple/xnu.git/blob - tests/safe_allocation_src/ctor.move.cpp
3 // safe_allocation(safe_allocation&& other);
6 #include <libkern/c++/safe_allocation.h>
7 #include <darwintest.h>
8 #include "test_utils.h"
19 // Move-construct from a non-null allocation (with different syntaxes)
22 tracked_safe_allocation
<T
> from(10, libkern::allocate_memory
);
23 tracking_allocator::reset();
25 T
* memory
= from
.data();
28 tracked_safe_allocation
<T
> to(std::move(from
));
29 CHECK(!tracking_allocator::did_allocate
);
30 CHECK(to
.data() == memory
);
31 CHECK(to
.size() == 10);
32 CHECK(from
.data() == nullptr);
33 CHECK(from
.size() == 0);
35 CHECK(tracking_allocator::did_deallocate
);
36 tracking_allocator::reset();
38 CHECK(!tracking_allocator::did_deallocate
);
42 tracked_safe_allocation
<T
> from(10, libkern::allocate_memory
);
43 tracking_allocator::reset();
45 T
* memory
= from
.data();
48 tracked_safe_allocation
<T
> to
{std::move(from
)};
49 CHECK(!tracking_allocator::did_allocate
);
50 CHECK(to
.data() == memory
);
51 CHECK(to
.size() == 10);
52 CHECK(from
.data() == nullptr);
53 CHECK(from
.size() == 0);
55 CHECK(tracking_allocator::did_deallocate
);
56 tracking_allocator::reset();
58 CHECK(!tracking_allocator::did_deallocate
);
62 tracked_safe_allocation
<T
> from(10, libkern::allocate_memory
);
63 tracking_allocator::reset();
65 T
* memory
= from
.data();
68 tracked_safe_allocation
<T
> to
= std::move(from
);
69 CHECK(!tracking_allocator::did_allocate
);
70 CHECK(to
.data() == memory
);
71 CHECK(to
.size() == 10);
72 CHECK(from
.data() == nullptr);
73 CHECK(from
.size() == 0);
75 CHECK(tracking_allocator::did_deallocate
);
76 tracking_allocator::reset();
78 CHECK(!tracking_allocator::did_deallocate
);
81 // Move-construct from a null allocation
84 tracked_safe_allocation
<T
> from
= nullptr;
85 tracking_allocator::reset();
88 tracked_safe_allocation
<T
> to(std::move(from
));
89 CHECK(!tracking_allocator::did_allocate
);
90 CHECK(to
.data() == nullptr);
91 CHECK(to
.size() == 0);
92 CHECK(from
.data() == nullptr);
93 CHECK(from
.size() == 0);
95 CHECK(!tracking_allocator::did_deallocate
);
96 tracking_allocator::reset();
98 CHECK(!tracking_allocator::did_deallocate
);
102 T_DECL(ctor_move
, "safe_allocation.ctor.move") {