]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/intrusive_shared_ptr_src/detach.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / detach.cpp
diff --git a/tests/intrusive_shared_ptr_src/detach.cpp b/tests/intrusive_shared_ptr_src/detach.cpp
new file mode 100644 (file)
index 0000000..6e34335
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// Tests for
+//  pointer detach() noexcept;
+//
+
+#include <libkern/c++/intrusive_shared_ptr.h>
+#include <darwintest.h>
+#include "test_policy.h"
+
+struct T {
+       int i;
+};
+
+template <typename T>
+static void
+tests()
+{
+       T obj{3};
+
+       tracking_policy::reset();
+       tracked_shared_ptr<T> ptr(&obj, libkern::retain);
+       T* raw = ptr.detach();
+       CHECK(raw == &obj);
+       CHECK(ptr.get() == nullptr); // ptr was set to null
+       CHECK(tracking_policy::retains == 1);
+       CHECK(tracking_policy::releases == 0);
+}
+
+T_DECL(detach, "intrusive_shared_ptr.detach") {
+       tests<T>();
+       tests<T const>();
+}