use test_log::test;
use tracing::instrument;
use zbus::zvariant::OwnedObjectPath;
struct Adapter {
name: String,
}
#[zbus::interface(interface = "org.test.Adapter", proxy(assume_defaults = true))]
impl Adapter {
#[zbus(property)]
fn name(&self) -> String {
self.name.clone()
}
}
struct Device {
adapter_path: OwnedObjectPath,
}
#[zbus::interface(interface = "org.test.Device", proxy(assume_defaults = true))]
impl Device {
#[zbus(property, proxy(object = "Adapter"))]
fn adapter(&self) -> OwnedObjectPath {
self.adapter_path.clone()
}
}
#[test(tokio::test(flavor = "multi_thread"))]
#[instrument]
async fn issue_356() {
use zbus::connection::Builder;
let adapter_path: OwnedObjectPath = "/org/test/adapter0".try_into().unwrap();
let device_path: OwnedObjectPath = "/org/test/device0".try_into().unwrap();
let connection = Builder::session()
.unwrap()
.serve_at(
&adapter_path,
Adapter {
name: "TestAdapter".to_string(),
},
)
.unwrap()
.serve_at(
&device_path,
Device {
adapter_path: adapter_path.clone(),
},
)
.unwrap()
.name("org.test.Issue356")
.unwrap()
.build()
.await
.unwrap();
let device_proxy = DeviceProxy::builder(&connection)
.destination("org.test.Issue356")
.unwrap()
.path(&device_path)
.unwrap()
.build()
.await
.unwrap();
let adapter_proxy = device_proxy.adapter().await.unwrap();
let adapter_name = adapter_proxy.name().await.unwrap();
assert_eq!(adapter_name, "TestAdapter");
}