summaryrefslogtreecommitdiff
path: root/test/test_stat.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2015-02-21 14:33:27 -0800
committerCarl Lerche <me@carllerche.com>2015-02-21 14:33:27 -0800
commit60ccee778b2adca488706c586bd61c5affa90de3 (patch)
treed8738241a4e5fa8fe02331f33ab190b980d507fd /test/test_stat.rs
parentb2454c9d793dfeb946d5e12f51ad571d32fa9987 (diff)
downloadnix-60ccee778b2adca488706c586bd61c5affa90de3.zip
Cleanup readv & writev + tests
Diffstat (limited to 'test/test_stat.rs')
-rw-r--r--test/test_stat.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_stat.rs b/test/test_stat.rs
new file mode 100644
index 00000000..ac4a8f08
--- /dev/null
+++ b/test/test_stat.rs
@@ -0,0 +1,31 @@
+use nix::sys::stat::stat;
+
+#[test]
+fn test_stat() {
+ use nix::fcntl::open;
+ use nix::unistd::{close, unlink};
+ use nix::fcntl::O_CREAT;
+ use nix::sys::stat::S_IWUSR;
+
+ let filename = b"target/foo.txt";
+ let fd_res = open(filename, O_CREAT, S_IWUSR).unwrap();
+ close(fd_res).unwrap(); //.ok().unwrap()); // close right here. We use the file only for the stat test
+ let stat_result = stat(filename);
+
+ match stat_result {
+ Ok(stats) => {
+ assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
+ assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent
+ assert!(stats.st_mode > 0); // must be positive integer
+ assert!(stats.st_nlink == 1); // there links created, must be 1
+ assert!(stats.st_uid > 0); // must be positive integer
+ assert!(stats.st_gid > 0); // must be positive integer
+ assert!(stats.st_rdev == 0); // no special device
+ assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file
+ assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent
+ assert!(stats.st_blocks == 0); // no blocks allocated because file size is 0
+ }
+ Err(_) => panic!("stat call failed") // if stats system call fails, something is seriously wrong on that machine
+ }
+ unlink(filename).unwrap();
+}