Skip to content

Commit

Permalink
tests for struct references
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 4, 2024
1 parent 8115db5 commit dceaeaa
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/libs/bindgen/src/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl TypeMap {
continue;
}

for ty in types {
dependencies.insert(ty.clone());
}

dependencies.combine_references(&item_dependencies, references);
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ features = [

[dependencies.windows-sys]
workspace = true
features = [
"Win32_Gaming",
]

[dependencies.windows-core]
workspace = true
6 changes: 6 additions & 0 deletions crates/tests/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions crates/tests/bindgen/src/reference_struct_filter.rs
Original file line number Diff line number Diff line change
@@ -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)");
}
22 changes: 22 additions & 0 deletions crates/tests/bindgen/src/reference_struct_reference_namespace.rs
Original file line number Diff line number Diff line change
@@ -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)",
);
}
22 changes: 22 additions & 0 deletions crates/tests/bindgen/src/reference_struct_reference_type.rs
Original file line number Diff line number Diff line change
@@ -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)",
);
}
16 changes: 16 additions & 0 deletions crates/tests/bindgen/src/reference_struct_sys_filter.rs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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,
}
15 changes: 15 additions & 0 deletions crates/tests/bindgen/src/reference_struct_sys_reference_type.rs
Original file line number Diff line number Diff line change
@@ -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,
}
9 changes: 9 additions & 0 deletions crates/tools/bindgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand Down

0 comments on commit dceaeaa

Please sign in to comment.