From c4fd42d5dc65c7029dd4d2b569b2037697ec4cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Tue, 6 Jun 2023 14:58:56 +0100 Subject: [PATCH] chore: add more unit tests --- src/dma.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/dma.rs b/src/dma.rs index 8414356d..13f45208 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -1,6 +1,6 @@ use crate::warnln; -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum DmaMode { General = 0x00, HBlank = 0x01, @@ -116,3 +116,39 @@ impl Default for Dma { Self::new() } } + +#[cfg(test)] +mod tests { + use crate::dma::{Dma, DmaMode}; + + #[test] + fn test_dma_default() { + let dma = Dma::default(); + assert_eq!(dma.active, false); + } + + #[test] + fn test_dma_reset() { + let mut dma = Dma::new(); + dma.source = 0x1234; + dma.destination = 0x5678; + dma.length = 0x9abc; + dma.mode = DmaMode::HBlank; + dma.active = true; + + dma.reset(); + + assert_eq!(dma.source, 0x0); + assert_eq!(dma.destination, 0x0); + assert_eq!(dma.length, 0x0); + assert_eq!(dma.mode, DmaMode::General); + assert_eq!(dma.active, false); + } + + #[test] + fn test_dma_set_active() { + let mut dma = Dma::new(); + dma.set_active(true); + assert_eq!(dma.active, true); + } +} \ No newline at end of file -- GitLab