@@ -595,7 +595,7 @@ mod tests {
595
595
596
596
use crate :: rc:: { autoreleasepool, RcTestObject , ThreadTestData } ;
597
597
use crate :: runtime:: { NSObject , NSZone } ;
598
- use crate :: { class, msg_send_id, AllocAnyThread } ;
598
+ use crate :: { class, extern_methods , msg_send_id, AllocAnyThread } ;
599
599
600
600
mod test_trait_disambugated {
601
601
use super :: * ;
@@ -1136,4 +1136,98 @@ mod tests {
1136
1136
let retained = retained. unwrap ( ) ;
1137
1137
assert_eq ! ( & * retained, cls) ;
1138
1138
}
1139
+
1140
+ extern_methods ! (
1141
+ unsafe impl RcTestObject {
1142
+ #[ method_id( copy) ]
1143
+ #[ unsafe ( method_family = new) ]
1144
+ fn copy_new( & self ) -> Retained <Self >;
1145
+
1146
+ #[ method_id( copy) ]
1147
+ #[ unsafe ( method_family = init) ]
1148
+ fn copy_init( this: Allocated <Self >) -> Retained <Self >;
1149
+
1150
+ #[ method_id( copy) ]
1151
+ #[ unsafe ( method_family = copy) ]
1152
+ fn copy_copy( & self ) -> Retained <Self >;
1153
+
1154
+ #[ method_id( copy) ]
1155
+ #[ unsafe ( method_family = mutableCopy) ]
1156
+ fn copy_mutable_copy( & self ) -> Retained <Self >;
1157
+
1158
+ #[ method_id( copy) ]
1159
+ #[ unsafe ( method_family = none) ]
1160
+ fn copy_none( & self ) -> Retained <Self >;
1161
+ }
1162
+ ) ;
1163
+
1164
+ #[ test]
1165
+ fn test_method_family ( ) {
1166
+ // Test a few combinations of (incorrect) method families.
1167
+ let obj = RcTestObject :: new ( ) ;
1168
+ let mut expected = ThreadTestData :: current ( ) ;
1169
+
1170
+ let copy = obj. copy_new ( ) ;
1171
+ expected. copy += 1 ;
1172
+ expected. alloc += 1 ;
1173
+ expected. init += 1 ;
1174
+ expected. assert_current ( ) ;
1175
+ drop ( copy) ;
1176
+ expected. release += 1 ;
1177
+ expected. drop += 1 ;
1178
+ expected. assert_current ( ) ;
1179
+
1180
+ let alloc = RcTestObject :: alloc ( ) ;
1181
+ let ptr = Allocated :: as_ptr ( & alloc) ;
1182
+ expected. alloc += 1 ;
1183
+ expected. assert_current ( ) ;
1184
+ let copy = RcTestObject :: copy_init ( alloc) ;
1185
+ expected. copy += 1 ;
1186
+ expected. alloc += 1 ;
1187
+ expected. init += 1 ;
1188
+ expected. assert_current ( ) ;
1189
+ drop ( copy) ;
1190
+ expected. release += 1 ;
1191
+ expected. drop += 1 ;
1192
+ expected. assert_current ( ) ;
1193
+ drop ( unsafe { Allocated :: new ( ptr. cast_mut ( ) ) } ) ;
1194
+ expected. release += 1 ;
1195
+ expected. assert_current ( ) ;
1196
+
1197
+ let copy = obj. copy_copy ( ) ;
1198
+ expected. copy += 1 ;
1199
+ expected. alloc += 1 ;
1200
+ expected. init += 1 ;
1201
+ expected. assert_current ( ) ;
1202
+ drop ( copy) ;
1203
+ expected. release += 1 ;
1204
+ expected. drop += 1 ;
1205
+ expected. assert_current ( ) ;
1206
+
1207
+ let copy = obj. copy_mutable_copy ( ) ;
1208
+ expected. copy += 1 ;
1209
+ expected. alloc += 1 ;
1210
+ expected. init += 1 ;
1211
+ expected. assert_current ( ) ;
1212
+ drop ( copy) ;
1213
+ expected. release += 1 ;
1214
+ expected. drop += 1 ;
1215
+ expected. assert_current ( ) ;
1216
+
1217
+ let copy = obj. copy_none ( ) ;
1218
+ expected. copy += 1 ;
1219
+ expected. alloc += 1 ;
1220
+ expected. init += 1 ;
1221
+ expected. retain += 1 ;
1222
+ expected. assert_current ( ) ;
1223
+ // SAFETY: Wrong method family specified, so we have +1 retain count
1224
+ // in excess.
1225
+ drop ( unsafe { Retained :: from_raw ( Retained :: as_ptr ( & copy) . cast_mut ( ) ) } ) ;
1226
+ expected. release += 1 ;
1227
+ expected. assert_current ( ) ;
1228
+ drop ( copy) ;
1229
+ expected. release += 1 ;
1230
+ expected. drop += 1 ;
1231
+ expected. assert_current ( ) ;
1232
+ }
1139
1233
}
0 commit comments