use super::super::{capacity_for, size_argument_for};
#[skuld::test]
fn capacity_holds_at_least_the_sizing_answer() {
for needed in [1usize, 20, 283, 1094, 100_000] {
let cap = capacity_for(needed);
assert!(
cap > needed,
"capacity_for({needed}) = {cap}: must hold {needed} pids plus room to grow"
);
}
}
#[skuld::test]
fn capacity_for_saturates_rather_than_panics_or_wraps_at_the_boundary() {
assert_eq!(capacity_for(usize::MAX), usize::MAX);
}
#[skuld::test]
fn a_pid_count_too_large_for_the_int_size_argument_is_an_error() {
let bytes = size_argument_for(4).expect("4 pids fits in an int");
assert_eq!(bytes, 4 * std::mem::size_of::<libc::c_int>() as libc::c_int);
let boundary = libc::c_int::MAX as usize / std::mem::size_of::<libc::c_int>();
let boundary_bytes = size_argument_for(boundary).expect("the exact boundary must succeed");
assert_eq!(
boundary_bytes,
(boundary * std::mem::size_of::<libc::c_int>()) as libc::c_int
);
let too_many = boundary + 1;
let err = size_argument_for(too_many).expect_err("an inexpressible size must fail");
assert_eq!(err.kind(), std::io::ErrorKind::Other);
size_argument_for(usize::MAX).expect_err("an overflowing byte count must fail");
}