diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 433e8c0..600080b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,21 +42,18 @@ jobs: 7z x 1.4.0.zip mv testing-plugins-1.4.0 testing-plugins - (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win32.7z', "$PWD/loot_api_win32.7z") - 7z x loot_api_win32.7z - mv loot_api-0.13.8-0-g47797cc_dev-win32 loot_api_win32 + (New-Object Net.WebClient).DownloadFile('https://github.com/loot/libloot/releases/download/0.18.2/libloot-0.18.2-0-gb1a9e31_0.18.2-win32.7z', "$PWD/libloot_win32.7z") + 7z x libloot_win32.7z + mv libloot-0.18.2-0-gb1a9e31_0.18.2-win32 libloot_win32 - (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win64.7z', "$PWD/loot_api_win64.7z") - 7z x loot_api_win64.7z - mv loot_api-0.13.8-0-g47797cc_dev-win64 loot_api_win64 + (New-Object Net.WebClient).DownloadFile('https://github.com/loot/libloot/releases/download/0.18.2/libloot-0.18.2-0-gb1a9e31_0.18.2-win64.7z', "$PWD/libloot_win64.7z") + 7z x libloot_win64.7z + mv libloot-0.18.2-0-gb1a9e31_0.18.2-win64 libloot_win64 (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api-python/releases/download/4.0.2/loot_api_python-4.0.2-0-gd356ac2_master-python2.7-win32.7z', "$PWD/loot_api_python.7z") 7z x loot_api_python.7z mv loot_api_python-4.0.2-0-gd356ac2_master-python2.7-win32 loot_api_python - (New-Object Net.WebClient).DownloadFile('https://7-zip.org/a/7z1805-extra.7z', "$PWD/7z.7z") - 7z x "$PWD/7z.7z" -o7z - cd .. - name: Build and run tests @@ -103,21 +100,18 @@ jobs: tar -xf 1.4.1.tar.gz mv testing-plugins-1.4.1 testing-plugins - wget https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win32.7z - 7z x loot_api-0.13.8-0-g47797cc_dev-win32.7z - mv loot_api-0.13.8-0-g47797cc_dev-win32 loot_api_win32 + wget https://github.com/loot/libloot/releases/download/0.18.2/libloot-0.18.2-0-gb1a9e31_0.18.2-win32.7z + 7z x libloot-0.18.2-0-gb1a9e31_0.18.2-win32.7z + mv libloot-0.18.2-0-gb1a9e31_0.18.2-win32 libloot_win32 - wget https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win64.7z - 7z x loot_api-0.13.8-0-g47797cc_dev-win64.7z - mv loot_api-0.13.8-0-g47797cc_dev-win64 loot_api_win64 + wget https://github.com/loot/libloot/releases/download/0.18.2/libloot-0.18.2-0-gb1a9e31_0.18.2-win64.7z + 7z x libloot-0.18.2-0-gb1a9e31_0.18.2-win64.7z + mv libloot-0.18.2-0-gb1a9e31_0.18.2-win64 libloot_win64 wget https://github.com/loot/loot-api-python/releases/download/4.0.2/loot_api_python-4.0.2-0-gd356ac2_master-python2.7-win32.7z 7z x loot_api_python-4.0.2-0-gd356ac2_master-python2.7-win32.7z mv loot_api_python-4.0.2-0-gd356ac2_master-python2.7-win32 loot_api_python - wget https://7-zip.org/a/7z1805-extra.7z - 7z x 7z1805-extra.7z -o7z - cd .. - name: Build and run tests with code coverage diff --git a/.gitignore b/.gitignore index e9a4d5c..0b210ee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,9 @@ /target/ **/*.rs.bk Cargo.lock -/tests/7z /tests/testing-plugins -/tests/loot_api* +/tests/libloot* +/tests/loot_api_python /ffi/include/ /ffi/build/ .vscode diff --git a/benches/eval.rs b/benches/eval.rs index bd052f5..fb9f064 100644 --- a/benches/eval.rs +++ b/benches/eval.rs @@ -124,10 +124,9 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() version(executable)", |b| { let state = State::new(GameType::Oblivion, ".".into(), ".".into()); - let expression = Expression::from_str( - "version(\"tests/loot_api_win32/loot_api.dll\", \"0.13.8.0\", ==)", - ) - .unwrap(); + let expression = + Expression::from_str("version(\"tests/libloot_win32/loot.dll\", \"0.18.2.0\", ==)") + .unwrap(); b.iter(|| { assert!(expression.eval(&state).unwrap()); diff --git a/src/function/eval.rs b/src/function/eval.rs index 4110265..bddda44 100644 --- a/src/function/eval.rs +++ b/src/function/eval.rs @@ -1204,20 +1204,23 @@ mod tests { #[test] fn function_version_eval_should_read_executable_file_version() { let function = Function::Version( - "loot_api.dll".into(), - "0.13.8.0".into(), + "loot.dll".into(), + "0.18.2.0".into(), ComparisonOperator::Equal, ); - let state = state("tests/loot_api_win32"); + let state = state("tests/libloot_win32"); assert!(function.eval(&state).unwrap()); } #[test] fn function_product_version_eval_should_read_executable_product_version() { - let function = - Function::ProductVersion("7za.exe".into(), "18.05".into(), ComparisonOperator::Equal); - let state = state("tests/7z"); + let function = Function::ProductVersion( + "loot.dll".into(), + "0.18.2".into(), + ComparisonOperator::Equal, + ); + let state = state("tests/libloot_win32"); assert!(function.eval(&state).unwrap()); } @@ -1234,11 +1237,11 @@ mod tests { #[test] fn get_product_version_should_return_ok_some_if_the_path_is_an_executable() { - let version = get_product_version(Path::new("tests/7z/7za.exe")) + let version = get_product_version(Path::new("tests/libloot_win32/loot.dll")) .unwrap() .unwrap(); - assert_eq!(Version::from("18.05"), version); + assert_eq!(Version::from("0.18.2"), version); } #[test] diff --git a/src/function/version.rs b/src/function/version.rs index 70755b5..db767ed 100644 --- a/src/function/version.rs +++ b/src/function/version.rs @@ -385,17 +385,16 @@ mod tests { #[test] fn version_read_file_version_should_read_the_file_version_field_of_a_32_bit_executable() { - let version = - Version::read_file_version(Path::new("tests/loot_api_win32/loot_api.dll")) - .unwrap() - .unwrap(); + let version = Version::read_file_version(Path::new("tests/libloot_win32/loot.dll")) + .unwrap() + .unwrap(); assert_eq!( version.release_ids, vec![ ReleaseId::Numeric(0), - ReleaseId::Numeric(13), - ReleaseId::Numeric(8), + ReleaseId::Numeric(18), + ReleaseId::Numeric(2), ReleaseId::Numeric(0), ] ); @@ -404,17 +403,16 @@ mod tests { #[test] fn version_read_file_version_should_read_the_file_version_field_of_a_64_bit_executable() { - let version = - Version::read_file_version(Path::new("tests/loot_api_win64/loot_api.dll")) - .unwrap() - .unwrap(); + let version = Version::read_file_version(Path::new("tests/libloot_win64/loot.dll")) + .unwrap() + .unwrap(); assert_eq!( version.release_ids, vec![ ReleaseId::Numeric(0), - ReleaseId::Numeric(13), - ReleaseId::Numeric(8), + ReleaseId::Numeric(18), + ReleaseId::Numeric(2), ReleaseId::Numeric(0), ] ); @@ -449,13 +447,17 @@ mod tests { #[test] fn version_read_product_version_should_read_the_file_version_field_of_a_32_bit_executable() { - let version = Version::read_product_version(Path::new("tests/7z/7za.exe")) + let version = Version::read_product_version(Path::new("tests/libloot_win32/loot.dll")) .unwrap() .unwrap(); assert_eq!( version.release_ids, - vec![ReleaseId::Numeric(18), ReleaseId::Numeric(5),] + vec![ + ReleaseId::Numeric(0), + ReleaseId::Numeric(18), + ReleaseId::Numeric(2) + ] ); assert!(version.pre_release_ids.is_empty()); } @@ -463,32 +465,43 @@ mod tests { #[test] fn version_read_product_version_should_read_the_file_version_field_of_a_64_bit_executable() { - let version = Version::read_product_version(Path::new("tests/7z/x64/7za.exe")) + let version = Version::read_product_version(Path::new("tests/libloot_win64/loot.dll")) .unwrap() .unwrap(); assert_eq!( version.release_ids, - vec![ReleaseId::Numeric(18), ReleaseId::Numeric(5),] + vec![ + ReleaseId::Numeric(0), + ReleaseId::Numeric(18), + ReleaseId::Numeric(2), + ] ); assert!(version.pre_release_ids.is_empty()); } #[test] - fn version_read_file_version_should_find_non_us_english_version_strings() { + fn version_read_product_version_should_find_non_us_english_version_strings() { let tmp_dir = tempfile::tempdir().unwrap(); - let dll_path = tmp_dir.path().join("7zxa.ru.dll"); + let dll_path = tmp_dir.path().join("loot.ru.dll"); + + let mut dll_bytes = std::fs::read("tests/libloot_win32/loot.dll").unwrap(); // Set the version info block's language code to 1049 (Russian). - let mut dll_bytes = std::fs::read("tests/7z/7zxa.dll").unwrap(); - dll_bytes[0x23B10] = 0x19; + dll_bytes[0x53204A] = b'1'; // This changes VersionInfo.strings.Language.lang_id + dll_bytes[0x53216C] = 0x19; // This changes VersionInfo.langs.Language.lang_id + std::fs::write(&dll_path, dll_bytes).unwrap(); let version = Version::read_product_version(&dll_path).unwrap().unwrap(); assert_eq!( version.release_ids, - vec![ReleaseId::Numeric(18), ReleaseId::Numeric(5)] + vec![ + ReleaseId::Numeric(0), + ReleaseId::Numeric(18), + ReleaseId::Numeric(2) + ] ); assert!(version.pre_release_ids.is_empty()); }