Skip to content

Commit

Permalink
Use Starfield plugins in Starfield tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 25, 2024
1 parent b90540c commit a498c2d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/load_order/asterisk_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ mod tests {
write_active_plugins_file(load_order.game_settings(), &loaded_plugin_names);

copy_to_test_dir(
"Blank.esm",
"Blank.full.esm",
"BlueprintShips-Starfield.esm",
&load_order.game_settings(),
);
Expand Down
14 changes: 7 additions & 7 deletions src/load_order/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,12 @@ mod tests {
let plugin_path = load_order
.game_settings
.plugins_directory()
.join("Blank - Different.esp");
.join("Blank.full.esm");
set_file_timestamps(&plugin_path, timestamp);
let plugin_path = load_order
.game_settings
.plugins_directory()
.join("Blank.esp");
.join("Blank.medium.esm");
set_file_timestamps(&plugin_path, timestamp);

let result = find_plugins_in_dirs(
Expand All @@ -844,12 +844,12 @@ mod tests {
);

let plugin_names = [
load_order.game_settings.master_file(),
"Blank.esm",
"Blank - Different.esp",
"Blank.full.esm",
"Blank.medium.esm",
"Starfield.esm",
"Blank.esp",
"Blank - Master Dependent.esp",
"Blàñk.esp",
"Blank.small.esm",
"Blank - Override.esp",
];

assert_eq!(plugin_names.as_slice(), result);
Expand Down
66 changes: 34 additions & 32 deletions src/load_order/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,36 +113,48 @@ pub fn set_timestamp_order(plugin_names: &[&str], parent_path: &Path) {
pub fn mock_game_files(game_id: GameId, game_dir: &Path) -> (GameSettings, Vec<Plugin>) {
let mut settings = game_settings_for_test(game_id, game_dir);

copy_to_test_dir("Blank.esm", settings.master_file(), &settings);
copy_to_test_dir("Blank.esm", "Blank.esm", &settings);
copy_to_test_dir("Blank.esp", "Blank.esp", &settings);
copy_to_test_dir("Blank - Different.esp", "Blank - Different.esp", &settings);
copy_to_test_dir(
"Blank - Master Dependent.esp",
"Blank - Master Dependent.esp",
&settings,
);
copy_to_test_dir("Blank.esp", "Blàñk.esp", &settings);

let plugin_names = [
settings.master_file(),
"Blank.esm",
"Blank.esp",
"Blank - Different.esp",
"Blank - Master Dependent.esp",
"Blàñk.esp",
];
set_timestamp_order(&plugin_names, &settings.plugins_directory());
if game_id == GameId::Starfield {
copy_to_test_dir("Blank.full.esm", settings.master_file(), &settings);
copy_to_test_dir("Blank.full.esm", "Blank.full.esm", &settings);
copy_to_test_dir("Blank.medium.esm", "Blank.medium.esm", &settings);
copy_to_test_dir("Blank.small.esm", "Blank.small.esm", &settings);
copy_to_test_dir("Blank.esp", "Blank.esp", &settings);
copy_to_test_dir("Blank - Override.esp", "Blank - Override.esp", &settings);
} else {
copy_to_test_dir("Blank.esm", settings.master_file(), &settings);
copy_to_test_dir("Blank.esm", "Blank.esm", &settings);
copy_to_test_dir("Blank.esp", "Blank.esp", &settings);
copy_to_test_dir("Blank - Different.esp", "Blank - Different.esp", &settings);
copy_to_test_dir(
"Blank - Master Dependent.esp",
"Blank - Master Dependent.esp",
&settings,
);
copy_to_test_dir("Blank.esp", "Blàñk.esp", &settings);

let plugin_names = [
settings.master_file(),
"Blank.esm",
"Blank.esp",
"Blank - Different.esp",
"Blank - Master Dependent.esp",
"Blàñk.esp",
];
set_timestamp_order(&plugin_names, &settings.plugins_directory());
}

// Refresh settings to account for newly-created plugin files.
settings.refresh_implicitly_active_plugins().unwrap();

let plugins = vec![
let mut plugins = vec![
Plugin::new(settings.master_file(), &settings).unwrap(),
Plugin::with_active("Blank.esp", &settings, true).unwrap(),
Plugin::new("Blank - Different.esp", &settings).unwrap(),
];

if game_id != GameId::Starfield {
plugins.push(Plugin::new("Blank - Different.esp", &settings).unwrap());
}

(settings, plugins)
}

Expand All @@ -162,16 +174,6 @@ pub fn set_master_flag(plugin: &Path, present: bool) -> io::Result<()> {
Ok(())
}

pub fn set_override_flag(plugin: &Path, present: bool) -> io::Result<()> {
let mut file = OpenOptions::new().write(true).open(plugin)?;
file.seek(io::SeekFrom::Start(9))?;

let value = if present { 2 } else { 0 };
file.write(&[value])?;

Ok(())
}

pub fn load_and_insert<T: MutableLoadOrder>(load_order: &mut T, plugin_name: &str) {
let plugin = Plugin::new(plugin_name, load_order.game_settings()).unwrap();

Expand Down
69 changes: 15 additions & 54 deletions src/load_order/writable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ mod tests {
use crate::game_settings::GameSettings;
use crate::load_order::mutable::{generic_insert_position, MutableLoadOrder};
use crate::load_order::readable::{ReadableLoadOrder, ReadableLoadOrderBase};
use crate::load_order::tests::{
load_and_insert, mock_game_files, set_master_flag, set_override_flag,
};
use crate::load_order::tests::{load_and_insert, mock_game_files, set_master_flag};
use crate::tests::copy_to_test_dir;

struct TestLoadOrder {
Expand Down Expand Up @@ -551,17 +549,7 @@ mod tests {
activate(&mut load_order, &plugin).unwrap();
}

let plugin = "override.esp";
copy_to_test_dir(
"Blank - Different Plugin Dependent.esp",
&plugin,
&load_order.game_settings(),
);
set_override_flag(
&load_order.game_settings().plugins_directory().join(plugin),
true,
)
.unwrap();
let plugin = "Blank - Override.esp";
load_and_insert(&mut load_order, &plugin);

assert!(!load_order.is_active(plugin));
Expand All @@ -575,30 +563,20 @@ mod tests {
let tmp_dir = tempdir().unwrap();
let mut load_order = prepare(GameId::Starfield, &tmp_dir.path());

for i in 0..(MAX_ACTIVE_NORMAL_PLUGINS - 2) {
for i in 0..(MAX_ACTIVE_NORMAL_PLUGINS - 1) {
let plugin = format!("{}.esp", i);
copy_to_test_dir("Blank.esp", &plugin, &load_order.game_settings());
copy_to_test_dir("Blank - Override.esp", &plugin, &load_order.game_settings());
load_and_insert(&mut load_order, &plugin);
activate(&mut load_order, &plugin).unwrap();
}

// Activate an override plugin as the 255th active plugin.
let plugin = "override.esp";
copy_to_test_dir(
"Blank - Different Plugin Dependent.esp",
&plugin,
&load_order.game_settings(),
);
set_override_flag(
&load_order.game_settings().plugins_directory().join(plugin),
true,
)
.unwrap();
let plugin = "Blank - Override.esp";
load_and_insert(&mut load_order, &plugin);
activate(&mut load_order, &plugin).unwrap();

assert!(activate(&mut load_order, "Blank - Different.esp").is_ok());
assert!(load_order.is_active("Blank - Different.esp"));
assert!(!load_order.is_active(plugin));

assert!(activate(&mut load_order, plugin).is_ok());
assert!(load_order.is_active(plugin));
}

#[test]
Expand Down Expand Up @@ -728,43 +706,26 @@ mod tests {
}

#[test]
fn set_active_plugins_should_not_count_existing_active_override_plugins_towards_limit() {
fn set_active_plugins_should_not_count_override_plugins_towards_limit() {
let tmp_dir = tempdir().unwrap();
let mut load_order = prepare(GameId::Starfield, &tmp_dir.path());

let mut active_plugins = vec!["Starfield.esm".to_string()];
let blank_override = "Blank - Override.esp";
load_and_insert(&mut load_order, blank_override);

let mut active_plugins = vec!["Starfield.esm".to_string(), blank_override.to_string()];

for i in 0..(MAX_ACTIVE_NORMAL_PLUGINS - 1) {
let plugin = format!("{}.esp", i);
copy_to_test_dir("Blank.esp", &plugin, &load_order.game_settings());
load_and_insert(&mut load_order, &plugin);
activate(&mut load_order, &plugin).unwrap();

active_plugins.push(plugin);
}

// Also activate a couple of override plugins.
for i in 0..2 {
let plugin = format!("{}.override.esp", i);
copy_to_test_dir(
"Blank - Different Plugin Dependent.esp",
&plugin,
&load_order.game_settings(),
);
set_override_flag(
&load_order.game_settings().plugins_directory().join(&plugin),
true,
)
.unwrap();
load_and_insert(&mut load_order, &plugin);
activate(&mut load_order, &plugin).unwrap();

active_plugins.push(plugin);
}

let active_plugins: Vec<&str> = active_plugins.iter().map(|s| s.as_str()).collect();

assert!(set_active_plugins(&mut load_order, &active_plugins).is_ok());
assert_eq!(257, load_order.active_plugin_names().len());
assert_eq!(256, load_order.active_plugin_names().len());
}
}
3 changes: 2 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn testing_plugins_dir(game_id: GameId) -> PathBuf {
let game_folder = match game_id {
Morrowind => "Morrowind",
Oblivion => "Oblivion",
Fallout4 | Fallout4VR | SkyrimSE | SkyrimVR | Starfield => "SkyrimSE",
Fallout4 | Fallout4VR | SkyrimSE | SkyrimVR => "SkyrimSE",
Starfield => "Starfield",
_ => "Skyrim",
};

Expand Down

0 comments on commit a498c2d

Please sign in to comment.