1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Tests for
3*bb611c8fSApple OSS Distributions //  explicit operator bool() const;
4*bb611c8fSApple OSS Distributions //
5*bb611c8fSApple OSS Distributions 
6*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_ptr.h>
7*bb611c8fSApple OSS Distributions #include <darwintest.h>
8*bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
9*bb611c8fSApple OSS Distributions #include "test_utils.h"
10*bb611c8fSApple OSS Distributions 
11*bb611c8fSApple OSS Distributions #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
12*bb611c8fSApple OSS Distributions 
13*bb611c8fSApple OSS Distributions struct T { };
14*bb611c8fSApple OSS Distributions 
15*bb611c8fSApple OSS Distributions template <typename T>
16*bb611c8fSApple OSS Distributions static void
17*bb611c8fSApple OSS Distributions tests()
18*bb611c8fSApple OSS Distributions {
19*bb611c8fSApple OSS Distributions 	{
20*bb611c8fSApple OSS Distributions 		test_bounded_ptr<T> p = nullptr;
21*bb611c8fSApple OSS Distributions 		if (p) {
22*bb611c8fSApple OSS Distributions 			_assert(false);
23*bb611c8fSApple OSS Distributions 		}
24*bb611c8fSApple OSS Distributions 		_assert(!p);
25*bb611c8fSApple OSS Distributions 	}
26*bb611c8fSApple OSS Distributions 	{
27*bb611c8fSApple OSS Distributions 		T t;
28*bb611c8fSApple OSS Distributions 		test_bounded_ptr<T> p(&t, &t, &t + 1);
29*bb611c8fSApple OSS Distributions 		if (p) {
30*bb611c8fSApple OSS Distributions 		} else {
31*bb611c8fSApple OSS Distributions 			_assert(false);
32*bb611c8fSApple OSS Distributions 		}
33*bb611c8fSApple OSS Distributions 		_assert(!!p);
34*bb611c8fSApple OSS Distributions 	}
35*bb611c8fSApple OSS Distributions }
36*bb611c8fSApple OSS Distributions 
37*bb611c8fSApple OSS Distributions T_DECL(operator_bool, "bounded_ptr.operator.bool") {
38*bb611c8fSApple OSS Distributions 	tests<T>();
39*bb611c8fSApple OSS Distributions 	tests<T const>();
40*bb611c8fSApple OSS Distributions 	tests<T volatile>();
41*bb611c8fSApple OSS Distributions 	tests<T const volatile>();
42*bb611c8fSApple OSS Distributions }
43