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