about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorJonathan Reem <jonathan.reem@gmail.com>2015-07-09 17:33:00 -0700
committerJonathan Reem <jonathan.reem@gmail.com>2015-07-09 17:41:09 -0700
commit69579e4d37849fe64cbdfc7e40dc614af802704d (patch)
treeaa0e5c16bae65fe1c41e3ea203f8a97f13cf76bb /src/libstd/ffi
parent84f9c61c69d311457d7a259be95876f5e4f5825e (diff)
downloadrust-69579e4d37849fe64cbdfc7e40dc614af802704d.tar.gz
rust-69579e4d37849fe64cbdfc7e40dc614af802704d.zip
Test that CStr and CString have equivalent hashes.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 1ddd74d3f4f..f13c10156f5 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -538,4 +538,19 @@ mod tests {
         let owned = unsafe { CStr::from_ptr(ptr).to_owned() };
         assert_eq!(owned.as_bytes_with_nul(), data);
     }
+
+    #[test]
+    fn equal_hash() {
+        use hash;
+
+        let data = b"123\xE2\xFA\xA6\0";
+        let ptr = data.as_ptr() as *const libc::c_char;
+        let cstr: &'static CStr = unsafe { CStr::from_ptr(ptr) };
+
+        let cstr_hash = hash::hash::<_, hash::SipHasher>(&cstr);
+        let cstring_hash =
+            hash::hash::<_, hash::SipHasher>(&CString::new(&data[..data.len() - 1]).unwrap());
+
+        assert_eq!(cstr_hash, cstring_hash);
+    }
 }