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