xref: /xnu-11417.140.69/tests/bounded_array_ref_src/test_policy.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions #ifndef TESTS_BOUNDED_ARRAY_REF_SRC_TEST_POLICY_H
2*43a90889SApple OSS Distributions #define TESTS_BOUNDED_ARRAY_REF_SRC_TEST_POLICY_H
3*43a90889SApple OSS Distributions 
4*43a90889SApple OSS Distributions #include <assert.h>
5*43a90889SApple OSS Distributions #include <darwintest_utils.h>
6*43a90889SApple OSS Distributions #include <libkern/c++/bounded_array.h>
7*43a90889SApple OSS Distributions #include <libkern/c++/bounded_array_ref.h>
8*43a90889SApple OSS Distributions #include <libkern/c++/bounded_ptr.h>
9*43a90889SApple OSS Distributions #include <stddef.h>
10*43a90889SApple OSS Distributions #include <string>
11*43a90889SApple OSS Distributions 
12*43a90889SApple OSS Distributions namespace {
13*43a90889SApple OSS Distributions struct test_policy {
14*43a90889SApple OSS Distributions 	static void
traptest_policy15*43a90889SApple OSS Distributions 	trap(char const*)
16*43a90889SApple OSS Distributions 	{
17*43a90889SApple OSS Distributions 		assert(false);
18*43a90889SApple OSS Distributions 	}
19*43a90889SApple OSS Distributions };
20*43a90889SApple OSS Distributions 
21*43a90889SApple OSS Distributions struct tracking_policy {
22*43a90889SApple OSS Distributions 	static bool did_trap;
23*43a90889SApple OSS Distributions 	static std::string message;
24*43a90889SApple OSS Distributions 	static void
traptracking_policy25*43a90889SApple OSS Distributions 	trap(char const* m)
26*43a90889SApple OSS Distributions 	{
27*43a90889SApple OSS Distributions 		did_trap = true;
28*43a90889SApple OSS Distributions 		message.assign(m);
29*43a90889SApple OSS Distributions 	}
30*43a90889SApple OSS Distributions 	static void
resettracking_policy31*43a90889SApple OSS Distributions 	reset()
32*43a90889SApple OSS Distributions 	{
33*43a90889SApple OSS Distributions 		did_trap = false;
34*43a90889SApple OSS Distributions 		message = "";
35*43a90889SApple OSS Distributions 	}
36*43a90889SApple OSS Distributions };
37*43a90889SApple OSS Distributions bool tracking_policy::did_trap = false;
38*43a90889SApple OSS Distributions std::string tracking_policy::message = "";
39*43a90889SApple OSS Distributions }
40*43a90889SApple OSS Distributions 
41*43a90889SApple OSS Distributions template <typename T>
42*43a90889SApple OSS Distributions using test_bounded_array_ref = libkern::bounded_array_ref<T, test_policy>;
43*43a90889SApple OSS Distributions 
44*43a90889SApple OSS Distributions template <typename T, size_t N>
45*43a90889SApple OSS Distributions using test_bounded_array = libkern::bounded_array<T, N, test_policy>;
46*43a90889SApple OSS Distributions 
47*43a90889SApple OSS Distributions template <typename T>
48*43a90889SApple OSS Distributions using test_bounded_ptr = libkern::bounded_ptr<T, test_policy>;
49*43a90889SApple OSS Distributions 
50*43a90889SApple OSS Distributions #define CHECK(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
51*43a90889SApple OSS Distributions 
52*43a90889SApple OSS Distributions #endif // !TESTS_BOUNDED_ARRAY_REF_SRC_TEST_POLICY_H
53