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