1 // 2 // Tests for 3 // T* data(); 4 // T const* data() const; 5 // 6 7 #include <libkern/c++/safe_allocation.h> 8 #include <darwintest.h> 9 #include "test_utils.h" 10 11 struct T { 12 int i; 13 }; 14 15 template <typename T> 16 static void 17 tests() 18 { 19 { 20 test_safe_allocation<T> array(10, libkern::allocate_memory); 21 CHECK(array.data() != nullptr); 22 } 23 { 24 T* memory = reinterpret_cast<T*>(malloc_allocator::allocate(10 * sizeof(T))); 25 test_safe_allocation<T> array(memory, 10, libkern::adopt_memory); 26 T* data = array.data(); 27 CHECK(data == memory); 28 } 29 { 30 T* memory = reinterpret_cast<T*>(malloc_allocator::allocate(10 * sizeof(T))); 31 test_safe_allocation<T> const array(memory, 10, libkern::adopt_memory); 32 T const* data = array.data(); 33 CHECK(data == memory); 34 } 35 } 36 37 T_DECL(data, "safe_allocation.data") { 38 tests<T>(); 39 tests<T const>(); 40 } 41