]> git.saurik.com Git - apple/xnu.git/blob - tests/safe_allocation_src/usage.for_loop.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / safe_allocation_src / usage.for_loop.cpp
1 //
2 // Make sure `safe_allocation` works nicely with the range-based for-loop.
3 //
4
5 #include <libkern/c++/safe_allocation.h>
6 #include <darwintest.h>
7 #include "test_utils.h"
8
9 struct T {
10 int i;
11 };
12
13 template <typename T>
14 static void
15 tests()
16 {
17 test_safe_allocation<T> array(10, libkern::allocate_memory);
18 for (T& element : array) {
19 element = T{3};
20 }
21
22 for (T const& element : array) {
23 CHECK(element.i == 3);
24 }
25 }
26
27 T_DECL(usage_for_loop, "safe_allocation.usage.for_loop") {
28 tests<T>();
29 }