@@ -10,7 +10,10 @@ fn test_client_capabilities() {
1010 let client = DbusClient :: new ( ) ;
1111 let msg = client. call_method ( "GetClientCapabilities" , & ( ) ) . unwrap ( ) ;
1212 let body = msg. body ( ) ;
13- let rsp: HashMap < String , Value > = body. deserialize ( ) . unwrap ( ) ;
13+ let rsp: HashMap < String , bool > = body. deserialize :: < HashMap < String , Value > > ( ) . unwrap ( )
14+ . into_iter ( )
15+ . map ( |( k, v) | ( k, v. try_into ( ) . unwrap ( ) ) )
16+ . collect ( ) ;
1417
1518 let capabilities = HashMap :: from ( [
1619 ( "conditionalCreate" , false ) ,
@@ -24,8 +27,8 @@ fn test_client_capabilities() {
2427 ( "signalUnknownCredential" , false ) ,
2528 ] ) ;
2629 for ( key, expected) in capabilities. iter ( ) {
27- let value : & Value = rsp. get ( * key) . unwrap ( ) ;
28- assert_eq ! ( * expected, value . try_into ( ) . unwrap ( ) ) ;
30+ let actual = rsp. get ( * key) . unwrap ( ) ;
31+ assert_eq ! ( * expected, * actual ) ;
2932 }
3033}
3134
@@ -35,36 +38,32 @@ mod client {
3538 use serde:: Serialize ;
3639 use zbus:: { blocking:: Connection , zvariant:: DynamicType , Message } ;
3740
38- fn init_test_dbus ( ) -> TestDBus {
39- let dbus = TestDBus :: new ( TestDBusFlags :: NONE ) ;
40-
41- // assumes this runs in root of Cargo project.
42- let current_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
43- let service_dir = current_dir. join ( SERVICE_DIR ) ;
44- println ! ( "{:?}" , service_dir) ;
45- dbus. add_service_dir ( service_dir. to_str ( ) . unwrap ( ) ) ;
46-
47- dbus. up ( ) ;
48- dbus
49- }
50-
5141 pub ( super ) struct DbusClient {
52- _bus : TestDBus ,
42+ bus : TestDBus ,
5343 }
5444
5545 impl DbusClient {
5646 pub fn new ( ) -> Self {
57- Self {
58- _bus : init_test_dbus ( ) ,
59- }
47+ let bus = TestDBus :: new ( TestDBusFlags :: NONE ) ;
48+ bus. add_service_dir ( SERVICE_DIR ) ;
49+ bus. up ( ) ;
50+ Self { bus }
6051 }
6152
6253 pub fn call_method < B > ( & self , method_name : & str , body : & B ) -> zbus:: Result < Message >
6354 where
6455 B : Serialize + DynamicType ,
6556 {
6657 let connection = Connection :: session ( ) . unwrap ( ) ;
67- connection. call_method ( Some ( SERVICE_NAME ) , PATH , Some ( INTERFACE ) , method_name, body)
58+ let message = connection. call_method ( Some ( SERVICE_NAME ) , PATH , Some ( INTERFACE ) , method_name, body) ;
59+ connection. close ( ) . unwrap ( ) ;
60+ message
61+ }
62+
63+ }
64+ impl Drop for DbusClient {
65+ fn drop ( & mut self ) {
66+ self . bus . stop ( ) ;
6867 }
6968 }
7069}
0 commit comments