]> git.saurik.com Git - apple/xnu.git/blob - tests/safe_allocation_src/ctor.adopt.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / safe_allocation_src / ctor.adopt.cpp
1 //
2 // Tests for
3 // explicit safe_allocation(T* data, size_t n, adopt_memory_t);
4 //
5
6 #include <libkern/c++/safe_allocation.h>
7 #include <darwintest.h>
8 #include "test_utils.h"
9
10 struct T {
11 int i;
12 };
13
14 template <typename T>
15 static void
16 tests()
17 {
18 {
19 T* memory = reinterpret_cast<T*>(tracking_allocator::allocate(10 * sizeof(T)));
20 tracking_allocator::reset();
21 {
22 tracked_safe_allocation<T> array(memory, 10, libkern::adopt_memory);
23 CHECK(!tracking_allocator::did_allocate);
24 CHECK(array.data() == memory);
25 CHECK(array.size() == 10);
26 CHECK(array.begin() == array.data());
27 CHECK(array.end() == array.data() + 10);
28 }
29 CHECK(tracking_allocator::deallocated_size == 10 * sizeof(T));
30 }
31 }
32
33 T_DECL(ctor_adopt, "safe_allocation.ctor.adopt") {
34 tests<T>();
35 tests<T const>();
36 }