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