From 53ff944e0282034ce647c2e5a23c17c1d323c469 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 6 Aug 2024 15:25:14 -0500 Subject: [PATCH] tests --- crates/tests/interface/tests/com.rs | 6 +- .../interface/tests/com_from_existing.rs | 4 +- crates/tests/interface/tests/no_use.rs | 4 +- crates/tests/structs/tests/propertykey.rs | 5 +- crates/tests/win32/tests/win32.rs | 4 +- crates/tests/winrt/tests/delegates.rs | 4 +- crates/tests/winrt/tests/generic_guids.rs | 81 ++++++++++--------- crates/tests/winrt/tests/guid.rs | 15 ---- crates/tests/winrt/tests/interface.rs | 2 +- crates/tests/winrt/tests/uri.rs | 2 +- 10 files changed, 59 insertions(+), 68 deletions(-) diff --git a/crates/tests/interface/tests/com.rs b/crates/tests/interface/tests/com.rs index 88d3aa2110..127979b569 100644 --- a/crates/tests/interface/tests/com.rs +++ b/crates/tests/interface/tests/com.rs @@ -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 } } @@ -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); @@ -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(()) } diff --git a/crates/tests/interface/tests/com_from_existing.rs b/crates/tests/interface/tests/com_from_existing.rs index a0243d3d35..d089370892 100644 --- a/crates/tests/interface/tests/com_from_existing.rs +++ b/crates/tests/interface/tests/com_from_existing.rs @@ -14,7 +14,7 @@ struct Test; impl IPersist_Impl for Test_Impl { fn GetClassID(&self) -> Result { - Ok("CEE1D356-0860-4262-90D4-C77423F0E352".into()) + "CEE1D356-0860-4262-90D4-C77423F0E352".try_into() } } @@ -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()?; diff --git a/crates/tests/interface/tests/no_use.rs b/crates/tests/interface/tests/no_use.rs index 5fdd2094a2..09505f4446 100644 --- a/crates/tests/interface/tests/no_use.rs +++ b/crates/tests/interface/tests/no_use.rs @@ -12,7 +12,7 @@ struct Test; impl windows::Win32::System::Com::IPersist_Impl for Test_Impl { fn GetClassID(&self) -> windows::core::Result { - Ok("CEE1D356-0860-4262-90D4-C77423F0E352".into()) + "CEE1D356-0860-4262-90D4-C77423F0E352".try_into() } } @@ -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)?; diff --git a/crates/tests/structs/tests/propertykey.rs b/crates/tests/structs/tests/propertykey.rs index 53e4ff7a9c..4d89a95985 100644 --- a/crates/tests/structs/tests/propertykey.rs +++ b/crates/tests/structs/tests/propertykey.rs @@ -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); } diff --git a/crates/tests/win32/tests/win32.rs b/crates/tests/win32/tests/win32.rs index 7f3fde6de7..4a27937c52 100644 --- a/crates/tests/win32/tests/win32.rs +++ b/crates/tests/win32/tests/win32.rs @@ -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; @@ -264,5 +264,5 @@ fn empty_struct() { assert!(ldap.0 == 123); assert!(core::mem::size_of::() == core::mem::size_of::()); - assert!(UIAnimationManager == GUID::from("4C1FC63A-695C-47E8-A339-1A194BE3D0B8")); + assert!(UIAnimationManager == GUID::try_from("4C1FC63A-695C-47E8-A339-1A194BE3D0B8").unwrap()); } diff --git a/crates/tests/winrt/tests/delegates.rs b/crates/tests/winrt/tests/delegates.rs index 2875e22fd3..d47a7a20f4 100644 --- a/crates/tests/winrt/tests/delegates.rs +++ b/crates/tests/winrt/tests/delegates.rs @@ -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(); @@ -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"))?; diff --git a/crates/tests/winrt/tests/generic_guids.rs b/crates/tests/winrt/tests/generic_guids.rs index b6414e6090..b81dc367e3 100644 --- a/crates/tests/winrt/tests/generic_guids.rs +++ b/crates/tests/winrt/tests/generic_guids.rs @@ -23,62 +23,62 @@ fn generic_guids() { // assert_eq!( IAsyncActionWithProgress::::IID, - GUID::from("DD725452-2DA3-5103-9C7D-22EE9BB14AD3") + GUID::try_from("DD725452-2DA3-5103-9C7D-22EE9BB14AD3").unwrap() ); assert_eq!( IAsyncOperationWithProgress::::IID, - GUID::from("94645425-B9E5-5B91-B509-8DA4DF6A8916") + GUID::try_from("94645425-B9E5-5B91-B509-8DA4DF6A8916").unwrap() ); assert_eq!( IAsyncOperation::::IID, - GUID::from("2BD35EE6-72D9-5C5D-9827-05EBB81487AB") + GUID::try_from("2BD35EE6-72D9-5C5D-9827-05EBB81487AB").unwrap() ); assert_eq!( IReferenceArray::::IID, - GUID::from("4A33FE03-E8B9-5346-A124-5449913ECA57") + GUID::try_from("4A33FE03-E8B9-5346-A124-5449913ECA57").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("F9E4006C-6E8C-56DF-811C-61F9990EBFB0") + GUID::try_from("F9E4006C-6E8C-56DF-811C-61F9990EBFB0").unwrap() ); assert_eq!( AsyncActionProgressHandler::::IID, - GUID::from("C261D8D0-71BA-5F38-A239-872342253A18") + GUID::try_from("C261D8D0-71BA-5F38-A239-872342253A18").unwrap() ); assert_eq!( AsyncActionWithProgressCompletedHandler::::IID, - GUID::from("9A0D211C-0374-5D23-9E15-EAA3570FAE63") + GUID::try_from("9A0D211C-0374-5D23-9E15-EAA3570FAE63").unwrap() ); assert_eq!( AsyncOperationCompletedHandler::::IID, - GUID::from("9D534225-231F-55E7-A6D0-6C938E2D9160") + GUID::try_from("9D534225-231F-55E7-A6D0-6C938E2D9160").unwrap() ); assert_eq!( AsyncOperationProgressHandler::::IID, - GUID::from("264F1E0C-ABE4-590B-9D37-E1CC118ECC75") + GUID::try_from("264F1E0C-ABE4-590B-9D37-E1CC118ECC75").unwrap() ); assert_eq!( AsyncOperationWithProgressCompletedHandler::::IID, - GUID::from("C2D078D8-AC47-55AB-83E8-123B2BE5BC5A") + GUID::try_from("C2D078D8-AC47-55AB-83E8-123B2BE5BC5A").unwrap() ); assert_eq!( EventHandler::::IID, - GUID::from("FA0B7D80-7EFA-52DF-9B69-0574CE57ADA4") + GUID::try_from("FA0B7D80-7EFA-52DF-9B69-0574CE57ADA4").unwrap() ); assert_eq!( TypedEventHandler::::IID, - GUID::from("EDB31843-B4CF-56EB-925A-D4D0CE97A08D") + GUID::try_from("EDB31843-B4CF-56EB-925A-D4D0CE97A08D").unwrap() ); // @@ -87,62 +87,62 @@ fn generic_guids() { assert_eq!( IIterable::::IID, - GUID::from("96565EB9-A692-59C8-BCB5-647CDE4E6C4D") + GUID::try_from("96565EB9-A692-59C8-BCB5-647CDE4E6C4D").unwrap() ); assert_eq!( IIterator::::IID, - GUID::from("3C9B1E27-8357-590B-8828-6E917F172390") + GUID::try_from("3C9B1E27-8357-590B-8828-6E917F172390").unwrap() ); assert_eq!( IKeyValuePair::::IID, - GUID::from("89336CD9-8B66-50A7-9759-EB88CCB2E1FE") + GUID::try_from("89336CD9-8B66-50A7-9759-EB88CCB2E1FE").unwrap() ); assert_eq!( IMapChangedEventArgs::::IID, - GUID::from("E1AA5138-12BD-51A1-8558-698DFD070ABE") + GUID::try_from("E1AA5138-12BD-51A1-8558-698DFD070ABE").unwrap() ); assert_eq!( IMapView::::IID, - GUID::from("B78F0653-FA89-59CF-BA95-726938AAE666") + GUID::try_from("B78F0653-FA89-59CF-BA95-726938AAE666").unwrap() ); assert_eq!( IMap::::IID, - GUID::from("9962CD50-09D5-5C46-B1E1-3C679C1C8FAE") + GUID::try_from("9962CD50-09D5-5C46-B1E1-3C679C1C8FAE").unwrap() ); assert_eq!( IObservableMap::::IID, - GUID::from("75F99E2A-137E-537E-A5B1-0B5A6245FC02") + GUID::try_from("75F99E2A-137E-537E-A5B1-0B5A6245FC02").unwrap() ); assert_eq!( IObservableVector::::IID, - GUID::from("D24C289F-2341-5128-AAA1-292DD0DC1950") + GUID::try_from("D24C289F-2341-5128-AAA1-292DD0DC1950").unwrap() ); assert_eq!( IVectorView::::IID, - GUID::from("5F07498B-8E14-556E-9D2E-2E98D5615DA9") + GUID::try_from("5F07498B-8E14-556E-9D2E-2E98D5615DA9").unwrap() ); assert_eq!( IVector::::IID, - GUID::from("0E3F106F-A266-50A1-8043-C90FCF3844F6") + GUID::try_from("0E3F106F-A266-50A1-8043-C90FCF3844F6").unwrap() ); assert_eq!( MapChangedEventHandler::::IID, - GUID::from("19046F0B-CF81-5DEC-BBB2-7CC250DA8B8B") + GUID::try_from("19046F0B-CF81-5DEC-BBB2-7CC250DA8B8B").unwrap() ); assert_eq!( VectorChangedEventHandler::::IID, - GUID::from("A1E9ACD7-E4DF-5A79-AEFA-DE07934AB0FB") + GUID::try_from("A1E9ACD7-E4DF-5A79-AEFA-DE07934AB0FB").unwrap() ); // @@ -151,67 +151,67 @@ fn generic_guids() { assert_eq!( IReference::::IID, - GUID::from("3C00FD60-2950-5939-A21A-2D12C5A01B8A") + GUID::try_from("3C00FD60-2950-5939-A21A-2D12C5A01B8A").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("95500129-FBF6-5AFC-89DF-70642D741990") + GUID::try_from("95500129-FBF6-5AFC-89DF-70642D741990").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("6EC9E41B-6709-5647-9918-A1270110FC4E") + GUID::try_from("6EC9E41B-6709-5647-9918-A1270110FC4E").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("548CEFBD-BC8A-5FA0-8DF2-957440FC8BF4") + GUID::try_from("548CEFBD-BC8A-5FA0-8DF2-957440FC8BF4").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("4DDA9E24-E69F-5C6A-A0A6-93427365AF2A") + GUID::try_from("4DDA9E24-E69F-5C6A-A0A6-93427365AF2A").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("e5198cc8-2873-55f5-b0a1-84ff9e4aad62") + GUID::try_from("e5198cc8-2873-55f5-b0a1-84ff9e4aad62").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("5AB7D2C3-6B62-5E71-A4B6-2D49C4F238FD") + GUID::try_from("5AB7D2C3-6B62-5E71-A4B6-2D49C4F238FD").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("513ef3af-e784-5325-a91e-97c2b8111cf3") + GUID::try_from("513ef3af-e784-5325-a91e-97c2b8111cf3").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("6755e376-53bb-568b-a11d-17239868309e") + GUID::try_from("6755e376-53bb-568b-a11d-17239868309e").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("719CC2BA-3E76-5DEF-9F1A-38D85A145EA8") + GUID::try_from("719CC2BA-3E76-5DEF-9F1A-38D85A145EA8").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("2F2D6C29-5473-5F3E-92E7-96572BB990E2") + GUID::try_from("2F2D6C29-5473-5F3E-92E7-96572BB990E2").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("7D50F649-632C-51F9-849A-EE49428933EA") + GUID::try_from("7D50F649-632C-51F9-849A-EE49428933EA").unwrap() ); assert_eq!( IReference::::IID, - GUID::from("FD416DFB-2A07-52EB-AAE3-DFCE14116C05") + GUID::try_from("FD416DFB-2A07-52EB-AAE3-DFCE14116C05").unwrap() ); // TODO: structs and enums @@ -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... @@ -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() ); } diff --git a/crates/tests/winrt/tests/guid.rs b/crates/tests/winrt/tests/guid.rs index 19701f3d6a..348a9557b4 100644 --- a/crates/tests/winrt/tests/guid.rs +++ b/crates/tests/winrt/tests/guid.rs @@ -1,4 +1,3 @@ -use windows::core::GUID; use windows::Foundation::GuidHelper; #[test] @@ -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); -} diff --git a/crates/tests/winrt/tests/interface.rs b/crates/tests/winrt/tests/interface.rs index 0fb0b99572..e99eaef160 100644 --- a/crates/tests/winrt/tests/interface.rs +++ b/crates/tests/winrt/tests/interface.rs @@ -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. diff --git a/crates/tests/winrt/tests/uri.rs b/crates/tests/winrt/tests/uri.rs index e146dcd6b4..b42265a39b 100644 --- a/crates/tests/winrt/tests/uri.rs +++ b/crates/tests/winrt/tests/uri.rs @@ -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"))?;