From a15e01f2eb4138941f4e3942cc7fcb96b71cea16 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 25 Jan 2019 13:31:06 +0100 Subject: [PATCH] Construct a vga buffer for testing --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/vga_buffer.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 68584800..c7e78e5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,11 @@ +[[package]] +name = "array-init" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bit_field" version = "0.9.0" @@ -12,6 +20,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "blog_os" version = "0.1.0" dependencies = [ + "array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "bootloader 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -78,6 +87,11 @@ name = "libc" version = "0.2.48" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "nodrop" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "os_bootinfo" version = "0.2.1" @@ -220,6 +234,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3cc8456d0ae81a8c76f59e384683a601548c38949a4bfcb65dd31ded5c75ff3" "checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bootloader 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "2b498d7168288f3667f80aee93b4894e355dfce867803e1ccd5d9ee42a0b0e1a" @@ -230,6 +245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" "checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a" "checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07" "checksum rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dee497e66d8d76bf08ce20c8d36e16f93749ab0bf89975b4f8ae5cee660c2da2" diff --git a/Cargo.toml b/Cargo.toml index 61bae0ce..62915175 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" bootloader = "0.3.12" volatile = "0.2.3" spin = "0.4.9" +array-init = "0.0.3" [dependencies.lazy_static] version = "1.0" diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 265557d7..8c512c94 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -140,3 +140,34 @@ pub fn _print(args: fmt::Arguments) { use core::fmt::Write; WRITER.lock().write_fmt(args).unwrap(); } + +#[cfg(test)] +mod test { + use super::*; + + fn construct_writer() -> Writer { + use std::boxed::Box; + + let buffer = construct_buffer(); + Writer { + column_position: 0, + color_code: ColorCode::new(Color::Blue, Color::Magenta), + buffer: Box::leak(Box::new(buffer)), + } + } + + fn construct_buffer() -> Buffer { + use array_init::array_init; + + Buffer { + chars: array_init(|_| array_init(|_| Volatile::new(empty_char()))), + } + } + + fn empty_char() -> ScreenChar { + ScreenChar { + ascii_character: b' ', + color_code: ColorCode::new(Color::Green, Color::Brown), + } + } +}