aboutsummaryrefslogtreecommitdiffstats
path: root/usbh/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-07-25 14:55:46 -0400
committerBrian Cully <bjc@kublai.com>2019-07-25 14:55:46 -0400
commitbcf4c44c39aa37e27d7204949c2a26bd5a5eb7eb (patch)
treea361319be2c44dc2c5d54639bf61038bfcb33c2c /usbh/src
parentbc9bbc1607978e9a21e648c567e1a8a46d47d677 (diff)
downloadsamd21-demo-bcf4c44c39aa37e27d7204949c2a26bd5a5eb7eb.tar.gz
samd21-demo-bcf4c44c39aa37e27d7204949c2a26bd5a5eb7eb.zip
Add deserialize tests for usbproto as well.
Diffstat (limited to 'usbh/src')
-rw-r--r--usbh/src/usbproto.rs40
1 files changed, 40 insertions, 0 deletions
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);
}
}