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