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