-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for NSUIApplication+MIKMIDI.
- Loading branch information
Andrew Madsen
committed
May 7, 2015
1 parent
3351a6a
commit 5dba0e0
Showing
2 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// MIKMIDIResponderChainTests.m | ||
// MIKMIDI | ||
// | ||
// Created by Andrew Madsen on 5/7/15. | ||
// Copyright (c) 2015 Mixed In Key. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <XCTest/XCTest.h> | ||
#import <MIKMIDI/MIKMIDI.h> | ||
|
||
@interface MIKMIDIDummyResponder : NSObject <MIKMIDIResponder> | ||
|
||
- (instancetype)initWithMIDIIdentifier:(NSString *)identifier subresponders:(NSArray *)subresponders; | ||
|
||
@property (nonatomic, strong, readonly) NSString *MIDIIdentifier; | ||
@property (nonatomic, strong, readonly) NSArray *subresponders; | ||
|
||
@end | ||
|
||
@implementation MIKMIDIDummyResponder | ||
|
||
- (instancetype)initWithMIDIIdentifier:(NSString *)identifier subresponders:(NSArray *)subresponders; | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
_MIDIIdentifier = identifier; | ||
_subresponders = subresponders; | ||
} | ||
return self; | ||
} | ||
|
||
- (BOOL)respondsToMIDICommand:(MIKMIDICommand *)command { return NO; } | ||
- (void)handleMIDICommand:(MIKMIDICommand *)command { } | ||
|
||
@end | ||
|
||
@interface MIKMIDIResponderChainTests : XCTestCase | ||
|
||
@property (nonatomic, strong) MIKMIDIDummyResponder *dummyResponder; | ||
|
||
@end | ||
|
||
@implementation MIKMIDIResponderChainTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
|
||
MIKMIDIDummyResponder *sub1 = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Sub1" subresponders:nil]; | ||
|
||
MIKMIDIDummyResponder *sub2sub1 = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Sub2Sub1" subresponders:nil]; | ||
MIKMIDIDummyResponder *sub2sub2 = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Sub2Sub2" subresponders:nil]; | ||
MIKMIDIDummyResponder *sub2 = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Sub2" subresponders:@[sub2sub1, sub2sub2]]; | ||
|
||
MIKMIDIDummyResponder *sub3 = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Sub3" subresponders:nil]; | ||
|
||
self.dummyResponder = [[MIKMIDIDummyResponder alloc] initWithMIDIIdentifier:@"Dummy" subresponders:@[sub1, sub2, sub3]]; | ||
} | ||
|
||
- (void)testRegistration | ||
{ | ||
NSApplication *app = [NSApplication sharedApplication]; | ||
[app registerMIDIResponder:self.dummyResponder]; | ||
|
||
XCTAssertNotNil([app MIDIResponderWithIdentifier:@"Dummy"], @"Top level dummy responder not found."); | ||
XCTAssertNotNil([app MIDIResponderWithIdentifier:@"Sub1"], @"First level dummy subresponder not found."); | ||
XCTAssertNotNil([app MIDIResponderWithIdentifier:@"Sub2Sub2"], @"First level dummy subresponder not found."); | ||
} | ||
|
||
- (void)testUncachedResponderSearchPerformance | ||
{ | ||
NSApplication *app = [NSApplication sharedApplication]; | ||
[self measureBlock:^{ | ||
for (NSUInteger i=0; i<50000; i++) { | ||
[app MIDIResponderWithIdentifier:@"Sub2Sub1"]; | ||
} | ||
}]; | ||
} | ||
|
||
@end |
This file contains 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