From dceaeaab3d88e3365ea19bbf50942523d3410255 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 4 Dec 2024 07:17:18 -0600 Subject: [PATCH] tests for struct references --- crates/libs/bindgen/src/type_map.rs | 4 +++ crates/tests/bindgen/Cargo.toml | 3 ++ crates/tests/bindgen/src/lib.rs | 6 ++++ .../bindgen/src/reference_struct_filter.rs | 35 +++++++++++++++++++ .../reference_struct_reference_namespace.rs | 22 ++++++++++++ .../src/reference_struct_reference_type.rs | 22 ++++++++++++ .../src/reference_struct_sys_filter.rs | 16 +++++++++ ...eference_struct_sys_reference_namespace.rs | 14 ++++++++ .../reference_struct_sys_reference_type.rs | 15 ++++++++ crates/tools/bindgen/src/main.rs | 9 +++++ 10 files changed, 146 insertions(+) create mode 100644 crates/tests/bindgen/src/reference_struct_filter.rs create mode 100644 crates/tests/bindgen/src/reference_struct_reference_namespace.rs create mode 100644 crates/tests/bindgen/src/reference_struct_reference_type.rs create mode 100644 crates/tests/bindgen/src/reference_struct_sys_filter.rs create mode 100644 crates/tests/bindgen/src/reference_struct_sys_reference_namespace.rs create mode 100644 crates/tests/bindgen/src/reference_struct_sys_reference_type.rs diff --git a/crates/libs/bindgen/src/type_map.rs b/crates/libs/bindgen/src/type_map.rs index e1cb9f359e..5e89a752b8 100644 --- a/crates/libs/bindgen/src/type_map.rs +++ b/crates/libs/bindgen/src/type_map.rs @@ -33,6 +33,10 @@ impl TypeMap { continue; } + for ty in types { + dependencies.insert(ty.clone()); + } + dependencies.combine_references(&item_dependencies, references); } } diff --git a/crates/tests/bindgen/Cargo.toml b/crates/tests/bindgen/Cargo.toml index 84ebeb212e..cc428c14a4 100644 --- a/crates/tests/bindgen/Cargo.toml +++ b/crates/tests/bindgen/Cargo.toml @@ -22,6 +22,9 @@ features = [ [dependencies.windows-sys] workspace = true +features = [ + "Win32_Gaming", +] [dependencies.windows-core] workspace = true diff --git a/crates/tests/bindgen/src/lib.rs b/crates/tests/bindgen/src/lib.rs index 109047fa3d..82e001b990 100644 --- a/crates/tests/bindgen/src/lib.rs +++ b/crates/tests/bindgen/src/lib.rs @@ -70,6 +70,12 @@ pub mod reference_dependency_skip_root; pub mod reference_dependent_flat; pub mod reference_dependent_full; pub mod reference_dependent_skip_root; +pub mod reference_struct_filter; +pub mod reference_struct_reference_namespace; +pub mod reference_struct_reference_type; +pub mod reference_struct_sys_filter; +pub mod reference_struct_sys_reference_namespace; +pub mod reference_struct_sys_reference_type; pub mod sort; pub mod struct_cpp_sys; pub mod struct_cpp_win; diff --git a/crates/tests/bindgen/src/reference_struct_filter.rs b/crates/tests/bindgen/src/reference_struct_filter.rs new file mode 100644 index 0000000000..f17ca5f44b --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_filter.rs @@ -0,0 +1,35 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct InkTrailPoint { + pub Point: Point, + pub Radius: f32, +} +impl windows_core::TypeKind for InkTrailPoint { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for InkTrailPoint { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice( + b"struct(Windows.UI.Composition.InkTrailPoint;struct(Windows.Foundation.Point;f4;f4);f4)", + ); +} +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct Point { + pub X: f32, + pub Y: f32, +} +impl windows_core::TypeKind for Point { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for Point { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::from_slice(b"struct(Windows.Foundation.Point;f4;f4)"); +} diff --git a/crates/tests/bindgen/src/reference_struct_reference_namespace.rs b/crates/tests/bindgen/src/reference_struct_reference_namespace.rs new file mode 100644 index 0000000000..69d3bca2d0 --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_reference_namespace.rs @@ -0,0 +1,22 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct InkTrailPoint { + pub Point: windows::Foundation::Point, + pub Radius: f32, +} +impl windows_core::TypeKind for InkTrailPoint { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for InkTrailPoint { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice( + b"struct(Windows.UI.Composition.InkTrailPoint;struct(Windows.Foundation.Point;f4;f4);f4)", + ); +} diff --git a/crates/tests/bindgen/src/reference_struct_reference_type.rs b/crates/tests/bindgen/src/reference_struct_reference_type.rs new file mode 100644 index 0000000000..69d3bca2d0 --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_reference_type.rs @@ -0,0 +1,22 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct InkTrailPoint { + pub Point: windows::Foundation::Point, + pub Radius: f32, +} +impl windows_core::TypeKind for InkTrailPoint { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for InkTrailPoint { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice( + b"struct(Windows.UI.Composition.InkTrailPoint;struct(Windows.Foundation.Point;f4;f4);f4)", + ); +} diff --git a/crates/tests/bindgen/src/reference_struct_sys_filter.rs b/crates/tests/bindgen/src/reference_struct_sys_filter.rs new file mode 100644 index 0000000000..ce7e1c4ea1 --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_sys_filter.rs @@ -0,0 +1,16 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +pub type GAMING_DEVICE_DEVICE_ID = i32; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct GAMING_DEVICE_MODEL_INFORMATION { + pub vendorId: GAMING_DEVICE_VENDOR_ID, + pub deviceId: GAMING_DEVICE_DEVICE_ID, +} +pub type GAMING_DEVICE_VENDOR_ID = i32; diff --git a/crates/tests/bindgen/src/reference_struct_sys_reference_namespace.rs b/crates/tests/bindgen/src/reference_struct_sys_reference_namespace.rs new file mode 100644 index 0000000000..8301455dbb --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_sys_reference_namespace.rs @@ -0,0 +1,14 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct GAMING_DEVICE_MODEL_INFORMATION { + pub vendorId: windows_sys::Win32::Gaming::GAMING_DEVICE_VENDOR_ID, + pub deviceId: windows_sys::Win32::Gaming::GAMING_DEVICE_DEVICE_ID, +} diff --git a/crates/tests/bindgen/src/reference_struct_sys_reference_type.rs b/crates/tests/bindgen/src/reference_struct_sys_reference_type.rs new file mode 100644 index 0000000000..727a5346c3 --- /dev/null +++ b/crates/tests/bindgen/src/reference_struct_sys_reference_type.rs @@ -0,0 +1,15 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +pub type GAMING_DEVICE_DEVICE_ID = i32; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct GAMING_DEVICE_MODEL_INFORMATION { + pub vendorId: windows_sys::Win32::Gaming::GAMING_DEVICE_VENDOR_ID, + pub deviceId: GAMING_DEVICE_DEVICE_ID, +} diff --git a/crates/tools/bindgen/src/main.rs b/crates/tools/bindgen/src/main.rs index 38be60948b..e5adda9f7f 100644 --- a/crates/tools/bindgen/src/main.rs +++ b/crates/tools/bindgen/src/main.rs @@ -128,6 +128,15 @@ fn main() { test("--out reference_async_action.rs --filter IAsyncAction"); test("--out reference_async_action_reference.rs --filter IAsyncAction --reference windows,skip-root,IAsyncInfo"); + // Tests for struct references + test("--out reference_struct_filter.rs --filter InkTrailPoint"); + test("--out reference_struct_reference_type.rs --filter InkTrailPoint --reference windows,skip-root,Point"); + test("--out reference_struct_reference_namespace.rs --filter InkTrailPoint --reference windows,skip-root,Windows.Foundation"); + test("--out reference_struct_sys_filter.rs --sys --filter GAMING_DEVICE_MODEL_INFORMATION"); + test("--out reference_struct_sys_reference_type.rs --sys --filter GAMING_DEVICE_MODEL_INFORMATION --reference windows_sys,skip-root,GAMING_DEVICE_VENDOR_ID"); + test("--out reference_struct_sys_reference_namespace.rs --sys --filter GAMING_DEVICE_MODEL_INFORMATION --reference windows_sys,skip-root,Windows.Win32.Gaming"); + + // Tests simulating reference dependency and dependent test_raw( "--no-comment --out reference_dependency_flat.rs --filter IMemoryBufferReference --flat", );