Created
August 1, 2009 16:18
-
-
Save mkhl/159706 to your computer and use it in GitHub Desktop.
Cocoa UI Unit Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Cocoa UI Unit Testing | |
| // Source: http://eschatologist.net/blog/?p=205 | |
| @interface MyTestCase : SenTestCase | |
| @end | |
| @implementation MyTestCase | |
| /*! Tells whether the control sends the action to the target. */ | |
| - (BOOL)checkControl:(NSControl *)control | |
| sendsAction:(SEL)action | |
| toTarget:(id)target | |
| { | |
| return ([control action] == action) | |
| && ([control target] == target); | |
| } | |
| /*! Tells whether the outlet is connected to the given destination. */ | |
| - (BOOL)checkOutlet:(id)outlet | |
| connectsTo:(id)destination | |
| { | |
| return outlet == destination; | |
| } | |
| /*! Tells whether the object's binding is connected through the given key path. */ | |
| - (BOOL)checkObject:(id)source | |
| hasBinding:(NSString *)binding | |
| toObject:(id)destination | |
| through:(NSString *)keyPath | |
| { | |
| NSDictionary *bindingInfo = [source infoForBinding:binding]; | |
| id observedObject = [bindingInfo objectForKey:NSObservedObjectKey]; | |
| NSString *observedKeyPath = [bindingInfo objectForKey:NSObservedKeyPathKey]; | |
| return (bindingInfo != nil) | |
| && (observedObject == destination) | |
| && [keyPath isEqualToString:observedKeyPath]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment