MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_slice_uninit

Function test_slice_uninit

src/buffer.rs:397–426  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

395 #[cfg(not(windows))]
396 #[test]
397 fn test_slice_uninit() {
398 use crate::io::read;
399 use core::mem::MaybeUninit;
400 use std::io::{Seek, SeekFrom};
401
402 // We need to obtain input stream with contents that we can compare
403 // against, so open our own source file.
404 let mut input = std::fs::File::open("src/buffer.rs").unwrap();
405
406 let mut buf = [MaybeUninit::<u8>::uninit(); 64];
407 let (init, uninit) = read(&input, &mut buf).unwrap();
408 assert_eq!(uninit.len(), 0);
409 assert_eq!(
410 &init[..58],
411 b"//! Utilities for functions that return data via buffers.\n"
412 );
413 assert_eq!(init.len(), buf.len());
414 assert_eq!(
415 unsafe { core::mem::transmute::<&mut [MaybeUninit<u8>], &mut [u8]>(&mut buf[..58]) },
416 b"//! Utilities for functions that return data via buffers.\n"
417 );
418 input.seek(SeekFrom::End(-1)).unwrap();
419 let (init, uninit) = read(&input, &mut buf).unwrap();
420 assert_eq!(init.len(), 1);
421 assert_eq!(uninit.len(), buf.len() - 1);
422 input.seek(SeekFrom::End(0)).unwrap();
423 let (init, uninit) = read(&input, &mut buf).unwrap();
424 assert_eq!(init.len(), 0);
425 assert_eq!(uninit.len(), buf.len());
426 }
427
428 #[cfg(not(windows))]
429 #[test]

Callers

nothing calls this directly

Calls 3

openFunction · 0.70
readFunction · 0.50
seekMethod · 0.45

Tested by

no test coverage detected