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