Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions crates/tests/riddle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,43 @@ mod nested_module;
mod nested_struct;
mod params;
mod r#struct;
mod win32_struct;
mod winrt_struct;

use std::process::Command;

pub fn run_riddle(name: &str) -> Vec<windows_metadata::File> {
let rd = format!("tests/{name}.rd");
pub fn run_riddle(name: &str, dialect: &str, etc: &[&str]) -> Vec<windows_metadata::File> {
let rdl = format!("tests/{name}.rdl");
let winmd = format!("tests/{name}.winmd");
let rs = format!("src/{name}.rs");

let before = std::fs::read_to_string(&rd).expect("Failed to read input");
let before = std::fs::read_to_string(&rdl).expect("Failed to read input");

// Convert .rd to .winmd
// Convert .rdl to .winmd
let mut command = Command::new("cargo");
command.args([
"run", "-p", "riddle", "--", "--in", &rd, "--out", &winmd, "--filter", "Test",
"run", "-p", "riddle", "--", "--in", &rdl, "--out", &winmd, "--filter", "Test",
]);
assert!(command.status().unwrap().success());

// Convert .winmd back to .rd
// Convert .winmd back to .rdl
let mut command = Command::new("cargo");
command.args([
"run", "-p", "riddle", "--", "--in", &winmd, "--out", &rd, "--filter", "Test",
"run", "-p", "riddle", "--", "--in", &winmd, "--out", &rdl, "--filter", "Test", "--config",
]);
command.arg(format!("TYPE={dialect}"));
assert!(command.status().unwrap().success());

// Check that .rd is unchanged
let after = std::fs::read_to_string(&rd).expect("Failed to read output");
assert_eq!(before, after);
// Check that .rdl is unchanged
let after = std::fs::read_to_string(&rdl).expect("Failed to read output");
assert_eq!(before, after, "no equal {}", rdl);

// Convert .rd to .rs
// Convert .rdl to .rs
let mut command = Command::new("cargo");
command.args([
"run", "-p", "riddle", "--", "--in", &rd, "--out", &rs, "--filter", "Test", "--config",
"FLATTEN",
"run", "-p", "riddle", "--", "--in", &rdl, "--out", &rs, "--filter", "Test",
]);
command.args(etc);
assert!(command.status().unwrap().success());

// Return winmd file for validation
Expand Down
41 changes: 41 additions & 0 deletions crates/tests/riddle/src/module_attributes.rs
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
// Bindings generated by `riddle` 0.0.1

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
#[repr(C)]
pub struct Type {
pub field: i32,
}
impl ::core::marker::Copy for Type {}
impl ::core::clone::Clone for Type {
fn clone(&self) -> Self {
*self
}
}
impl ::core::fmt::Debug for Type {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Type").field("field", &self.field).finish()
}
}
impl ::windows_core::TypeKind for Type {
type TypeKind = ::windows_core::CopyType;
}
impl ::windows_core::RuntimeType for Type {
const SIGNATURE: ::windows_core::imp::ConstBuffer =
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.Type;i4)");
}
impl ::core::cmp::PartialEq for Type {
fn eq(&self, other: &Self) -> bool {
self.field == other.field
}
}
impl ::core::cmp::Eq for Type {}
impl ::core::default::Default for Type {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
}
}
64 changes: 34 additions & 30 deletions crates/tests/riddle/src/nested_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,43 @@
dead_code,
clippy::all
)]
#[repr(C)]
pub struct NestedType {
pub field: f32,
}
impl ::core::marker::Copy for NestedType {}
impl ::core::clone::Clone for NestedType {
fn clone(&self) -> Self {
*self
pub mod NestedModule {
#[repr(C)]
pub struct NestedType {
pub field: f32,
}
}
impl ::core::fmt::Debug for NestedType {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("NestedType")
.field("field", &self.field)
.finish()
impl ::core::marker::Copy for NestedType {}
impl ::core::clone::Clone for NestedType {
fn clone(&self) -> Self {
*self
}
}
}
impl ::windows_core::TypeKind for NestedType {
type TypeKind = ::windows_core::CopyType;
}
impl ::windows_core::RuntimeType for NestedType {
const SIGNATURE: ::windows_core::imp::ConstBuffer =
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.NestedModule.NestedType;f4)");
}
impl ::core::cmp::PartialEq for NestedType {
fn eq(&self, other: &Self) -> bool {
self.field == other.field
impl ::core::fmt::Debug for NestedType {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("NestedType")
.field("field", &self.field)
.finish()
}
}
}
impl ::core::cmp::Eq for NestedType {}
impl ::core::default::Default for NestedType {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
impl ::windows_core::TypeKind for NestedType {
type TypeKind = ::windows_core::CopyType;
}
impl ::windows_core::RuntimeType for NestedType {
const SIGNATURE: ::windows_core::imp::ConstBuffer =
::windows_core::imp::ConstBuffer::from_slice(
b"struct(Test.NestedModule.NestedType;f4)",
);
}
impl ::core::cmp::PartialEq for NestedType {
fn eq(&self, other: &Self) -> bool {
self.field == other.field
}
}
impl ::core::cmp::Eq for NestedType {}
impl ::core::default::Default for NestedType {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
}
}
}
#[repr(C)]
Expand Down
38 changes: 38 additions & 0 deletions crates/tests/riddle/src/win32_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Bindings generated by `riddle` 0.0.1

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
#[repr(C)]
pub struct Type {
pub field: i32,
}
impl ::core::marker::Copy for Type {}
impl ::core::clone::Clone for Type {
fn clone(&self) -> Self {
*self
}
}
impl ::core::fmt::Debug for Type {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Type").field("field", &self.field).finish()
}
}
impl ::windows_core::TypeKind for Type {
type TypeKind = ::windows_core::CopyType;
}
impl ::core::cmp::PartialEq for Type {
fn eq(&self, other: &Self) -> bool {
self.field == other.field
}
}
impl ::core::cmp::Eq for Type {}
impl ::core::default::Default for Type {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
}
}
42 changes: 42 additions & 0 deletions crates/tests/riddle/src/winrt_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Bindings generated by `riddle` 0.0.1

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
#[repr(C)]
pub struct Type {
pub field: i32,
}
impl ::core::marker::Copy for Type {}
impl ::core::clone::Clone for Type {
fn clone(&self) -> Self {
*self
}
}
impl ::core::fmt::Debug for Type {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Type").field("field", &self.field).finish()
}
}
impl ::windows_core::TypeKind for Type {
type TypeKind = ::windows_core::CopyType;
}
impl ::windows_core::RuntimeType for Type {
const SIGNATURE: ::windows_core::imp::ConstBuffer =
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.Type;i4)");
}
impl ::core::cmp::PartialEq for Type {
fn eq(&self, other: &Self) -> bool {
self.field == other.field
}
}
impl ::core::cmp::Eq for Type {}
impl ::core::default::Default for Type {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
}
}
10 changes: 0 additions & 10 deletions crates/tests/riddle/tests/module_attributes.rd

