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