]> git.saurik.com Git - apple/xnu.git/blame - tests/safe_allocation_src/data.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / safe_allocation_src / data.cpp
CommitLineData
f427ee49
A
1//
2// Tests for
3// T* data();
4// T const* data() const;
5//
6
7#include <libkern/c++/safe_allocation.h>
8#include <darwintest.h>
9#include "test_utils.h"
10
11struct T {
12 int i;
13};
14
15template <typename T>
16static void
17tests()
18{
19 {
20 test_safe_allocation<T> array(10, libkern::allocate_memory);
21 CHECK(array.data() != nullptr);
22 }
23 {
24 T* memory = reinterpret_cast<T*>(malloc_allocator::allocate(10 * sizeof(T)));
25 test_safe_allocation<T> array(memory, 10, libkern::adopt_memory);
26 T* data = array.data();
27 CHECK(data == memory);
28 }
29 {
30 T* memory = reinterpret_cast<T*>(malloc_allocator::allocate(10 * sizeof(T)));
31 test_safe_allocation<T> const array(memory, 10, libkern::adopt_memory);
32 T const* data = array.data();
33 CHECK(data == memory);
34 }
35}
36
37T_DECL(data, "safe_allocation.data") {
38 tests<T>();
39 tests<T const>();
40}