Nothing to see here, move along meow
1use lancer_core::ipc::{IPC_MSG_WORDS, MAX_IPC_BYTES, pack_bytes, unpack_bytes};
2use proptest::prelude::*;
3
4#[test]
5fn empty_input_packs_to_zero_message() {
6 let msg = pack_bytes(&[]);
7 assert!(msg.iter().all(|&w| w == 0));
8}
9
10#[test]
11fn single_byte_positioning() {
12 (0..MAX_IPC_BYTES).for_each(|i| {
13 let mut src = [0u8; MAX_IPC_BYTES];
14 src[i] = 0xAB;
15 let msg = pack_bytes(&src[..=i]);
16 let word_idx = i / 8;
17 let byte_idx = i % 8;
18 let extracted = ((msg[1 + word_idx] >> (byte_idx * 8)) & 0xFF) as u8;
19 assert_eq!(extracted, 0xAB, "byte at position {i} misplaced");
20 });
21}
22
23#[test]
24fn overcapacity_clamp() {
25 let mut msg = [0u64; IPC_MSG_WORDS];
26 msg[0] = 100;
27 let mut dst = [0u8; MAX_IPC_BYTES];
28 let count = unpack_bytes(&msg, &mut dst);
29 assert_eq!(count, MAX_IPC_BYTES);
30}
31
32proptest! {
33 #[test]
34 fn round_trip(bytes in proptest::collection::vec(any::<u8>(), 0..=MAX_IPC_BYTES)) {
35 let msg = pack_bytes(&bytes);
36 let mut dst = [0u8; MAX_IPC_BYTES];
37 let count = unpack_bytes(&msg, &mut dst);
38 prop_assert_eq!(count, bytes.len());
39 prop_assert_eq!(&dst[..count], &bytes[..]);
40 }
41
42 #[test]
43 fn pack_clamps_oversized(bytes in proptest::collection::vec(any::<u8>(), 41..=128)) {
44 let msg = pack_bytes(&bytes);
45 prop_assert_eq!(msg[0], MAX_IPC_BYTES as u64);
46 let mut dst = [0u8; MAX_IPC_BYTES];
47 let count = unpack_bytes(&msg, &mut dst);
48 prop_assert_eq!(count, MAX_IPC_BYTES);
49 prop_assert_eq!(&dst[..], &bytes[..MAX_IPC_BYTES]);
50 }
51}