Skip to content

Commit

Permalink
Added unit tests for NSUIApplication+MIKMIDI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Madsen committed May 7, 2015
1 parent 3351a6a commit 5dba0e0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 17 deletions.
82 changes: 82 additions & 0 deletions Framework/MIKMIDI Tests/MIKMIDIResponderChainTests.m
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
30 changes: 13 additions & 17 deletions Framework/MIKMIDI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
83BC19BC1A23CD0D004F384F /* MIKMIDIMetronome.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BC19BA1A23CD0D004F384F /* MIKMIDIMetronome.m */; };
83C3716719D607010017186B /* MIKMIDIClientDestinationEndpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C3716519D607010017186B /* MIKMIDIClientDestinationEndpoint.h */; settings = {ATTRIBUTES = (Public, ); }; };
83C3716819D607010017186B /* MIKMIDIClientDestinationEndpoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 83C3716619D607010017186B /* MIKMIDIClientDestinationEndpoint.m */; };
9D2ED25F1AFBD062000325CC /* MIKMIDIResponderChainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */; };
9D3781561AA407A7007A61BE /* MIKMIDIResponder.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D74EF5817A713A100BEE89F /* MIKMIDIResponder.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D4DF13F1AAB57430065F004 /* MIKMIDI_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4DF13E1AAB57430065F004 /* MIKMIDI_Tests.m */; };
9D4DF1401AAB57430065F004 /* MIKMIDI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D74EEA517A7129300BEE89F /* MIKMIDI.framework */; };
Expand Down Expand Up @@ -330,14 +331,15 @@
83BC19BA1A23CD0D004F384F /* MIKMIDIMetronome.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMetronome.m; sourceTree = "<group>"; };
83C3716519D607010017186B /* MIKMIDIClientDestinationEndpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIClientDestinationEndpoint.h; sourceTree = "<group>"; };
83C3716619D607010017186B /* MIKMIDIClientDestinationEndpoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIClientDestinationEndpoint.m; sourceTree = "<group>"; };
9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMacDebugQuickLookSupport.m; sourceTree = "<group>"; };
9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIResponderChainTests.m; sourceTree = "<group>"; };
9D4DF13A1AAB57430065F004 /* MIKMIDI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "MIKMIDI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
9D4DF13D1AAB57430065F004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9D4DF13E1AAB57430065F004 /* MIKMIDI_Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MIKMIDI_Tests.m; sourceTree = "<group>"; };
9D4DF14C1AAB57800065F004 /* MIKMIDISequenceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDISequenceTests.m; sourceTree = "<group>"; };
9D4DF14E1AAB57C90065F004 /* bach.mid */ = {isa = PBXFileReference; lastKnownFileType = audio.midi; path = bach.mid; sourceTree = "<group>"; };
9D4DF1531AAB60490065F004 /* MIKMIDITrackTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDITrackTests.m; sourceTree = "<group>"; };
9D5946CD1A9FA7C200B5ACFB /* MIKMIDISynthesizer_SubclassMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIKMIDISynthesizer_SubclassMethods.h; sourceTree = "<group>"; };
9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMacDebugQuickLookSupport.m; sourceTree = "<group>"; };
9D74EEA517A7129300BEE89F /* MIKMIDI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MIKMIDI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9D74EEA817A7129300BEE89F /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
9D74EEAB17A7129300BEE89F /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -486,29 +488,14 @@
name = Files;
sourceTree = "<group>";
};
9D7027D11ACC9D4C009AFAED /* Debugging */ = {
isa = PBXGroup;
children = (
9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */,
);
name = Debugging;
sourceTree = "<group>";
};
9D7027D11ACC9D4C009AFAED /* Debugging */ = {
isa = PBXGroup;
children = (
9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */,
);
name = Debugging;
sourceTree = "<group>";
};
9D4DF13B1AAB57430065F004 /* MIKMIDI Tests */ = {
isa = PBXGroup;
children = (
9D4DF13E1AAB57430065F004 /* MIKMIDI_Tests.m */,
9D4DF14C1AAB57800065F004 /* MIKMIDISequenceTests.m */,
9D4DF1531AAB60490065F004 /* MIKMIDITrackTests.m */,
9DCDDB591AB3514100F8347E /* MIKMIDISequencerTests.m */,
9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */,
9D4DF13C1AAB57430065F004 /* Supporting Files */,
9D4DF1501AAB57CD0065F004 /* Resources */,
);
Expand All @@ -532,6 +519,14 @@
name = Resources;
sourceTree = "<group>";
};
9D7027D11ACC9D4C009AFAED /* Debugging */ = {
isa = PBXGroup;
children = (
9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */,
);
name = Debugging;
sourceTree = "<group>";
};
9D74EE9B17A7129300BEE89F = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1091,6 +1086,7 @@
files = (
9DCDDB5A1AB3514100F8347E /* MIKMIDISequencerTests.m in Sources */,
9D4DF13F1AAB57430065F004 /* MIKMIDI_Tests.m in Sources */,
9D2ED25F1AFBD062000325CC /* MIKMIDIResponderChainTests.m in Sources */,
9D4DF14D1AAB57800065F004 /* MIKMIDISequenceTests.m in Sources */,
9D4DF1541AAB60490065F004 /* MIKMIDITrackTests.m in Sources */,
);
Expand Down

0 comments on commit 5dba0e0

Please sign in to comment.