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