aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-08-09 12:24:09 -0400
committerBrian Cully <bjc@kublai.com>2019-08-09 12:24:09 -0400
commitb255613f3792ec6dc1c57876e59d95c33538b607 (patch)
treec390be01063ea4ba89ded7d1df45747abebc72c6
parent54e051b7dfbfde9083ce4becd80718ea642114fd (diff)
downloadusb-host-b255613f3792ec6dc1c57876e59d95c33538b607.tar.gz
usb-host-b255613f3792ec6dc1c57876e59d95c33538b607.zip
Add tests for USB descriptor layout.
-rw-r--r--.gitignore1
-rw-r--r--src/descriptor.rs28
-rw-r--r--[-rwxr-xr-x]src/lib.rs2
3 files changed, 31 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 1d8e8c5..c4448c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/target
*/target
**/*.rs.bk
Cargo.lock
diff --git a/src/descriptor.rs b/src/descriptor.rs
index 8461413..c0d3314 100644
--- a/src/descriptor.rs
+++ b/src/descriptor.rs
@@ -1,4 +1,5 @@
#[derive(Clone, Copy, Debug)]
+#[repr(u8)]
pub enum DescriptorType {
Device = 1,
Configuration = 2,
@@ -66,3 +67,30 @@ pub struct EndpointDescriptor {
pub w_max_packet_size: u16,
pub b_interval: u8,
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ use core::mem;
+
+ #[test]
+ fn device_descriptor_layout() {
+ assert_eq!(mem::size_of::<DeviceDescriptor>(), 18);
+ }
+
+ #[test]
+ fn configuration_descriptor_layout() {
+ assert_eq!(mem::size_of::<ConfigurationDescriptor>(), 9);
+ }
+
+ #[test]
+ fn interface_descriptor_layout() {
+ assert_eq!(mem::size_of::<InterfaceDescriptor>(), 9);
+ }
+
+ #[test]
+ fn endpoint_descriptor_layout() {
+ assert_eq!(mem::size_of::<EndpointDescriptor>(), 7);
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 551824a..742e02c 100755..100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,5 @@
+//! Traits for a hardware-agnostic USB host interface.
+
#![no_std]
mod descriptor;