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