aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usbh/src/usbproto.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/usbh/src/usbproto.rs b/usbh/src/usbproto.rs
index 36edaad..33bc28c 100644
--- a/usbh/src/usbproto.rs
+++ b/usbh/src/usbproto.rs
@@ -313,7 +313,6 @@ impl Default for DescriptorType {
#[cfg(test)]
mod test {
- use super::super::pipe::DataBuf;
use super::*;
#[test]
@@ -339,7 +338,7 @@ mod test {
0xa1, 0xa2, 1,
];
- serde_test(desc, &want);
+ serde_test(&desc, &want);
}
#[test]
@@ -356,7 +355,7 @@ mod test {
};
let want = [0x12, 0x02, 0x20, 0x00, 0x05, 0x0a, 0x01, 0x40, 0xfa];
- serde_test(desc, &want);
+ serde_test(&desc, &want);
}
#[test]
@@ -374,7 +373,7 @@ mod test {
};
let want = [0x12, 0x04, 0x02, 0xaa, 0x05, 0x11, 0x22, 0x33, 0x0a];
- serde_test(desc, &want);
+ serde_test(&desc, &want);
}
#[test]
@@ -389,7 +388,7 @@ mod test {
};
let want = [0x12, 0x05, 0x01, 0x22, 0xad, 0xde, 0x33];
- serde_test(desc, &want);
+ serde_test(&desc, &want);
}
#[test]
@@ -403,27 +402,37 @@ mod test {
};
let want = [0x80, 0x06, 0x00, 0x01, 0xef, 0xbe, 0x012, 0x00];
- serde_test(setup_packet, &want);
+ serde_test(&setup_packet, &want);
}
- fn serde_test<T>(mut native: T, raw: &[u8])
+ fn serde_test<T>(native: &T, raw: &[u8])
where
T: Default + PartialEq + core::fmt::Debug,
{
- let db = DataBuf::from(&mut native);
- assert_eq!(db.len, raw.len());
+ ser_test(native, raw);
+ de_test(raw, native);
+ }
- // Serialization.
- let got_raw = unsafe { core::slice::from_raw_parts(db.ptr, db.len) };
+ fn ser_test<T>(native: &T, raw: &[u8]) {
+ let ptr = native as *const T as *const u8;
+ let len = core::mem::size_of::<T>();
+ assert_eq!(len, raw.len());
+ let got_raw = unsafe { core::slice::from_raw_parts(ptr, len) };
assert_eq!(got_raw, raw);
+ }
- // Deserialization.
+ fn de_test<T>(raw: &[u8], native: &T)
+ where
+ T: Default + PartialEq + core::fmt::Debug,
+ {
let mut got_native: T = Default::default();
- let db = DataBuf::from(&mut got_native);
- let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) };
- for i in 0..db.len {
+ let ptr = &mut got_native as *mut T as *mut u8;
+ let len = core::mem::size_of::<T>();
+ assert_eq!(raw.len(), len);
+ let dbslice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
+ for i in 0..len {
dbslice[i] = raw[i];
}
- assert_eq!(got_native, native);
+ assert_eq!(got_native, *native);
}
}