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