Skip to content

Commit

Permalink
gio: Add DBus RegistrationBuilder.property()/set_property() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quo committed Jan 3, 2025
1 parent bdd68d5 commit 7e9610c
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions gio/tests/dbus_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn test_gdbus_peer_connection() {
const EXAMPLE_XML: &str = r#"
<node>
<interface name='com.github.gtk_rs'>
<property type='i' name='Number' access='readwrite' />
<method name='Hello'>
<arg type='s' name='name' direction='in'/>
<arg type='s' name='greet' direction='out'/>
Expand Down Expand Up @@ -57,6 +58,7 @@ fn test_gdbus_peer_connection() {
parameters,
invocation| {
dbg!(
"method_call",
_sender,
_object_path,
_interface_name,
Expand All @@ -69,6 +71,34 @@ fn test_gdbus_peer_connection() {
invocation.return_value(Some(&(format!("Hello {name}!"),).to_variant()));
},
)
.property({
|_connection, _sender, _object_path, _interface_name, _property_name| {
dbg!(
"get_property",
_sender,
_object_path,
_interface_name,
_property_name
);
assert_eq!(_property_name, "Number");
123.to_variant()
}
})
.set_property({
|_connection, _sender, _object_path, _interface_name, _property_name, _value| {
dbg!(
"set_property",
_sender,
_object_path,
_interface_name,
_property_name,
&_value
);
assert_eq!(_property_name, "Number");
assert_eq!(_value, 456.to_variant());
true
}
})
.build()
.unwrap();

Expand Down Expand Up @@ -137,6 +167,42 @@ fn test_gdbus_peer_connection() {

dbg!(&result);

dbg!("getting property");

let getresult = client
.call_future(
None,
"/com/github/gtk_rs",
"org.freedesktop.DBus.Properties",
"Get",
Some(&("com.github.gtk_rs", "Number").to_variant()),
Some(VariantTy::new("(v)").unwrap()),
gio::DBusCallFlags::NONE,
10000,
)
.await
.unwrap();

assert_eq!(getresult, (123.to_variant(),).to_variant());

dbg!("setting property");

let setresult = client
.call_future(
None,
"/com/github/gtk_rs",
"org.freedesktop.DBus.Properties",
"Set",
Some(&("com.github.gtk_rs", "Number", 456.to_variant()).to_variant()),
None,
gio::DBusCallFlags::NONE,
10000,
)
.await
.unwrap();

assert_eq!(setresult, ().to_variant());

dbg!("closing client");
client.close_future().await.unwrap();
dbg!("closed client, closing server");
Expand Down

0 comments on commit 7e9610c

Please sign in to comment.