@@ -252,4 +252,44 @@ mod test {
252252 unsafe { <MySharedRc as SharedType >:: RefCountedType :: from_raw ( inner_raw_ptr_clone) } ;
253253 assert_eq ! ( std:: rc:: Rc :: strong_count( & b. 0 ) , 1 ) ;
254254 }
255+
256+ #[ test]
257+ fn from_glib_borrow_arc ( ) {
258+ assert_ne ! ( crate :: Type :: INVALID , MySharedRc :: static_type( ) ) ;
259+
260+ let b = MySharedArc :: from_refcounted ( std:: sync:: Arc :: new ( MySharedInner {
261+ foo : String :: from ( "abc" ) ,
262+ } ) ) ;
263+
264+ let inner_raw_ptr = std:: sync:: Arc :: into_raw ( b. clone ( ) . 0 ) ;
265+
266+ assert_eq ! ( std:: sync:: Arc :: strong_count( & b. 0 ) , 2 ) ;
267+
268+ unsafe {
269+ let _ = MySharedArc :: from_glib_borrow ( inner_raw_ptr) ;
270+ assert_eq ! ( std:: sync:: Arc :: strong_count( & b. 0 ) , 2 ) ;
271+ }
272+
273+ assert_eq ! ( std:: sync:: Arc :: strong_count( & b. 0 ) , 2 ) ;
274+ }
275+
276+ #[ test]
277+ fn from_glib_borrow_rc ( ) {
278+ assert_ne ! ( crate :: Type :: INVALID , MySharedRc :: static_type( ) ) ;
279+
280+ let b = MySharedRc :: from_refcounted ( std:: rc:: Rc :: new ( MySharedInner {
281+ foo : String :: from ( "abc" ) ,
282+ } ) ) ;
283+
284+ let inner_raw_ptr = std:: rc:: Rc :: into_raw ( b. clone ( ) . 0 ) ;
285+
286+ assert_eq ! ( std:: rc:: Rc :: strong_count( & b. 0 ) , 2 ) ;
287+
288+ unsafe {
289+ let _ = MySharedRc :: from_glib_borrow ( inner_raw_ptr) ;
290+ assert_eq ! ( std:: rc:: Rc :: strong_count( & b. 0 ) , 2 ) ;
291+ }
292+
293+ assert_eq ! ( std:: rc:: Rc :: strong_count( & b. 0 ) , 2 ) ;
294+ }
255295}
0 commit comments