181 lines
7.1 KiB
Rust
181 lines
7.1 KiB
Rust
// SPDX-License-Identifier: CPAL-1.0
|
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
|
|
|
//! Steam: valid fixtures and the hostile ones that are Steam-specific.
|
|
|
|
use arena_core::{CoverHint, Launch, ParseError, Source, WinPath, steam};
|
|
|
|
fn lib() -> WinPath {
|
|
WinPath::parse(r"D:\SteamLibrary").unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_current_layout() {
|
|
let dirs = steam::library_folders(include_bytes!("fixtures/steam/libraryfolders.vdf")).unwrap();
|
|
let dirs: Vec<&str> = dirs.iter().map(WinPath::as_str).collect();
|
|
assert_eq!(dirs, [r"C:\Program Files (x86)\Steam", r"D:\SteamLibrary"]);
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_old_layout() {
|
|
let dirs = steam::library_folders(include_bytes!("fixtures/steam/libraryfolders_old.vdf")).unwrap();
|
|
let dirs: Vec<&str> = dirs.iter().map(WinPath::as_str).collect();
|
|
assert_eq!(dirs, [r"D:\SteamLibrary", r"E:\Games\Steam"]);
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_empty_root_is_empty_list() {
|
|
assert_eq!(steam::library_folders(b"\"libraryfolders\"\n{\n}\n").unwrap(), Vec::<WinPath>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_needs_the_root_key() {
|
|
assert_eq!(steam::library_folders(b"\"other\" { }"), Err(ParseError::Missing("libraryfolders")));
|
|
assert_eq!(steam::library_folders(b"\"libraryfolders\" \"x\""), Err(ParseError::WrongType("libraryfolders")));
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_refuses_path_object() {
|
|
let r = steam::library_folders(include_bytes!("fixtures/steam/libraryfolders_wrongtype.vdf"));
|
|
assert_eq!(r, Err(ParseError::WrongType("path")));
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_refuses_missing_path() {
|
|
let r = steam::library_folders(b"\"libraryfolders\" { \"0\" { \"label\" \"\" } }");
|
|
assert_eq!(r, Err(ParseError::Missing("path")));
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_refuses_unc() {
|
|
let r = steam::library_folders(include_bytes!("fixtures/steam/libraryfolders_unc.vdf"));
|
|
assert_eq!(r, Err(ParseError::BadPath("path")));
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_refuses_the_same_folder_twice() {
|
|
let r = steam::library_folders(include_bytes!("fixtures/steam/libraryfolders_dup.vdf"));
|
|
assert_eq!(r, Err(ParseError::Duplicate("path")));
|
|
}
|
|
|
|
#[test]
|
|
fn library_folders_caps_the_count() {
|
|
let mut s = String::from("\"libraryfolders\"\n{\n");
|
|
for i in 0..=arena_core::limits::MAX_LIBRARIES {
|
|
s.push_str(&format!("\"{i}\" {{ \"path\" \"D:\\\\Lib{i}\" }}\n"));
|
|
}
|
|
s.push_str("}\n");
|
|
assert_eq!(steam::library_folders(s.as_bytes()), Err(ParseError::TooMany("libraries")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_valid() {
|
|
let g = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_1234560.acf"), &lib()).unwrap();
|
|
assert_eq!(g.id.as_str(), "steam:1234560");
|
|
assert_eq!(g.source, Source::Steam);
|
|
assert_eq!(g.title, "Example Quest: The \"Quoted\" Edition");
|
|
assert_eq!(g.install_dir.as_ref().map(WinPath::as_str), Some(r"D:\SteamLibrary\steamapps\common\Example Quest"));
|
|
assert_eq!(g.launch, Launch::SteamRunGameId(1_234_560));
|
|
assert_eq!(g.launch.uri().as_deref(), Some("steam://rungameid/1234560"));
|
|
assert_eq!(g.cover, Some(CoverHint::SteamLibraryCache { app_id: 1_234_560 }));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_redistributable_is_not_a_game() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_228980.acf"), &lib());
|
|
assert!(matches!(r, Err(ParseError::NotAGame(_))), "{r:?}");
|
|
assert!(steam::is_tool(228_980));
|
|
assert!(!steam::is_tool(1_234_560));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_traversal_in_installdir() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_traversal.acf"), &lib());
|
|
assert_eq!(r, Err(ParseError::BadPath("installdir")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_absolute_installdir() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_absolute.acf"), &lib());
|
|
assert_eq!(r, Err(ParseError::BadPath("installdir")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_appid_object() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_wrongtype.acf"), &lib());
|
|
assert_eq!(r, Err(ParseError::WrongType("appid")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_duplicate_keys_ignoring_case() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_dupkey.acf"), &lib());
|
|
assert_eq!(r, Err(ParseError::Duplicate("key")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_absurd_appid() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_absurd.acf"), &lib());
|
|
assert_eq!(r, Err(ParseError::BadId));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_line_break_in_string() {
|
|
let r = steam::app_manifest(include_bytes!("fixtures/steam/appmanifest_unterminated.acf"), &lib());
|
|
assert!(matches!(r, Err(ParseError::Syntax { .. })), "{r:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_appid_rules() {
|
|
for bad in ["0", "-1", "+5", "01", " 5", "5 ", "4294967296", "1e3", "0x10", ""] {
|
|
let acf = format!("\"AppState\" {{ \"appid\" \"{bad}\" \"name\" \"N\" \"installdir\" \"N\" }}");
|
|
assert_eq!(steam::app_manifest(acf.as_bytes(), &lib()), Err(ParseError::BadId), "appid {bad:?}");
|
|
}
|
|
let acf = "\"AppState\" { \"appid\" \"4294967295\" \"name\" \"N\" \"installdir\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(acf.as_bytes(), &lib()).unwrap().launch, Launch::SteamRunGameId(u32::MAX));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_missing_fields() {
|
|
let no_name = "\"AppState\" { \"appid\" \"10\" \"installdir\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(no_name.as_bytes(), &lib()), Err(ParseError::Missing("name")));
|
|
let no_dir = "\"AppState\" { \"appid\" \"10\" \"name\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(no_dir.as_bytes(), &lib()), Err(ParseError::Missing("installdir")));
|
|
let no_id = "\"AppState\" { \"name\" \"N\" \"installdir\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(no_id.as_bytes(), &lib()), Err(ParseError::Missing("appid")));
|
|
assert_eq!(steam::app_manifest(b"\"Other\" { }", &lib()), Err(ParseError::Missing("AppState")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_blank_or_control_title() {
|
|
let blank = "\"AppState\" { \"appid\" \"10\" \"name\" \" \" \"installdir\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(blank.as_bytes(), &lib()), Err(ParseError::Missing("name")));
|
|
let ctl = "\"AppState\" { \"appid\" \"10\" \"name\" \"a\\tb\" \"installdir\" \"N\" }";
|
|
assert_eq!(steam::app_manifest(ctl.as_bytes(), &lib()), Err(ParseError::BadValue("name")));
|
|
}
|
|
|
|
#[test]
|
|
fn app_manifest_refuses_device_name_installdir() {
|
|
for bad in ["CON", "nul", "COM1", "lpt9.txt", "a/b", r"a\\b", ".", "..", "x:", "dots.", ""] {
|
|
let acf = format!("\"AppState\" {{ \"appid\" \"10\" \"name\" \"N\" \"installdir\" \"{bad}\" }}");
|
|
assert_eq!(steam::app_manifest(acf.as_bytes(), &lib()), Err(ParseError::BadPath("installdir")), "{bad:?}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn manifest_names() {
|
|
assert_eq!(steam::app_id_from_manifest_name("appmanifest_1234560.acf"), Some(1_234_560));
|
|
for bad in [
|
|
"appmanifest_0.acf",
|
|
"appmanifest_01.acf",
|
|
"appmanifest_.acf",
|
|
"appmanifest_12.acf.bak",
|
|
"APPMANIFEST_12.ACF",
|
|
"appmanifest_99999999999.acf",
|
|
"appmanifest_-1.acf",
|
|
"libraryfolders.vdf",
|
|
"appmanifest_1 2.acf",
|
|
] {
|
|
assert_eq!(steam::app_id_from_manifest_name(bad), None, "{bad}");
|
|
}
|
|
}
|