22import XCTest
33
44fileprivate class ExampleClass : NSObject {
5- @objc dynamic func foo ( ) { }
5+ @objc dynamic func doSomething ( ) { }
66}
77
88fileprivate class ExampleSubclass : ExampleClass { }
@@ -12,7 +12,7 @@ final class ClassHookTests: InterposeKitTestCase {
1212 func testSuccess_applyHook( ) throws {
1313 let hook = try Interpose . applyHook (
1414 on: ExampleClass . self,
15- for: #selector( ExampleClass . foo ) ,
15+ for: #selector( ExampleClass . doSomething ) ,
1616 methodSignature: ( @convention( c) ( NSObject, Selector) - > Void) . self,
1717 hookSignature: ( @convention( block) ( NSObject) - > Void) . self
1818 ) { hook in
@@ -22,22 +22,22 @@ final class ClassHookTests: InterposeKitTestCase {
2222 XCTAssertEqual ( hook. state, . active)
2323 XCTAssertMatchesRegex (
2424 hook. debugDescription,
25- #"^Active hook for -\[ExampleClass foo \] \(originalIMP: 0x[0-9a-fA-F]+\)$"#
25+ #"^Active hook for -\[ExampleClass doSomething \] \(originalIMP: 0x[0-9a-fA-F]+\)$"#
2626 )
2727
2828 try hook. revert ( )
2929
3030 XCTAssertEqual ( hook. state, . pending)
3131 XCTAssertMatchesRegex (
3232 hook. debugDescription,
33- #"^Pending hook for -\[ExampleClass foo \]$"#
33+ #"^Pending hook for -\[ExampleClass doSomething \]$"#
3434 )
3535 }
3636
3737 func testSuccess_prepareHook( ) throws {
3838 let hook = try Interpose . prepareHook (
3939 on: ExampleClass . self,
40- for: #selector( ExampleClass . foo ) ,
40+ for: #selector( ExampleClass . doSomething ) ,
4141 methodSignature: ( @convention( c) ( NSObject, Selector) - > Void) . self,
4242 hookSignature: ( @convention( block) ( NSObject) - > Void) . self
4343 ) { hook in
@@ -47,39 +47,39 @@ final class ClassHookTests: InterposeKitTestCase {
4747 XCTAssertEqual ( hook. state, . pending)
4848 XCTAssertMatchesRegex (
4949 hook. debugDescription,
50- #"^Pending hook for -\[ExampleClass foo \]$"#
50+ #"^Pending hook for -\[ExampleClass doSomething \]$"#
5151 )
5252
5353 try hook. apply ( )
5454
5555 XCTAssertEqual ( hook. state, . active)
5656 XCTAssertMatchesRegex (
5757 hook. debugDescription,
58- #"^Active hook for -\[ExampleClass foo \] \(originalIMP: 0x[0-9a-fA-F]+\)$"#
58+ #"^Active hook for -\[ExampleClass doSomething \] \(originalIMP: 0x[0-9a-fA-F]+\)$"#
5959 )
6060
6161 try hook. revert ( )
6262
6363 XCTAssertEqual ( hook. state, . pending)
6464 XCTAssertMatchesRegex (
6565 hook. debugDescription,
66- #"^Pending hook for -\[ExampleClass foo \]$"#
66+ #"^Pending hook for -\[ExampleClass doSomething \]$"#
6767 )
6868 }
6969
7070 func testValidationFailure_methodNotFound( ) throws {
7171 XCTAssertThrowsError (
7272 try Interpose . prepareHook (
7373 on: ExampleClass . self,
74- for: Selector ( ( " bar " ) ) ,
74+ for: Selector ( ( " doSomethingNotFound " ) ) ,
7575 methodSignature: ( @convention( c) ( NSObject, Selector) - > Void) . self,
7676 hookSignature: ( @convention( block) ( NSObject) - > Void) . self
7777 ) { hook in
7878 return { `self` in }
7979 } ,
8080 expected: InterposeError . methodNotFound (
8181 class: ExampleClass . self,
82- selector: Selector ( ( " bar " ) )
82+ selector: Selector ( ( " doSomethingNotFound " ) )
8383 )
8484 )
8585 }
@@ -88,23 +88,23 @@ final class ClassHookTests: InterposeKitTestCase {
8888 XCTAssertThrowsError (
8989 try Interpose . prepareHook (
9090 on: ExampleSubclass . self,
91- for: #selector( ExampleClass . foo ) ,
91+ for: #selector( ExampleClass . doSomething ) ,
9292 methodSignature: ( @convention( c) ( NSObject, Selector) - > Void) . self,
9393 hookSignature: ( @convention( block) ( NSObject) - > Void) . self
9494 ) { hook in
9595 return { `self` in }
9696 } ,
9797 expected: InterposeError . methodNotDirectlyImplemented (
9898 class: ExampleSubclass . self,
99- selector: #selector( ExampleClass . foo )
99+ selector: #selector( ExampleClass . doSomething )
100100 )
101101 )
102102 }
103103
104104 func testRevertFailure_corrupted( ) throws {
105105 let hook = try Interpose . applyHook (
106106 on: ExampleClass . self,
107- for: #selector( ExampleClass . foo ) ,
107+ for: #selector( ExampleClass . doSomething ) ,
108108 methodSignature: ( @convention( c) ( NSObject, Selector) - > Void) . self,
109109 hookSignature: ( @convention( block) ( NSObject) - > Void) . self
110110 ) { hook in
@@ -116,15 +116,15 @@ final class ClassHookTests: InterposeKitTestCase {
116116 // in which it cannot restore the original implementation.
117117 let method = try XCTUnwrap ( class_getInstanceMethod (
118118 ExampleClass . self,
119- #selector( ExampleClass . foo )
119+ #selector( ExampleClass . doSomething )
120120 ) )
121121
122122 let externalBlock : @convention ( block) ( NSObject ) -> Void = { _ in }
123123 let externalIMP = imp_implementationWithBlock ( externalBlock)
124124
125125 XCTAssertNotNil ( class_replaceMethod (
126126 ExampleClass . self,
127- #selector( ExampleClass . foo ) ,
127+ #selector( ExampleClass . doSomething ) ,
128128 externalIMP,
129129 method_getTypeEncoding ( method)
130130 ) )
@@ -133,15 +133,15 @@ final class ClassHookTests: InterposeKitTestCase {
133133 try hook. revert ( ) ,
134134 expected: InterposeError . revertCorrupted (
135135 class: ExampleClass . self,
136- selector: #selector( ExampleClass . foo ) ,
136+ selector: #selector( ExampleClass . doSomething ) ,
137137 imp: externalIMP
138138 )
139139 )
140140
141141 XCTAssertEqual ( hook. state, . failed)
142142 XCTAssertMatchesRegex (
143143 hook. debugDescription,
144- #"^Failed hook for -\[ExampleClass foo \]$"#
144+ #"^Failed hook for -\[ExampleClass doSomething \]$"#
145145 )
146146 }
147147
0 commit comments