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