From 1a05a8cf305d3e1f94fea56e22fa240354a1c314 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Fri, 16 Nov 2018 21:09:15 +1100 Subject: [PATCH] Create the start of a test for GraphicDisplay --- src/graphics.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/graphics.rs b/src/graphics.rs index 135b24b..58895f9 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -107,3 +107,64 @@ where } } } + +#[cfg(test)] +mod tests { + use super::*; + use ::{Display, DisplayInterface, Dimensions, GraphicDisplay, Color, Rotation}; + + const ROWS: u16 = 212; + const COLS: u8 = 104; + const BUFFER_SIZE: usize = ROWS as usize * COLS as usize; + + struct MockInterface {} + struct MockError {} + + impl MockInterface { + fn new() -> Self { + MockInterface {} + } + } + + impl DisplayInterface for MockInterface { + type Error = MockError; + + fn reset>(&mut self, delay: &mut D) { + // self.reset.set_low(); + // delay.delay_ms(RESET_DELAY_MS); + // self.reset.set_high(); + // delay.delay_ms(RESET_DELAY_MS); + } + + fn send_command(&mut self, command: u8) -> Result<(), Self::Error> { + // self.dc.set_low(); + // self.write(&[command])?; + // self.dc.set_high(); + + Ok(()) + } + + fn send_data(&mut self, data: &[u8]) -> Result<(), Self::Error> { + // self.dc.set_high(); + // self.write(data) + Ok(()) + } + + fn busy_wait(&self) { + // while self.busy.is_high() {} + } + } + + // fn setup_display<'a>() -> GraphicDisplay<'a, MockInterface> { + // } + + #[test] + fn set_corner_pixels() { + let interface = MockInterface::new(); + let dimensions = Dimensions { rows: ROWS, cols: COLS }; + let mut black_buffer = [0u8; BUFFER_SIZE]; // FIXME: This is using 1 byte per pixel when it only needs to be one bit + let mut red_buffer = [0u8; BUFFER_SIZE]; + let display = Display::new(interface, dimensions, Rotation::Rotate270); + GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer); + } +}