From bcf4c44c39aa37e27d7204949c2a26bd5a5eb7eb Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 25 Jul 2019 14:55:46 -0400 Subject: Add deserialize tests for usbproto as well. --- usbh/src/usbproto.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'usbh') diff --git a/usbh/src/usbproto.rs b/usbh/src/usbproto.rs index 97d1839..4fd97b0 100644 --- a/usbh/src/usbproto.rs +++ b/usbh/src/usbproto.rs @@ -371,6 +371,14 @@ mod test { ]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; assert_eq!(got, want); + + let mut desc2: USBDeviceDescriptor = Default::default(); + let db = DataBuf::from(&mut desc2); + let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) }; + for i in 0..db.len { + dbslice[i] = want[i]; + } + assert_eq!(desc2, desc); } #[test] @@ -390,6 +398,14 @@ mod test { let want = [0x12, 0x02, 0x20, 0x00, 0x05, 0x0a, 0x01, 0x40, 0xfa]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; assert_eq!(got, want); + + let mut desc2: USBConfigurationDescriptor = Default::default(); + let db = DataBuf::from(&mut desc2); + let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) }; + for i in 0..db.len { + dbslice[i] = want[i]; + } + assert_eq!(desc2, desc); } #[test] @@ -410,6 +426,14 @@ mod test { let want = [0x12, 0x04, 0x02, 0xaa, 0x05, 0x11, 0x22, 0x33, 0x0a]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; assert_eq!(got, want); + + let mut desc2: USBInterfaceDescriptor = Default::default(); + let db = DataBuf::from(&mut desc2); + let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) }; + for i in 0..db.len { + dbslice[i] = want[i]; + } + assert_eq!(desc2, desc); } #[test] @@ -427,6 +451,14 @@ mod test { let want = [0x12, 0x05, 0x01, 0x22, 0xad, 0xde, 0x33]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; assert_eq!(got, want); + + let mut desc2: USBEndpointDescriptor = Default::default(); + let db = DataBuf::from(&mut desc2); + let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) }; + for i in 0..db.len { + dbslice[i] = want[i]; + } + assert_eq!(desc2, desc); } #[test] @@ -443,5 +475,13 @@ mod test { let want = [0x80, 0x06, 0x00, 0x01, 0xef, 0xbe, 0x012, 0x00]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; assert_eq!(got, want); + + let mut setup_packet2: USBSetupPacket = Default::default(); + let db = DataBuf::from(&mut setup_packet2); + let dbslice = unsafe { core::slice::from_raw_parts_mut(db.ptr, db.len) }; + for i in 0..db.len { + dbslice[i] = want[i]; + } + assert_eq!(setup_packet2, setup_packet); } } -- cgit v1.2.3