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_array_ref.h>
7*bb611c8fSApple OSS Distributions #include "test_policy.h"
8*bb611c8fSApple OSS Distributions #include <darwintest.h>
9*bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
10*bb611c8fSApple OSS Distributions 
11*bb611c8fSApple OSS Distributions struct T { int i; };
12*bb611c8fSApple OSS Distributions 
13*bb611c8fSApple OSS Distributions template <typename T>
14*bb611c8fSApple OSS Distributions static void
15*bb611c8fSApple OSS Distributions tests()
16*bb611c8fSApple OSS Distributions {
17*bb611c8fSApple OSS Distributions 	{
18*bb611c8fSApple OSS Distributions 		test_bounded_array_ref<T> const view;
19*bb611c8fSApple OSS Distributions 		if (view) {
20*bb611c8fSApple OSS Distributions 			CHECK(false);
21*bb611c8fSApple OSS Distributions 		}
22*bb611c8fSApple OSS Distributions 		CHECK(!view);
23*bb611c8fSApple OSS Distributions 	}
24*bb611c8fSApple OSS Distributions 	{
25*bb611c8fSApple OSS Distributions 		T array[5] = {};
26*bb611c8fSApple OSS Distributions 		test_bounded_array_ref<T> const view(array);
27*bb611c8fSApple OSS Distributions 		if (view) {
28*bb611c8fSApple OSS Distributions 		} else {
29*bb611c8fSApple OSS Distributions 			CHECK(false);
30*bb611c8fSApple OSS Distributions 		}
31*bb611c8fSApple OSS Distributions 		CHECK(!!view);
32*bb611c8fSApple OSS Distributions 	}
33*bb611c8fSApple OSS Distributions }
34*bb611c8fSApple OSS Distributions 
35*bb611c8fSApple OSS Distributions T_DECL(operator_bool, "bounded_array_ref.operator.bool") {
36*bb611c8fSApple OSS Distributions 	tests<T>();
37*bb611c8fSApple OSS Distributions 	tests<T const>();
38*bb611c8fSApple OSS Distributions }
39