#[path = "../../../os-vfs-stat/src/lib.rs"] mod stat; fn root() -> stat::Inode { stat::Inode { number: 1, kind: stat::Kind::Directory, permissions: 0o555, uid: 0, gid: 0, size: 64, allocated_bytes: 512 } } fn empty() -> stat::Inode { stat::Inode { number: 2, kind: stat::Kind::Regular, permissions: 0o444, uid: 0, gid: 0, size: 0, allocated_bytes: 0 } } fn wide() -> stat::Inode { stat::Inode { number: 3, kind: stat::Kind::Regular, permissions: 0o444, uid: 0, gid: 0, size: 513, allocated_bytes: 1024 } } fn catalog() -> stat::Catalog { stat::Catalog::new(root(), stat::Name::new(b"bos").unwrap(), empty(), stat::Name::new(b"buyuk").unwrap(), wide()).unwrap() } #[test] fn os_vfs_paths_stat_positive() { let catalog = catalog(); let before = catalog; let root = catalog.stat_root(); assert_eq!((root.inode, root.kind, root.permissions, root.size, root.blocks512), (1, stat::Kind::Directory, 0o555, 64, 1)); let empty = catalog.stat_file(b"bos").unwrap(); assert_eq!((empty.inode, empty.kind, empty.permissions, empty.size, empty.blocks512), (2, stat::Kind::Regular, 0o444, 0, 0)); let wide = catalog.stat_file(b"buyuk").unwrap(); assert_eq!((wide.inode, wide.kind, wide.permissions, wide.size, wide.blocks512), (3, stat::Kind::Regular, 0o444, 513, 2)); assert_eq!((empty.uid, empty.gid, wide.uid, wide.gid), (0, 0, 0, 0)); assert_eq!(stat::STAT_WIRE_BYTES, 40); let wire = stat::StatWire::from(wide); assert_eq!((wire.inode, wire.size, wire.blocks512, wire.kind, wire.permissions, wire.uid, wire.gid), (3, 513, 2, 2, 0o444, 0, 0)); assert_eq!(catalog, before); } #[test] fn os_vfs_paths_stat_negative() { let healthy = catalog(); let mut corrupt = wide(); corrupt.size = 1025; assert_eq!(stat::Catalog::new(root(), stat::Name::new(b"bos").unwrap(), empty(), stat::Name::new(b"buyuk").unwrap(), corrupt), Err(stat::Error::CorruptInodeSize)); assert_eq!(healthy.stat_file(b"buyuk").unwrap().size, 513); assert_eq!(healthy.stat_file(b"olmayan"), Err(stat::Error::NoEntry)); assert_eq!(healthy.stat_file(&[0xff]), Err(stat::Error::InvalidName)); assert_eq!(healthy, catalog()); }