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