Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Debug for AgileReference #1986

Merged
merged 2 commits into from Aug 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/libs/windows/src/core/agile_reference.rs
Expand Up @@ -22,3 +22,9 @@ impl<T: Interface> AgileReference<T> {

unsafe impl<T: Interface> Send for AgileReference<T> {}
unsafe impl<T: Interface> Sync for AgileReference<T> {}

impl<T> std::fmt::Debug for AgileReference<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "AgileReference({:?})", <&IAgileReference as Into<&IUnknown>>::into(&self.0))
}
}
15 changes: 13 additions & 2 deletions crates/tests/agile_reference/tests/tests.rs
@@ -1,8 +1,9 @@
use windows::core::{AgileReference, Result};
use windows::core::{w, AgileReference, Result};
use windows::Foundation::Uri;
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;

#[test]
fn test() -> Result<()> {
fn agile_send() -> Result<()> {
let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?;
let reference = AgileReference::new(&manager)?;

Expand All @@ -14,3 +15,13 @@ fn test() -> Result<()> {
});
handle.join().unwrap()
}

#[test]
fn agile_debug() -> Result<()> {
let uri = Uri::CreateUri(w!("http://kennykerr.ca"))?;
assert!(format!("{:?}", uri).starts_with("Uri(IUnknown(0x"));

let reference = AgileReference::new(&uri)?;
assert!(format!("{:?}", reference).starts_with("AgileReference(IUnknown(0x"));
Ok(())
}