X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/eb6b6ca394357805f2bdba989abae309f718b4d8..f427ee49d309d8fc33ebf3042c3a775f2f530ded:/tests/bounded_ptr_src/assign.nullptr.cpp?ds=inline diff --git a/tests/bounded_ptr_src/assign.nullptr.cpp b/tests/bounded_ptr_src/assign.nullptr.cpp new file mode 100644 index 000000000..a9f062650 --- /dev/null +++ b/tests/bounded_ptr_src/assign.nullptr.cpp @@ -0,0 +1,55 @@ +// +// Tests for +// bounded_ptr& operator=(std::nullptr_t); +// + +#include +#include +#include +#include +#include "test_utils.h" + +#define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__) + +struct T { }; + +template +static void +tests() +{ + T obj{}; + + // Assign from nullptr + { + test_bounded_ptr p(&obj, &obj, &obj + 1); + _assert(p != nullptr); + test_bounded_ptr& ref = (p = nullptr); + _assert(&ref == &p); + _assert(p == nullptr); + } + + // Assign from NULL + { + test_bounded_ptr p(&obj, &obj, &obj + 1); + _assert(p != nullptr); + test_bounded_ptr& ref = (p = NULL); + _assert(&ref == &p); + _assert(p == nullptr); + } + + // Assign from 0 + { + test_bounded_ptr p(&obj, &obj, &obj + 1); + _assert(p != nullptr); + test_bounded_ptr& ref = (p = 0); + _assert(&ref == &p); + _assert(p == nullptr); + } +} + +T_DECL(assign_nullptr, "bounded_ptr.assign.nullptr") { + tests(); + tests(); + tests(); + tests(); +}