use std::sync::Mutex;
pub fn config_get_string(group: Option<&str>, key: &str) -> Option<String> {
crate::configstore::ConfigStore::instance()
.get(group, key)
.ok()
.filter(|s| !s.is_empty())
}
pub fn config_get_int(group: Option<&str>, key: &str, default: i32) -> i32 {
crate::configstore::ConfigStore::instance().get_int(group, key, default)
}
pub fn configuration_location() -> String {
crate::filefunctions::FileFunctions::new()
.get_configuration_location()
.unwrap_or_default()
}
pub static ENV_TEST_LOCK: Mutex<()> = Mutex::new(());
pub fn default_disk_cache_path() -> String {
crate::filefunctions::default_disk_cache_path()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn config_missing_key_falls_back() {
assert_eq!(config_get_int(None, "GraphicsBackend", 7), 7);
assert_eq!(config_get_string(None, "missing"), None);
}
#[test]
fn configuration_location_uses_env_override() {
let _guard = ENV_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = std::env::temp_dir().join("quercusrender-config-test");
std::env::set_var("QUERCUS_CONFIG_DIR", &dir);
let loc = configuration_location();
assert_eq!(loc, dir.to_string_lossy());
std::env::remove_var("QUERCUS_CONFIG_DIR");
}
#[test]
fn default_disk_cache_path_is_under_config() {
let _guard = ENV_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = std::env::temp_dir().join("quercusrender-cache-test");
std::env::set_var("QUERCUS_CONFIG_DIR", &dir);
let p = default_disk_cache_path();
assert!(p.ends_with("/mediacache") || p.ends_with("\\mediacache"));
std::env::remove_var("QUERCUS_CONFIG_DIR");
}
}