Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 6, 2024
1 parent 55a2968 commit 53ff944
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 68 deletions.
6 changes: 3 additions & 3 deletions crates/tests/interface/tests/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct PersistState {

impl ICustomPersist_Impl for Persist_Impl {
unsafe fn GetClassID(&self, clsid: *mut GUID) -> HRESULT {
*clsid = "117fb826-2155-483a-b50d-bc99a2c7cca3".into();
*clsid = "117fb826-2155-483a-b50d-bc99a2c7cca3".try_into().unwrap();
S_OK
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ fn test_custom_interface() -> windows::core::Result<()> {
let p: IPersistMemory = p.cast()?;
assert_eq!(
p.GetClassID()?,
"117fb826-2155-483a-b50d-bc99a2c7cca3".into()
"117fb826-2155-483a-b50d-bc99a2c7cca3".try_into()?,
);
assert_eq!(p.GetSizeMax()?, 10);
assert_eq!(p.IsDirty(), S_FALSE);
Expand Down Expand Up @@ -165,7 +165,7 @@ fn test_custom_interface() -> windows::core::Result<()> {
let p: ICustomPersist = p.cast()?;
let mut b = GUID::default();
p.GetClassID(&mut b).ok()?;
assert_eq!(b, "117fb826-2155-483a-b50d-bc99a2c7cca3".into());
assert_eq!(b, "117fb826-2155-483a-b50d-bc99a2c7cca3".try_into()?);

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/interface/tests/com_from_existing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Test;

impl IPersist_Impl for Test_Impl {
fn GetClassID(&self) -> Result<GUID> {
Ok("CEE1D356-0860-4262-90D4-C77423F0E352".into())
"CEE1D356-0860-4262-90D4-C77423F0E352".try_into()
}
}

Expand All @@ -30,7 +30,7 @@ fn test() -> Result<()> {
let p: IPersist = Test.into();
assert_eq!(
p.GetClassID()?,
"CEE1D356-0860-4262-90D4-C77423F0E352".into()
"CEE1D356-0860-4262-90D4-C77423F0E352".try_into()?
);

let m: ITestPersistMemory = p.cast()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/interface/tests/no_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Test;

impl windows::Win32::System::Com::IPersist_Impl for Test_Impl {
fn GetClassID(&self) -> windows::core::Result<windows::core::GUID> {
Ok("CEE1D356-0860-4262-90D4-C77423F0E352".into())
"CEE1D356-0860-4262-90D4-C77423F0E352".try_into()
}
}

Expand All @@ -28,7 +28,7 @@ fn test() -> windows::core::Result<()> {
let p: windows::Win32::System::Com::IPersist = Test.into();
assert_eq!(
p.GetClassID()?,
"CEE1D356-0860-4262-90D4-C77423F0E352".into()
"CEE1D356-0860-4262-90D4-C77423F0E352".try_into()?
);

let m: ITestPersistMemory = windows_core::Interface::cast(&p)?;
Expand Down
5 changes: 4 additions & 1 deletion crates/tests/structs/tests/propertykey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use windows::Win32::Devices::Properties::DEVPKEY_Device_BiosDeviceName;

#[test]
fn test_debug_impl() {
assert!(DEVPKEY_Device_BiosDeviceName.fmtid == "540B947E-8B40-45BC-A8A2-6A0B894CBDA2".into());
assert!(
DEVPKEY_Device_BiosDeviceName.fmtid
== "540B947E-8B40-45BC-A8A2-6A0B894CBDA2".try_into().unwrap()
);
assert!(DEVPKEY_Device_BiosDeviceName.pid == 10);
}
4 changes: 2 additions & 2 deletions crates/tests/win32/tests/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn constant() {
assert!(WM_KEYUP == 257u32);
assert!(D3D12_DEFAULT_BLEND_FACTOR_ALPHA == 1f32);
assert!(UIA_ScrollPatternNoScroll == -1f64);
assert!(CLSID_D2D1Shadow == GUID::from("C67EA361-1863-4e69-89DB-695D3E9A5B6B"));
assert!(CLSID_D2D1Shadow == GUID::try_from("C67EA361-1863-4e69-89DB-695D3E9A5B6B").unwrap());

let b: PCSTR = D3DCOMPILER_DLL_A;
let c: PCWSTR = D3DCOMPILER_DLL_W;
Expand Down Expand Up @@ -264,5 +264,5 @@ fn empty_struct() {
assert!(ldap.0 == 123);
assert!(core::mem::size_of::<PLDAPSearch>() == core::mem::size_of::<usize>());

assert!(UIAnimationManager == GUID::from("4C1FC63A-695C-47E8-A339-1A194BE3D0B8"));
assert!(UIAnimationManager == GUID::try_from("4C1FC63A-695C-47E8-A339-1A194BE3D0B8").unwrap());
}
4 changes: 2 additions & 2 deletions crates/tests/winrt/tests/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn non_generic() -> windows::core::Result<()> {

assert_eq!(
Handler::IID,
windows::core::GUID::from("A4ED5C81-76C9-40BD-8BE6-B1D90FB20AE7")
windows::core::GUID::try_from("A4ED5C81-76C9-40BD-8BE6-B1D90FB20AE7")?
);

let (tx, rx) = std::sync::mpsc::channel();
Expand All @@ -37,7 +37,7 @@ fn generic() -> windows::core::Result<()> {

assert_eq!(
Handler::IID,
windows::core::GUID::from("DAE18EA9-FCF3-5ACF-BCDD-8C354CBA6D23")
windows::core::GUID::try_from("DAE18EA9-FCF3-5ACF-BCDD-8C354CBA6D23")?
);

let uri = Uri::CreateUri(&windows::core::HSTRING::from("http://kennykerr.ca"))?;
Expand Down
81 changes: 42 additions & 39 deletions crates/tests/winrt/tests/generic_guids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,62 @@ fn generic_guids() {
//
assert_eq!(
IAsyncActionWithProgress::<A>::IID,
GUID::from("DD725452-2DA3-5103-9C7D-22EE9BB14AD3")
GUID::try_from("DD725452-2DA3-5103-9C7D-22EE9BB14AD3").unwrap()
);

assert_eq!(
IAsyncOperationWithProgress::<A, B>::IID,
GUID::from("94645425-B9E5-5B91-B509-8DA4DF6A8916")
GUID::try_from("94645425-B9E5-5B91-B509-8DA4DF6A8916").unwrap()
);

assert_eq!(
IAsyncOperation::<A>::IID,
GUID::from("2BD35EE6-72D9-5C5D-9827-05EBB81487AB")
GUID::try_from("2BD35EE6-72D9-5C5D-9827-05EBB81487AB").unwrap()
);

assert_eq!(
IReferenceArray::<A>::IID,
GUID::from("4A33FE03-E8B9-5346-A124-5449913ECA57")
GUID::try_from("4A33FE03-E8B9-5346-A124-5449913ECA57").unwrap()
);

assert_eq!(
IReference::<A>::IID,
GUID::from("F9E4006C-6E8C-56DF-811C-61F9990EBFB0")
GUID::try_from("F9E4006C-6E8C-56DF-811C-61F9990EBFB0").unwrap()
);

assert_eq!(
AsyncActionProgressHandler::<A>::IID,
GUID::from("C261D8D0-71BA-5F38-A239-872342253A18")
GUID::try_from("C261D8D0-71BA-5F38-A239-872342253A18").unwrap()
);

assert_eq!(
AsyncActionWithProgressCompletedHandler::<A>::IID,
GUID::from("9A0D211C-0374-5D23-9E15-EAA3570FAE63")
GUID::try_from("9A0D211C-0374-5D23-9E15-EAA3570FAE63").unwrap()
);

assert_eq!(
AsyncOperationCompletedHandler::<A>::IID,
GUID::from("9D534225-231F-55E7-A6D0-6C938E2D9160")
GUID::try_from("9D534225-231F-55E7-A6D0-6C938E2D9160").unwrap()
);

assert_eq!(
AsyncOperationProgressHandler::<A, B>::IID,
GUID::from("264F1E0C-ABE4-590B-9D37-E1CC118ECC75")
GUID::try_from("264F1E0C-ABE4-590B-9D37-E1CC118ECC75").unwrap()
);

assert_eq!(
AsyncOperationWithProgressCompletedHandler::<A, B>::IID,
GUID::from("C2D078D8-AC47-55AB-83E8-123B2BE5BC5A")
GUID::try_from("C2D078D8-AC47-55AB-83E8-123B2BE5BC5A").unwrap()
);

assert_eq!(
EventHandler::<A>::IID,
GUID::from("FA0B7D80-7EFA-52DF-9B69-0574CE57ADA4")
GUID::try_from("FA0B7D80-7EFA-52DF-9B69-0574CE57ADA4").unwrap()
);

assert_eq!(
TypedEventHandler::<A, B>::IID,
GUID::from("EDB31843-B4CF-56EB-925A-D4D0CE97A08D")
GUID::try_from("EDB31843-B4CF-56EB-925A-D4D0CE97A08D").unwrap()
);

//
Expand All @@ -87,62 +87,62 @@ fn generic_guids() {

assert_eq!(
IIterable::<A>::IID,
GUID::from("96565EB9-A692-59C8-BCB5-647CDE4E6C4D")
GUID::try_from("96565EB9-A692-59C8-BCB5-647CDE4E6C4D").unwrap()
);

assert_eq!(
IIterator::<A>::IID,
GUID::from("3C9B1E27-8357-590B-8828-6E917F172390")
GUID::try_from("3C9B1E27-8357-590B-8828-6E917F172390").unwrap()
);

assert_eq!(
IKeyValuePair::<A, B>::IID,
GUID::from("89336CD9-8B66-50A7-9759-EB88CCB2E1FE")
GUID::try_from("89336CD9-8B66-50A7-9759-EB88CCB2E1FE").unwrap()
);

assert_eq!(
IMapChangedEventArgs::<A>::IID,
GUID::from("E1AA5138-12BD-51A1-8558-698DFD070ABE")
GUID::try_from("E1AA5138-12BD-51A1-8558-698DFD070ABE").unwrap()
);

assert_eq!(
IMapView::<A, B>::IID,
GUID::from("B78F0653-FA89-59CF-BA95-726938AAE666")
GUID::try_from("B78F0653-FA89-59CF-BA95-726938AAE666").unwrap()
);

assert_eq!(
IMap::<A, B>::IID,
GUID::from("9962CD50-09D5-5C46-B1E1-3C679C1C8FAE")
GUID::try_from("9962CD50-09D5-5C46-B1E1-3C679C1C8FAE").unwrap()
);

assert_eq!(
IObservableMap::<A, B>::IID,
GUID::from("75F99E2A-137E-537E-A5B1-0B5A6245FC02")
GUID::try_from("75F99E2A-137E-537E-A5B1-0B5A6245FC02").unwrap()
);

assert_eq!(
IObservableVector::<A>::IID,
GUID::from("D24C289F-2341-5128-AAA1-292DD0DC1950")
GUID::try_from("D24C289F-2341-5128-AAA1-292DD0DC1950").unwrap()
);

assert_eq!(
IVectorView::<A>::IID,
GUID::from("5F07498B-8E14-556E-9D2E-2E98D5615DA9")
GUID::try_from("5F07498B-8E14-556E-9D2E-2E98D5615DA9").unwrap()
);

assert_eq!(
IVector::<A>::IID,
GUID::from("0E3F106F-A266-50A1-8043-C90FCF3844F6")
GUID::try_from("0E3F106F-A266-50A1-8043-C90FCF3844F6").unwrap()
);

assert_eq!(
MapChangedEventHandler::<A, B>::IID,
GUID::from("19046F0B-CF81-5DEC-BBB2-7CC250DA8B8B")
GUID::try_from("19046F0B-CF81-5DEC-BBB2-7CC250DA8B8B").unwrap()
);

assert_eq!(
VectorChangedEventHandler::<A>::IID,
GUID::from("A1E9ACD7-E4DF-5A79-AEFA-DE07934AB0FB")
GUID::try_from("A1E9ACD7-E4DF-5A79-AEFA-DE07934AB0FB").unwrap()
);

//
Expand All @@ -151,67 +151,67 @@ fn generic_guids() {

assert_eq!(
IReference::<bool>::IID,
GUID::from("3C00FD60-2950-5939-A21A-2D12C5A01B8A")
GUID::try_from("3C00FD60-2950-5939-A21A-2D12C5A01B8A").unwrap()
);

assert_eq!(
IReference::<i8>::IID,
GUID::from("95500129-FBF6-5AFC-89DF-70642D741990")
GUID::try_from("95500129-FBF6-5AFC-89DF-70642D741990").unwrap()
);

assert_eq!(
IReference::<i16>::IID,
GUID::from("6EC9E41B-6709-5647-9918-A1270110FC4E")
GUID::try_from("6EC9E41B-6709-5647-9918-A1270110FC4E").unwrap()
);

assert_eq!(
IReference::<i32>::IID,
GUID::from("548CEFBD-BC8A-5FA0-8DF2-957440FC8BF4")
GUID::try_from("548CEFBD-BC8A-5FA0-8DF2-957440FC8BF4").unwrap()
);

assert_eq!(
IReference::<i64>::IID,
GUID::from("4DDA9E24-E69F-5C6A-A0A6-93427365AF2A")
GUID::try_from("4DDA9E24-E69F-5C6A-A0A6-93427365AF2A").unwrap()
);

assert_eq!(
IReference::<u8>::IID,
GUID::from("e5198cc8-2873-55f5-b0a1-84ff9e4aad62")
GUID::try_from("e5198cc8-2873-55f5-b0a1-84ff9e4aad62").unwrap()
);

assert_eq!(
IReference::<u16>::IID,
GUID::from("5AB7D2C3-6B62-5E71-A4B6-2D49C4F238FD")
GUID::try_from("5AB7D2C3-6B62-5E71-A4B6-2D49C4F238FD").unwrap()
);

assert_eq!(
IReference::<u32>::IID,
GUID::from("513ef3af-e784-5325-a91e-97c2b8111cf3")
GUID::try_from("513ef3af-e784-5325-a91e-97c2b8111cf3").unwrap()
);

assert_eq!(
IReference::<u64>::IID,
GUID::from("6755e376-53bb-568b-a11d-17239868309e")
GUID::try_from("6755e376-53bb-568b-a11d-17239868309e").unwrap()
);

assert_eq!(
IReference::<f32>::IID,
GUID::from("719CC2BA-3E76-5DEF-9F1A-38D85A145EA8")
GUID::try_from("719CC2BA-3E76-5DEF-9F1A-38D85A145EA8").unwrap()
);

assert_eq!(
IReference::<f64>::IID,
GUID::from("2F2D6C29-5473-5F3E-92E7-96572BB990E2")
GUID::try_from("2F2D6C29-5473-5F3E-92E7-96572BB990E2").unwrap()
);

assert_eq!(
IReference::<GUID>::IID,
GUID::from("7D50F649-632C-51F9-849A-EE49428933EA")
GUID::try_from("7D50F649-632C-51F9-849A-EE49428933EA").unwrap()
);

assert_eq!(
IReference::<HSTRING>::IID,
GUID::from("FD416DFB-2A07-52EB-AAE3-DFCE14116C05")
GUID::try_from("FD416DFB-2A07-52EB-AAE3-DFCE14116C05").unwrap()
);

// TODO: structs and enums
Expand All @@ -234,7 +234,10 @@ fn generic_class_guid() {
);
}

assert_eq!(Uri::IID, GUID::from("9E365E57-48B2-4160-956F-C7385120BBFC"));
assert_eq!(
Uri::IID,
GUID::try_from("9E365E57-48B2-4160-956F-C7385120BBFC").unwrap()
);

// Then the generic case...

Expand All @@ -246,6 +249,6 @@ fn generic_class_guid() {

assert_eq!(
DeviceInformationCollection::IID,
GUID::from("E170688F-3495-5BF6-AAB5-9CAC17E0F10F")
GUID::try_from("E170688F-3495-5BF6-AAB5-9CAC17E0F10F").unwrap()
);
}
15 changes: 0 additions & 15 deletions crates/tests/winrt/tests/guid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use windows::core::GUID;
use windows::Foundation::GuidHelper;

#[test]
Expand All @@ -11,17 +10,3 @@ fn guid_helper() -> windows::core::Result<()> {

Ok(())
}

#[test]
fn guid_from_string() {
let a = GUID::from("CFF52E04-CCA6-4614-A17E-754910C84A99");

let b = GUID::from_values(
0xCFF52E04,
0xCCA6,
0x4614,
[0xA1, 0x7E, 0x75, 0x49, 0x10, 0xC8, 0x4A, 0x99],
);

assert!(a == b);
}
2 changes: 1 addition & 1 deletion crates/tests/winrt/tests/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use windows::Foundation::IStringable;
fn interface() -> windows::core::Result<()> {
assert_eq!(
IStringable::IID,
windows::core::GUID::from("96369F54-8EB6-48F0-ABCE-C1B211E627C3")
windows::core::GUID::try_from("96369F54-8EB6-48F0-ABCE-C1B211E627C3")?
);

// TODO: Find an example where the default constructor is not exclusive.
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/winrt/tests/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn uri() -> windows::core::Result<()> {

assert_eq!(
Uri::IID,
windows::core::GUID::from("9E365E57-48B2-4160-956F-C7385120BBFC") // IUriRuntimeClass
windows::core::GUID::try_from("9E365E57-48B2-4160-956F-C7385120BBFC")? // IUriRuntimeClass
);

let uri = &Uri::CreateUri(&windows::core::HSTRING::from("http://kennykerr.ca"))?;
Expand Down

0 comments on commit 53ff944

Please sign in to comment.