diff --git a/Cargo.toml b/Cargo.toml index c3cb937..99c5fcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ readme = ".github/README.md" exclude = [".github", ".metadata", "docs", "tests"] [workspace] -members = ["crates/samples/*", "crates/tests/*"] +members = ["crates/samples/*"] [dependencies.windows] version = "0.59" diff --git a/crates/tests/enumerators/Cargo.toml b/crates/tests/enumerators/Cargo.toml deleted file mode 100644 index 5f5312c..0000000 --- a/crates/tests/enumerators/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "test_enumerators" -version = "0.0.0" -edition = "2021" -publish = false - -[dependencies.windows-core] -version = "0.59" - -[dependencies.microsoft-dia] -path = "../../../" diff --git a/crates/tests/enumerators/src/lib.rs b/crates/tests/enumerators/src/lib.rs deleted file mode 100644 index 8b13789..0000000 --- a/crates/tests/enumerators/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/tests/enumerators/tests/tests.rs b/crates/tests/enumerators/tests/tests.rs deleted file mode 100644 index 571ae9c..0000000 --- a/crates/tests/enumerators/tests/tests.rs +++ /dev/null @@ -1,92 +0,0 @@ -use microsoft_dia::{nsfRegularExpression, DiaSource, IDiaDataSource, IDiaSession, SymTagNull}; -use windows_core::*; -const S_OK: HRESULT = HRESULT(0); - -fn get_test_session() -> Result { - unsafe { - let path = if cfg!(target_arch = "x86_64") { - s!( - r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll" - ) - } else if cfg!(target_arch = "aarch64") { - s!( - r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\arm64\msdia140.dll" - ) - } else if cfg!(target_arch = "x86") { - s!(r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\msdia140.dll") - } else { - panic!("Unsupported target architecture"); - }; - let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(path, &DiaSource)?; - let executable = std::env::current_exe().unwrap(); - source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?; - source.openSession() - } -} - -#[allow(dead_code)] -static TEST_VALUE_01: i32 = 1; -#[allow(dead_code)] -static TEST_VALUE_02: i32 = 2; -#[allow(dead_code)] -static TEST_VALUE_03: i32 = 3; - -#[test] -fn simple_enumeration() -> Result<()> { - unsafe { - let session = get_test_session()?; - let symbols = session.globalScope()?.findChildren( - SymTagNull, - w!("tests::TEST_VALUE_[0-9]+"), - nsfRegularExpression.0 as u32, - )?; - - let mut found = Vec::new(); - for i in 0..symbols.Count()? { - found.push(symbols.Item(i as u32)?.name()?); - } - assert_eq!( - found, - [ - "tests::TEST_VALUE_01", - "tests::TEST_VALUE_02", - "tests::TEST_VALUE_03", - ] - ); - - Ok(()) - } -} - -#[test] -fn batch_enumeration() -> Result<()> { - unsafe { - let session = get_test_session()?; - let symbols = session.globalScope()?.findChildren( - SymTagNull, - w!("tests::TEST_VALUE_[0-9]+"), - nsfRegularExpression.0 as u32, - )?; - - let mut found = Vec::new(); - let mut batch = [None, None]; - let mut fetched = 0; - while symbols.Next(&mut batch, &mut fetched) == S_OK { - found.extend( - batch[0..fetched as usize] - .iter() - .filter_map(|s| s.as_ref()?.name().ok()), - ); - } - assert_eq!( - found, - [ - "tests::TEST_VALUE_01", - "tests::TEST_VALUE_02", - "tests::TEST_VALUE_03", - ] - ); - - Ok(()) - } -} diff --git a/tests/basic/mod.rs b/tests/basic/mod.rs new file mode 100644 index 0000000..66ae915 --- /dev/null +++ b/tests/basic/mod.rs @@ -0,0 +1,28 @@ +use microsoft_dia::{NameSearchOptions, SymTagData}; +use windows_core::*; + +use crate::common::get_test_session; + +#[allow(dead_code)] +static TEST_DATA: u32 = 42; + +#[test] +fn symbol_properties() -> Result<()> { + unsafe { + let session = get_test_session()?; + let symbol = session + .globalScope()? + .findChildren( + SymTagData, + w!("main::basic::TEST_DATA"), + NameSearchOptions::default().0 as u32, + )? + .Item(0)?; + + assert_eq!(symbol.unalignedType()?, false); + assert_eq!(symbol.constType()?, false); + assert_eq!(symbol.volatileType()?, false); + + Ok(()) + } +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 0000000..95e92ba --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,24 @@ +use microsoft_dia::{DiaSource, IDiaDataSource, IDiaSession}; +use windows_core::*; + +pub fn get_test_session() -> Result { + unsafe { + let path = if cfg!(target_arch = "x86_64") { + s!( + r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll" + ) + } else if cfg!(target_arch = "aarch64") { + s!( + r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\arm64\msdia140.dll" + ) + } else if cfg!(target_arch = "x86") { + s!(r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\msdia140.dll") + } else { + panic!("Unsupported target architecture"); + }; + let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(path, &DiaSource)?; + let executable = std::env::current_exe().unwrap(); + source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?; + source.openSession() + } +} \ No newline at end of file diff --git a/tests/enumerators/mod.rs b/tests/enumerators/mod.rs new file mode 100644 index 0000000..5bd541b --- /dev/null +++ b/tests/enumerators/mod.rs @@ -0,0 +1,75 @@ +use crate::common::get_test_session; +use microsoft_dia::{nsfRegularExpression, SymTagNull}; +use windows::Win32::Foundation::S_OK; +use windows_core::*; + +#[allow(dead_code)] +static TEST_VALUE_01: i32 = 1; +#[allow(dead_code)] +static TEST_VALUE_02: i32 = 2; +#[allow(dead_code)] +static TEST_VALUE_03: i32 = 3; + +#[test] +fn simple_enumeration() -> Result<()> { + unsafe { + let session = get_test_session()?; + let symbols = session.globalScope()?.findChildren( + SymTagNull, + w!("main::enumerators::TEST_VALUE_[0-9]+"), + nsfRegularExpression.0 as u32, + )?; + + let mut found = Vec::new(); + for i in 0..symbols.Count()? { + found.push(symbols.Item(i as u32)?.name()?); + } + + found.sort_by(|a, b| a.cmp(b)); + assert_eq!( + found, + [ + "main::enumerators::TEST_VALUE_01", + "main::enumerators::TEST_VALUE_02", + "main::enumerators::TEST_VALUE_03", + ] + ); + + Ok(()) + } +} + +#[test] +fn batch_enumeration() -> Result<()> { + unsafe { + let session = get_test_session()?; + let symbols = session.globalScope()?.findChildren( + SymTagNull, + w!("main::enumerators::TEST_VALUE_[0-9]+"), + nsfRegularExpression.0 as u32, + )?; + + let mut found = Vec::new(); + let mut batch = [None, None]; + let mut fetched = 0; + while symbols.Next(&mut batch, &mut fetched) == S_OK { + found.extend( + batch[0..fetched as usize] + .iter() + .filter_map(|s| s.as_ref()?.name().ok()), + ); + } + + found.sort_by(|a, b| a.cmp(b)); + assert_eq!( + found, + [ + "main::enumerators::TEST_VALUE_01", + "main::enumerators::TEST_VALUE_02", + "main::enumerators::TEST_VALUE_03", + ] + ); + + Ok(()) + } +} diff --git a/tests/main.rs b/tests/main.rs new file mode 100644 index 0000000..7b050d0 --- /dev/null +++ b/tests/main.rs @@ -0,0 +1,4 @@ +mod common; + +mod basic; +mod enumerators;