Skip to content

Commit

Permalink
Implement Debug for AgileReference (#1986)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 26, 2022
1 parent f8947e7 commit 9a1c065
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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(())
}

0 comments on commit 9a1c065

Please sign in to comment.