1*bb611c8fSApple OSS Distributions // 2*bb611c8fSApple OSS Distributions // Tests for 3*bb611c8fSApple OSS Distributions // bounded_ptr(std::nullptr_t); 4*bb611c8fSApple OSS Distributions // 5*bb611c8fSApple OSS Distributions 6*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_ptr.h> 7*bb611c8fSApple OSS Distributions #include <darwintest.h> 8*bb611c8fSApple OSS Distributions #include <darwintest_utils.h> 9*bb611c8fSApple OSS Distributions #include "test_utils.h" 10*bb611c8fSApple OSS Distributions 11*bb611c8fSApple OSS Distributions #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__) 12*bb611c8fSApple OSS Distributions 13*bb611c8fSApple OSS Distributions struct T { }; 14*bb611c8fSApple OSS Distributions 15*bb611c8fSApple OSS Distributions template <typename T> 16*bb611c8fSApple OSS Distributions static void 17*bb611c8fSApple OSS Distributions tests() 18*bb611c8fSApple OSS Distributions { 19*bb611c8fSApple OSS Distributions // Test with nullptr 20*bb611c8fSApple OSS Distributions { 21*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = nullptr; 22*bb611c8fSApple OSS Distributions _assert(p == nullptr); 23*bb611c8fSApple OSS Distributions } 24*bb611c8fSApple OSS Distributions { 25*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p{nullptr}; 26*bb611c8fSApple OSS Distributions _assert(p == nullptr); 27*bb611c8fSApple OSS Distributions } 28*bb611c8fSApple OSS Distributions { 29*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p(nullptr); 30*bb611c8fSApple OSS Distributions _assert(p == nullptr); 31*bb611c8fSApple OSS Distributions } 32*bb611c8fSApple OSS Distributions { 33*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(nullptr); 34*bb611c8fSApple OSS Distributions _assert(p == nullptr); 35*bb611c8fSApple OSS Distributions } 36*bb611c8fSApple OSS Distributions { 37*bb611c8fSApple OSS Distributions auto f = [](test_bounded_ptr<T> p) { 38*bb611c8fSApple OSS Distributions _assert(p == nullptr); 39*bb611c8fSApple OSS Distributions }; 40*bb611c8fSApple OSS Distributions f(nullptr); 41*bb611c8fSApple OSS Distributions } 42*bb611c8fSApple OSS Distributions 43*bb611c8fSApple OSS Distributions // Test with NULL 44*bb611c8fSApple OSS Distributions { 45*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = NULL; 46*bb611c8fSApple OSS Distributions _assert(p == nullptr); 47*bb611c8fSApple OSS Distributions } 48*bb611c8fSApple OSS Distributions { 49*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p{NULL}; 50*bb611c8fSApple OSS Distributions _assert(p == nullptr); 51*bb611c8fSApple OSS Distributions } 52*bb611c8fSApple OSS Distributions { 53*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p(NULL); 54*bb611c8fSApple OSS Distributions _assert(p == nullptr); 55*bb611c8fSApple OSS Distributions } 56*bb611c8fSApple OSS Distributions { 57*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(NULL); 58*bb611c8fSApple OSS Distributions _assert(p == nullptr); 59*bb611c8fSApple OSS Distributions } 60*bb611c8fSApple OSS Distributions { 61*bb611c8fSApple OSS Distributions auto f = [](test_bounded_ptr<T> p) { 62*bb611c8fSApple OSS Distributions _assert(p == nullptr); 63*bb611c8fSApple OSS Distributions }; 64*bb611c8fSApple OSS Distributions f(NULL); 65*bb611c8fSApple OSS Distributions } 66*bb611c8fSApple OSS Distributions 67*bb611c8fSApple OSS Distributions // Test with 0 68*bb611c8fSApple OSS Distributions { 69*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = 0; 70*bb611c8fSApple OSS Distributions _assert(p == nullptr); 71*bb611c8fSApple OSS Distributions } 72*bb611c8fSApple OSS Distributions { 73*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p{0}; 74*bb611c8fSApple OSS Distributions _assert(p == nullptr); 75*bb611c8fSApple OSS Distributions } 76*bb611c8fSApple OSS Distributions { 77*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p(0); 78*bb611c8fSApple OSS Distributions _assert(p == nullptr); 79*bb611c8fSApple OSS Distributions } 80*bb611c8fSApple OSS Distributions { 81*bb611c8fSApple OSS Distributions test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(0); 82*bb611c8fSApple OSS Distributions _assert(p == nullptr); 83*bb611c8fSApple OSS Distributions } 84*bb611c8fSApple OSS Distributions { 85*bb611c8fSApple OSS Distributions auto f = [](test_bounded_ptr<T> p) { 86*bb611c8fSApple OSS Distributions _assert(p == nullptr); 87*bb611c8fSApple OSS Distributions }; 88*bb611c8fSApple OSS Distributions f(0); 89*bb611c8fSApple OSS Distributions } 90*bb611c8fSApple OSS Distributions } 91*bb611c8fSApple OSS Distributions 92*bb611c8fSApple OSS Distributions T_DECL(ctor_nullptr, "bounded_ptr.ctor.nullptr") { 93*bb611c8fSApple OSS Distributions tests<T>(); 94*bb611c8fSApple OSS Distributions tests<T const>(); 95*bb611c8fSApple OSS Distributions tests<T volatile>(); 96*bb611c8fSApple OSS Distributions tests<T const volatile>(); 97*bb611c8fSApple OSS Distributions } 98