xref: /xnu-8020.140.41/tests/bounded_ptr_src/operator_bool.cpp (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1*27b03b36SApple OSS Distributions //
2*27b03b36SApple OSS Distributions // Tests for
3*27b03b36SApple OSS Distributions //  explicit operator bool() const;
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 Distributions tests()
18*27b03b36SApple OSS Distributions {
19*27b03b36SApple OSS Distributions 	{
20*27b03b36SApple OSS Distributions 		test_bounded_ptr<T> p = nullptr;
21*27b03b36SApple OSS Distributions 		if (p) {
22*27b03b36SApple OSS Distributions 			_assert(false);
23*27b03b36SApple OSS Distributions 		}
24*27b03b36SApple OSS Distributions 		_assert(!p);
25*27b03b36SApple OSS Distributions 	}
26*27b03b36SApple OSS Distributions 	{
27*27b03b36SApple OSS Distributions 		T t;
28*27b03b36SApple OSS Distributions 		test_bounded_ptr<T> p(&t, &t, &t + 1);
29*27b03b36SApple OSS Distributions 		if (p) {
30*27b03b36SApple OSS Distributions 		} else {
31*27b03b36SApple OSS Distributions 			_assert(false);
32*27b03b36SApple OSS Distributions 		}
33*27b03b36SApple OSS Distributions 		_assert(!!p);
34*27b03b36SApple OSS Distributions 	}
35*27b03b36SApple OSS Distributions }
36*27b03b36SApple OSS Distributions 
37*27b03b36SApple OSS Distributions T_DECL(operator_bool, "bounded_ptr.operator.bool") {
38*27b03b36SApple OSS Distributions 	tests<T>();
39*27b03b36SApple OSS Distributions 	tests<T const>();
40*27b03b36SApple OSS Distributions 	tests<T volatile>();
41*27b03b36SApple OSS Distributions 	tests<T const volatile>();
42*27b03b36SApple OSS Distributions }
43