// SPDX-License-Identifier: MIT //! Shared fixtures (the reference's tests/conftest.py): ROMs and BIOS images are read in //! place, and a test that needs one is skipped (it returns early, saying why) when the //! variable is unset or the file is absent, so the default suite runs anywhere. #![allow(dead_code)] use std::io::Read; use std::path::PathBuf; use a7800::machine::{NTSC, PAL}; use a7800::romsets::{DUMPS_2600, LICENSED_7800}; use a7800::system::find_bios; pub fn nointro() -> Option { match std::env::var("NO_INTRO_DIR") { Ok(v) if !v.is_empty() => Some(PathBuf::from(v)), _ => { eprintln!("skipped: NO_INTRO_DIR is not set: export it as the folder that holds the No-Intro sets"); None } } } fn read(path: PathBuf) -> Option> { if !path.exists() { eprintln!("skipped: not on this machine: {}", path.display()); return None; } let mut zip = zip::ZipArchive::new(std::fs::File::open(path).ok()?).ok()?; let mut entry = zip.by_index(0).ok()?; let mut data = Vec::new(); entry.read_to_end(&mut data).ok()?; Some(data) } pub fn licensed(name: &str) -> Option> { read(nointro()?.join(LICENSED_7800).join(name)) } pub fn licensed_path(name: &str) -> Option { let path = nointro()?.join(LICENSED_7800).join(name); path.exists().then_some(path) } pub fn a2600(name: &str) -> Option> { read(nointro()?.join(DUMPS_2600).join(name)) } pub fn ntsc_bios() -> Option> { let bios = find_bios(&NTSC); if bios.is_none() { eprintln!("skipped: no NTSC BIOS image found by hash below $MAME_ROMPATH (set it?)"); } bios } pub fn pal_bios() -> Option> { let bios = find_bios(&PAL); if bios.is_none() { eprintln!("skipped: no PAL BIOS image found by hash below $MAME_ROMPATH (set it?)"); } bios }