mirror of
https://github.com/Feliix42/ssd1675.git
synced 2024-11-24 03:36:30 +00:00
Fix up graphics tests
This commit is contained in:
parent
a95bb3d01b
commit
b6d8d7aabb
1 changed files with 45 additions and 61 deletions
106
src/graphics.rs
106
src/graphics.rs
|
@ -163,12 +163,11 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use self::embedded_graphics::coord::Coord;
|
use self::embedded_graphics::coord::Coord;
|
||||||
use self::embedded_graphics::fonts::{Font12x16, Font6x8};
|
|
||||||
use self::embedded_graphics::prelude::*;
|
use self::embedded_graphics::prelude::*;
|
||||||
use self::embedded_graphics::primitives::{Circle, Line, Rect};
|
use self::embedded_graphics::primitives::Rect;
|
||||||
use self::embedded_graphics::Drawing;
|
use self::embedded_graphics::Drawing;
|
||||||
use super::*;
|
use super::*;
|
||||||
use {Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation};
|
use {Builder, Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation};
|
||||||
|
|
||||||
const ROWS: u16 = 3;
|
const ROWS: u16 = 3;
|
||||||
const COLS: u8 = 8;
|
const COLS: u8 = 8;
|
||||||
|
@ -186,49 +185,42 @@ mod tests {
|
||||||
impl DisplayInterface for MockInterface {
|
impl DisplayInterface for MockInterface {
|
||||||
type Error = MockError;
|
type Error = MockError;
|
||||||
|
|
||||||
fn reset<D: hal::blocking::delay::DelayMs<u8>>(&mut self, _delay: &mut D) {
|
fn reset<D: hal::blocking::delay::DelayMs<u8>>(&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> {
|
fn send_command(&mut self, _command: u8) -> Result<(), Self::Error> {
|
||||||
// self.dc.set_low();
|
|
||||||
// self.write(&[command])?;
|
|
||||||
// self.dc.set_high();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_data(&mut self, _data: &[u8]) -> Result<(), Self::Error> {
|
fn send_data(&mut self, _data: &[u8]) -> Result<(), Self::Error> {
|
||||||
// self.dc.set_high();
|
|
||||||
// self.write(data)
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn busy_wait(&self) {
|
fn busy_wait(&self) {}
|
||||||
// while self.busy.is_high() {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn setup_display<'a>() -> GraphicDisplay<'a, MockInterface> {
|
fn build_mock_display<'a>() -> Display<'a, MockInterface> {
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn clear_white() {
|
|
||||||
let interface = MockInterface::new();
|
let interface = MockInterface::new();
|
||||||
let dimensions = Dimensions {
|
let dimensions = Dimensions {
|
||||||
rows: ROWS,
|
rows: ROWS,
|
||||||
cols: COLS,
|
cols: COLS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let config = Builder::new()
|
||||||
|
.dimensions(dimensions)
|
||||||
|
.rotation(Rotation::Rotate270)
|
||||||
|
.build()
|
||||||
|
.expect("invalid config");
|
||||||
|
Display::new(interface, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn clear_white() {
|
||||||
let mut black_buffer = [0u8; BUFFER_SIZE];
|
let mut black_buffer = [0u8; BUFFER_SIZE];
|
||||||
let mut red_buffer = [0u8; BUFFER_SIZE];
|
let mut red_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
{
|
{
|
||||||
let display = Display::new(interface, dimensions, Rotation::Rotate270);
|
let mut display =
|
||||||
let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
display.clear(Color::White);
|
display.clear(Color::White);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,18 +230,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn clear_black() {
|
fn clear_black() {
|
||||||
let interface = MockInterface::new();
|
|
||||||
let dimensions = Dimensions {
|
|
||||||
rows: ROWS,
|
|
||||||
cols: COLS,
|
|
||||||
};
|
|
||||||
let mut black_buffer = [0u8; BUFFER_SIZE];
|
let mut black_buffer = [0u8; BUFFER_SIZE];
|
||||||
let mut red_buffer = [0u8; BUFFER_SIZE];
|
let mut red_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
{
|
{
|
||||||
let display = Display::new(interface, dimensions, Rotation::Rotate270);
|
let mut display =
|
||||||
let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
display.clear(Color::Black);
|
display.clear(Color::Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,18 +245,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn clear_red() {
|
fn clear_red() {
|
||||||
let interface = MockInterface::new();
|
|
||||||
let dimensions = Dimensions {
|
|
||||||
rows: ROWS,
|
|
||||||
cols: COLS,
|
|
||||||
};
|
|
||||||
let mut black_buffer = [0u8; BUFFER_SIZE];
|
let mut black_buffer = [0u8; BUFFER_SIZE];
|
||||||
let mut red_buffer = [0u8; BUFFER_SIZE];
|
let mut red_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
{
|
{
|
||||||
let display = Display::new(interface, dimensions, Rotation::Rotate270);
|
let mut display =
|
||||||
let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
display.clear(Color::Red);
|
display.clear(Color::Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,17 +260,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn draw_rect_white() {
|
fn draw_rect_white() {
|
||||||
let interface = MockInterface::new();
|
|
||||||
let dimensions = Dimensions {
|
|
||||||
rows: ROWS,
|
|
||||||
cols: COLS,
|
|
||||||
};
|
|
||||||
let mut black_buffer = [0u8; BUFFER_SIZE];
|
let mut black_buffer = [0u8; BUFFER_SIZE];
|
||||||
let mut red_buffer = [0u8; BUFFER_SIZE];
|
let mut red_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
{
|
{
|
||||||
let display = Display::new(interface, dimensions, Rotation::Rotate0);
|
let mut display =
|
||||||
let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
display.draw(
|
display.draw(
|
||||||
Rect::new(Coord::new(0, 0), Coord::new(2, 2))
|
Rect::new(Coord::new(0, 0), Coord::new(2, 2))
|
||||||
|
@ -299,32 +274,41 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(black_buffer, [0b11100000, 0b10100000, 0b11100000]);
|
#[rustfmt::skip]
|
||||||
assert_eq!(red_buffer, [0b00000000, 0b00000000, 0b00000000]);
|
assert_eq!(black_buffer, [0b11100000,
|
||||||
|
0b10100000,
|
||||||
|
0b11100000]);
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
assert_eq!(red_buffer, [0b00000000,
|
||||||
|
0b00000000,
|
||||||
|
0b00000000]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn draw_rect_red() {
|
fn draw_rect_red() {
|
||||||
let interface = MockInterface::new();
|
|
||||||
let dimensions = Dimensions {
|
|
||||||
rows: ROWS,
|
|
||||||
cols: COLS,
|
|
||||||
};
|
|
||||||
let mut black_buffer = [0u8; BUFFER_SIZE];
|
let mut black_buffer = [0u8; BUFFER_SIZE];
|
||||||
let mut red_buffer = [0u8; BUFFER_SIZE];
|
let mut red_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
{
|
{
|
||||||
let display = Display::new(interface, dimensions, Rotation::Rotate0);
|
let mut display =
|
||||||
let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
display.draw(
|
display.draw(
|
||||||
Rect::new(Coord::new(1, 0), Coord::new(3, 2))
|
Rect::new(Coord::new(0, 0), Coord::new(2, 2))
|
||||||
.with_stroke(Some(Color::Red))
|
.with_stroke(Some(Color::Red))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(black_buffer, [0b01110000, 0b01010000, 0b01110000]);
|
#[rustfmt::skip]
|
||||||
assert_eq!(red_buffer, [0b01110000, 0b01010000, 0b01110000]);
|
assert_eq!(black_buffer, [0b11100000,
|
||||||
|
0b10100000,
|
||||||
|
0b11100000]);
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
assert_eq!(red_buffer, [0b11100000,
|
||||||
|
0b10100000,
|
||||||
|
0b11100000]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue