X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/eb6b6ca394357805f2bdba989abae309f718b4d8..f427ee49d309d8fc33ebf3042c3a775f2f530ded:/tests/safe_allocation_src/assign.nullptr.cpp diff --git a/tests/safe_allocation_src/assign.nullptr.cpp b/tests/safe_allocation_src/assign.nullptr.cpp new file mode 100644 index 000000000..07a13a149 --- /dev/null +++ b/tests/safe_allocation_src/assign.nullptr.cpp @@ -0,0 +1,46 @@ +// +// Tests for +// safe_allocation& operator=(std::nullptr_t); +// + +#include +#include +#include "test_utils.h" + +struct T { + int i; +}; + +template +static void +tests() +{ + // Assign to a non-null allocation + { + tracked_safe_allocation array(10, libkern::allocate_memory); + tracking_allocator::reset(); + + tracked_safe_allocation& ref = (array = nullptr); + CHECK(&ref == &array); + CHECK(array.data() == nullptr); + CHECK(array.size() == 0); + CHECK(tracking_allocator::did_deallocate); + } + + // Assign to a null allocation + { + tracked_safe_allocation array = nullptr; + tracking_allocator::reset(); + + tracked_safe_allocation& ref = (array = nullptr); + CHECK(&ref == &array); + CHECK(array.data() == nullptr); + CHECK(array.size() == 0); + CHECK(!tracking_allocator::did_deallocate); + } +} + +T_DECL(assign_nullptr, "safe_allocation.assign.nullptr") { + tests(); + tests(); +}