]> git.lizzy.rs Git - rust.git/commitdiff
Add calloc test
authorTim Diekmann <tim.diekmann@3dvision.de>
Sun, 7 Apr 2019 23:12:50 +0000 (01:12 +0200)
committerTim Diekmann <tim.diekmann@3dvision.de>
Sun, 7 Apr 2019 23:12:50 +0000 (01:12 +0200)
tests/run-pass/calloc.rs [new file with mode: 0644]

diff --git a/tests/run-pass/calloc.rs b/tests/run-pass/calloc.rs
new file mode 100644 (file)
index 0000000..8e8e2e5
--- /dev/null
@@ -0,0 +1,26 @@
+//ignore-windows: Uses POSIX APIs
+
+#![feature(rustc_private)]
+
+use core::slice;
+
+extern crate libc;
+
+fn main() {
+    unsafe {
+        let p1 = libc::calloc(0, 0);
+        assert!(p1.is_null());
+
+        let p2 = libc::calloc(20, 0);
+        assert!(p2.is_null());
+
+        let p3 = libc::calloc(0, 20);
+        assert!(p3.is_null());
+
+        let p4 = libc::calloc(4, 8) as *const u8;
+        assert!(!p4.is_null());
+
+        let slice = slice::from_raw_parts(p4, 4 * 8);
+        assert_eq!(&slice, &[0_u8; 4 * 8]);
+    }
+}