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