This file was deleted.

7 changes: 7 additions & 0 deletions crates/tests/riddle/tests/module_attributes.rdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![winrt]

mod Test {
struct Type {
field: i32,
}
}
7 changes: 7 additions & 0 deletions crates/tests/riddle/tests/module_attributes.rs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
use test_riddle::run_riddle;
use windows_metadata::*;

#[test]
fn test() {
let files = run_riddle("module_attributes", "winrt", &[]);
let _reader = &Reader::new(&files);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![winrt]

mod Test {
mod NestedModule {
struct NestedType {
Expand All @@ -7,4 +9,4 @@ mod Test {
struct TestType {
field: i32,
}
}
}
2 changes: 1 addition & 1 deletion crates/tests/riddle/tests/nested_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use windows_metadata::*;

#[test]
fn test() {
let files = run_riddle("nested_module");
let files = run_riddle("nested_module", "winrt", &[]);
let reader = &Reader::new(&files);

let types: Vec<Item> = reader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![winrt]

mod Test {
struct Inner {
field_i32: i32,
Expand All @@ -7,4 +9,4 @@ mod Test {
field_inner: Inner,
field_usize: usize,
}
}
}
2 changes: 1 addition & 1 deletion crates/tests/riddle/tests/nested_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use windows_metadata::*;

#[test]
fn test() {
let files = run_riddle("nested_struct");
let files = run_riddle("nested_struct", "winrt", &[]);
let reader = &Reader::new(&files);

let def = reader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![winrt]

mod Test {
interface IParams {
fn Nothing();
Expand All @@ -15,4 +17,4 @@ mod Test {
fn ISize(a: isize, b: isize) -> isize;
fn USize(a: usize, b: usize) -> usize;
}
}
}
2 changes: 1 addition & 1 deletion crates/tests/riddle/tests/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use windows_metadata::*;

#[test]
fn test() {
let files = run_riddle("params");
let files = run_riddle("params", "winrt", &[]);
let reader = &Reader::new(&files);

let def = reader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![winrt]

mod Test {
struct Primitives {
field_bool: bool,
Expand All @@ -14,4 +16,4 @@ mod Test {
field_isize: isize,
field_usize: usize,
}
}
}
2 changes: 1 addition & 1 deletion crates/tests/riddle/tests/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use windows_metadata::*;

#[test]
fn test() {
let files = run_riddle("struct");
let files = run_riddle("struct", "winrt", &[]);
let reader = &Reader::new(&files);

let def = reader
Expand Down
7 changes: 7 additions & 0 deletions crates/tests/riddle/tests/win32_struct.rdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![win32]

mod Test {
struct Type {
field: i32,
}
}
Loading