@@ -19,34 +19,25 @@ impl TestIt {
1919}
2020
2121#[ test]
22- fn opaque_pointer_with_free ( ) {
22+ fn own_back ( ) {
2323 let pointer = opaque_pointer:: raw ( TestIt :: new ( 2 ) ) ;
24- // Context to drop object variable
25- {
26- let object = unsafe { opaque_pointer:: mut_object ( pointer) } ;
27- object. add ( 3 ) ;
28- }
29- // Context to drop object variable
30- {
31- let object = unsafe { opaque_pointer:: object ( pointer) } ;
32- assert_eq ! ( object. get( ) , 5 ) ;
33- }
34- unsafe { opaque_pointer:: free ( pointer) } ;
24+ let test_it = unsafe { opaque_pointer:: own_back ( pointer) } ;
25+ assert_eq ! ( test_it. get( ) , 2 ) ;
3526}
3627
3728#[ test]
38- fn opaque_pointer_with_own_back ( ) {
29+ fn immutable_reference ( ) {
3930 let pointer = opaque_pointer:: raw ( TestIt :: new ( 2 ) ) ;
40- // Context to drop object variable
41- {
42- let object = unsafe { opaque_pointer:: mut_object ( pointer) } ;
43- object . add ( 3 ) ;
44- }
45- // Context to drop object variable
46- {
47- let object = unsafe { opaque_pointer:: object ( pointer ) } ;
48- assert_eq ! ( object . get ( ) , 5 ) ;
49- }
50- let test_it = unsafe { opaque_pointer :: own_back ( pointer ) } ;
51- assert_eq ! ( test_it . get ( ) , 5 ) ;
31+ let object = unsafe { opaque_pointer :: object ( pointer ) } ;
32+ assert_eq ! ( object . get ( ) , 2 ) ;
33+ unsafe { opaque_pointer:: own_back ( pointer) } ;
34+ }
35+
36+ # [ test ]
37+ fn mutable_reference ( ) {
38+ let pointer = opaque_pointer:: raw ( TestIt :: new ( 2 ) ) ;
39+ let object = unsafe { opaque_pointer :: mut_object ( pointer ) } ;
40+ object . add ( 3 ) ;
41+ assert_eq ! ( object . get ( ) , 5 ) ;
42+ unsafe { opaque_pointer :: own_back ( pointer ) } ;
5243}
0 commit comments