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