]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/safe_allocation_src/ctor.default.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / safe_allocation_src / ctor.default.cpp
diff --git a/tests/safe_allocation_src/ctor.default.cpp b/tests/safe_allocation_src/ctor.default.cpp
new file mode 100644 (file)
index 0000000..54e5e0f
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// Tests for
+//  explicit safe_allocation();
+//
+
+#include <libkern/c++/safe_allocation.h>
+#include <darwintest.h>
+#include "test_utils.h"
+
+struct T {
+       int i;
+};
+
+template <typename T>
+static void
+tests()
+{
+       {
+               test_safe_allocation<T> array;
+               CHECK(array.data() == nullptr);
+               CHECK(array.size() == 0);
+               CHECK(array.begin() == array.end());
+       }
+       {
+               test_safe_allocation<T> array{};
+               CHECK(array.data() == nullptr);
+               CHECK(array.size() == 0);
+               CHECK(array.begin() == array.end());
+       }
+       {
+               test_safe_allocation<T> array = test_safe_allocation<T>();
+               CHECK(array.data() == nullptr);
+               CHECK(array.size() == 0);
+               CHECK(array.begin() == array.end());
+       }
+}
+
+T_DECL(ctor_default, "safe_allocation.ctor.default") {
+       tests<T>();
+       tests<T const>();
+}