test_runner/
console.rs

1use std::process::Termination;
2
3use ctru::prelude::*;
4use ctru::services::gfx::{Flush, Swap};
5
6use super::TestRunner;
7
8/// Run tests using the [`ctru::console::Console`] (print results to the 3DS screen).
9/// This is mostly useful for running tests manually, especially on real hardware.
10pub struct ConsoleRunner {
11    gfx: Gfx,
12    hid: Hid,
13    apt: Apt,
14}
15
16impl TestRunner for ConsoleRunner {
17    type Context<'this> = Console<'this>;
18
19    fn new() -> Self {
20        let gfx = Gfx::new().unwrap();
21        let hid = Hid::new().unwrap();
22        let apt = Apt::new().unwrap();
23
24        gfx.top_screen.borrow_mut().set_wide_mode(true);
25
26        Self { gfx, hid, apt }
27    }
28
29    fn setup(&mut self) -> Self::Context<'_> {
30        Console::new(self.gfx.top_screen.borrow_mut())
31    }
32
33    fn cleanup<T: Termination>(mut self, result: T) -> T {
34        // We don't actually care about the output of the test result, either
35        // way we'll stop and show the results to the user.
36
37        println!("Press START to exit.");
38
39        while self.apt.main_loop() {
40            let mut screen = self.gfx.top_screen.borrow_mut();
41            screen.flush_buffers();
42            screen.swap_buffers();
43
44            self.gfx.wait_for_vblank();
45
46            self.hid.scan_input();
47            if self.hid.keys_down().contains(KeyPad::START) {
48                break;
49            }
50        }
51
52        result
53    }
54}