1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Make sure `safe_allocation` can be used to create a two-dimensional array.
3*bb611c8fSApple OSS Distributions //
4*bb611c8fSApple OSS Distributions // Note that we don't really recommend using that representation for two
5*bb611c8fSApple OSS Distributions // dimensional arrays because other representations are better, but it
6*bb611c8fSApple OSS Distributions // should at least work.
7*bb611c8fSApple OSS Distributions //
8*bb611c8fSApple OSS Distributions 
9*bb611c8fSApple OSS Distributions #include <libkern/c++/safe_allocation.h>
10*bb611c8fSApple OSS Distributions #include <darwintest.h>
11*bb611c8fSApple OSS Distributions #include "test_utils.h"
12*bb611c8fSApple OSS Distributions 
13*bb611c8fSApple OSS Distributions struct T {
14*bb611c8fSApple OSS Distributions 	int i;
15*bb611c8fSApple OSS Distributions };
16*bb611c8fSApple OSS Distributions 
17*bb611c8fSApple OSS Distributions template <typename T>
18*bb611c8fSApple OSS Distributions static void
19*bb611c8fSApple OSS Distributions tests()
20*bb611c8fSApple OSS Distributions {
21*bb611c8fSApple OSS Distributions 	test_safe_allocation<test_safe_allocation<int> > array(10, libkern::allocate_memory);
22*bb611c8fSApple OSS Distributions 
23*bb611c8fSApple OSS Distributions 	for (int i = 0; i < 10; i++) {
24*bb611c8fSApple OSS Distributions 		array[i] = test_safe_allocation<int>(10, libkern::allocate_memory);
25*bb611c8fSApple OSS Distributions 		for (int j = 0; j < 10; ++j) {
26*bb611c8fSApple OSS Distributions 			array[i][j] = i + j;
27*bb611c8fSApple OSS Distributions 		}
28*bb611c8fSApple OSS Distributions 	}
29*bb611c8fSApple OSS Distributions 
30*bb611c8fSApple OSS Distributions 	for (int i = 0; i < 10; i++) {
31*bb611c8fSApple OSS Distributions 		for (int j = 0; j < 10; ++j) {
32*bb611c8fSApple OSS Distributions 			CHECK(array[i][j] == i + j);
33*bb611c8fSApple OSS Distributions 		}
34*bb611c8fSApple OSS Distributions 	}
35*bb611c8fSApple OSS Distributions }
36*bb611c8fSApple OSS Distributions 
37*bb611c8fSApple OSS Distributions T_DECL(usage_two_dimensions, "safe_allocation.usage.two_dimensions") {
38*bb611c8fSApple OSS Distributions 	tests<T>();
39*bb611c8fSApple OSS Distributions }
40