1*2c2f96dcSApple OSS Distributions // 2*2c2f96dcSApple OSS Distributions // Tests for 3*2c2f96dcSApple OSS Distributions // explicit safe_allocation(); 4*2c2f96dcSApple OSS Distributions // 5*2c2f96dcSApple OSS Distributions 6*2c2f96dcSApple OSS Distributions #include <libkern/c++/safe_allocation.h> 7*2c2f96dcSApple OSS Distributions #include <darwintest.h> 8*2c2f96dcSApple OSS Distributions #include "test_utils.h" 9*2c2f96dcSApple OSS Distributions 10*2c2f96dcSApple OSS Distributions struct T { 11*2c2f96dcSApple OSS Distributions int i; 12*2c2f96dcSApple OSS Distributions }; 13*2c2f96dcSApple OSS Distributions 14*2c2f96dcSApple OSS Distributions template <typename T> 15*2c2f96dcSApple OSS Distributions static void tests()16*2c2f96dcSApple OSS Distributionstests() 17*2c2f96dcSApple OSS Distributions { 18*2c2f96dcSApple OSS Distributions { 19*2c2f96dcSApple OSS Distributions test_safe_allocation<T> array; 20*2c2f96dcSApple OSS Distributions CHECK(array.data() == nullptr); 21*2c2f96dcSApple OSS Distributions CHECK(array.size() == 0); 22*2c2f96dcSApple OSS Distributions CHECK(array.begin() == array.end()); 23*2c2f96dcSApple OSS Distributions } 24*2c2f96dcSApple OSS Distributions { 25*2c2f96dcSApple OSS Distributions test_safe_allocation<T> array{}; 26*2c2f96dcSApple OSS Distributions CHECK(array.data() == nullptr); 27*2c2f96dcSApple OSS Distributions CHECK(array.size() == 0); 28*2c2f96dcSApple OSS Distributions CHECK(array.begin() == array.end()); 29*2c2f96dcSApple OSS Distributions } 30*2c2f96dcSApple OSS Distributions { 31*2c2f96dcSApple OSS Distributions test_safe_allocation<T> array = test_safe_allocation<T>(); 32*2c2f96dcSApple OSS Distributions CHECK(array.data() == nullptr); 33*2c2f96dcSApple OSS Distributions CHECK(array.size() == 0); 34*2c2f96dcSApple OSS Distributions CHECK(array.begin() == array.end()); 35*2c2f96dcSApple OSS Distributions } 36*2c2f96dcSApple OSS Distributions } 37*2c2f96dcSApple OSS Distributions 38*2c2f96dcSApple OSS Distributions T_DECL(ctor_default, "safe_allocation.ctor.default") { 39*2c2f96dcSApple OSS Distributions tests<T>(); 40*2c2f96dcSApple OSS Distributions tests<T const>(); 41*2c2f96dcSApple OSS Distributions } 42