]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/bounded_ptr_src/assign.nullptr.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / bounded_ptr_src / assign.nullptr.cpp
diff --git a/tests/bounded_ptr_src/assign.nullptr.cpp b/tests/bounded_ptr_src/assign.nullptr.cpp
new file mode 100644 (file)
index 0000000..a9f0626
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// Tests for
+//  bounded_ptr& operator=(std::nullptr_t);
+//
+
+#include <cstddef>
+#include <libkern/c++/bounded_ptr.h>
+#include <darwintest.h>
+#include <darwintest_utils.h>
+#include "test_utils.h"
+
+#define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
+
+struct T { };
+
+template <typename T, typename TQual>
+static void
+tests()
+{
+       T obj{};
+
+       // Assign from nullptr
+       {
+               test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
+               _assert(p != nullptr);
+               test_bounded_ptr<TQual>& ref = (p = nullptr);
+               _assert(&ref == &p);
+               _assert(p == nullptr);
+       }
+
+       // Assign from NULL
+       {
+               test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
+               _assert(p != nullptr);
+               test_bounded_ptr<TQual>& ref = (p = NULL);
+               _assert(&ref == &p);
+               _assert(p == nullptr);
+       }
+
+       // Assign from 0
+       {
+               test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
+               _assert(p != nullptr);
+               test_bounded_ptr<TQual>& ref = (p = 0);
+               _assert(&ref == &p);
+               _assert(p == nullptr);
+       }
+}
+
+T_DECL(assign_nullptr, "bounded_ptr.assign.nullptr") {
+       tests<T, T>();
+       tests<T, T const>();
+       tests<T, T volatile>();
+       tests<T, T const volatile>();
+}