@@ -760,12 +760,15 @@ impl Drop for ProtocolBuilder {
760
760
761
761
#[ cfg( test) ]
762
762
mod tests {
763
+ use core:: hash:: Hasher ;
764
+ use std:: collections:: hash_map:: DefaultHasher ;
765
+ use std:: hash:: Hash ;
766
+
763
767
use super :: * ;
764
768
use crate :: mutability:: Immutable ;
765
769
use crate :: rc:: Id ;
766
- use crate :: runtime:: { NSObject , NSZone , __NSCopying as NSCopying } ;
767
- use crate :: test_utils;
768
- use crate :: { declare_class, msg_send, ClassType , ProtocolType } ;
770
+ use crate :: runtime:: { NSObject , NSObjectProtocol , NSZone , __NSCopying as NSCopying } ;
771
+ use crate :: { declare_class, extern_methods, msg_send, test_utils, ClassType , ProtocolType } ;
769
772
770
773
#[ test]
771
774
fn test_alignment ( ) {
@@ -1157,4 +1160,55 @@ mod tests {
1157
1160
1158
1161
let _ = GenericDeclareClass :: < ( ) > :: class ( ) ;
1159
1162
}
1163
+
1164
+ #[ test]
1165
+ fn test_inherited_nsobject_methods_work ( ) {
1166
+ declare_class ! (
1167
+ #[ derive( Debug , PartialEq , Eq , Hash ) ]
1168
+ struct Custom ;
1169
+
1170
+ unsafe impl ClassType for Custom {
1171
+ type Super = NSObject ;
1172
+ type Mutability = Immutable ;
1173
+ const NAME : & ' static str = "TestInheritedNSObjectMethodsWork" ;
1174
+ }
1175
+ ) ;
1176
+
1177
+ extern_methods ! (
1178
+ unsafe impl Custom {
1179
+ #[ method_id( new) ]
1180
+ fn new( ) -> Id <Self >;
1181
+ }
1182
+ ) ;
1183
+
1184
+ let obj1 = Custom :: new ( ) ;
1185
+ let obj2 = Custom :: new ( ) ;
1186
+
1187
+ // isEqual:
1188
+ assert_eq ! ( obj1, obj1) ;
1189
+ assert_ne ! ( obj1, obj2) ;
1190
+
1191
+ // description
1192
+ let expected =
1193
+ format ! ( "Custom {{ __superclass: ManuallyDrop {{ value: <TestInheritedNSObjectMethodsWork: {obj1:p}> }} }}" ) ;
1194
+ assert_eq ! ( format!( "{obj1:?}" ) , expected) ;
1195
+
1196
+ // hash
1197
+ let mut hashstate1 = DefaultHasher :: new ( ) ;
1198
+ let mut hashstate2 = DefaultHasher :: new ( ) ;
1199
+
1200
+ obj1. hash ( & mut hashstate1) ;
1201
+ obj1. hash ( & mut hashstate2) ;
1202
+
1203
+ assert_eq ! ( hashstate1. finish( ) , hashstate2. finish( ) ) ;
1204
+
1205
+ let mut hashstate2 = DefaultHasher :: new ( ) ;
1206
+ obj2. hash ( & mut hashstate2) ;
1207
+ assert_ne ! ( hashstate1. finish( ) , hashstate2. finish( ) ) ;
1208
+
1209
+ // isKindOfClass:
1210
+ assert ! ( obj1. is_kind_of:: <NSObject >( ) ) ;
1211
+ assert ! ( obj1. is_kind_of:: <Custom >( ) ) ;
1212
+ assert ! ( obj1. is_kind_of:: <Custom >( ) ) ;
1213
+ }
1160
1214
}
0 commit comments