diff --git a/Framework/MIKMIDI Tests/MIKMIDIResponderChainTests.m b/Framework/MIKMIDI Tests/MIKMIDIResponderChainTests.m new file mode 100644 index 00000000..11e6b001 --- /dev/null +++ b/Framework/MIKMIDI Tests/MIKMIDIResponderChainTests.m @@ -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 +#import +#import + +@interface MIKMIDIDummyResponder : NSObject + +- (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 diff --git a/Framework/MIKMIDI.xcodeproj/project.pbxproj b/Framework/MIKMIDI.xcodeproj/project.pbxproj index a218f07f..5ef7b376 100644 --- a/Framework/MIKMIDI.xcodeproj/project.pbxproj +++ b/Framework/MIKMIDI.xcodeproj/project.pbxproj @@ -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 */; }; @@ -330,7 +331,7 @@ 83BC19BA1A23CD0D004F384F /* MIKMIDIMetronome.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMetronome.m; sourceTree = ""; }; 83C3716519D607010017186B /* MIKMIDIClientDestinationEndpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIClientDestinationEndpoint.h; sourceTree = ""; }; 83C3716619D607010017186B /* MIKMIDIClientDestinationEndpoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIClientDestinationEndpoint.m; sourceTree = ""; }; - 9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMacDebugQuickLookSupport.m; sourceTree = ""; }; + 9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIResponderChainTests.m; sourceTree = ""; }; 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 = ""; }; 9D4DF13E1AAB57430065F004 /* MIKMIDI_Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MIKMIDI_Tests.m; sourceTree = ""; }; @@ -338,6 +339,7 @@ 9D4DF14E1AAB57C90065F004 /* bach.mid */ = {isa = PBXFileReference; lastKnownFileType = audio.midi; path = bach.mid; sourceTree = ""; }; 9D4DF1531AAB60490065F004 /* MIKMIDITrackTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDITrackTests.m; sourceTree = ""; }; 9D5946CD1A9FA7C200B5ACFB /* MIKMIDISynthesizer_SubclassMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIKMIDISynthesizer_SubclassMethods.h; sourceTree = ""; }; + 9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMacDebugQuickLookSupport.m; sourceTree = ""; }; 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; }; @@ -486,22 +488,6 @@ name = Files; sourceTree = ""; }; - 9D7027D11ACC9D4C009AFAED /* Debugging */ = { - isa = PBXGroup; - children = ( - 9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */, - ); - name = Debugging; - sourceTree = ""; - }; - 9D7027D11ACC9D4C009AFAED /* Debugging */ = { - isa = PBXGroup; - children = ( - 9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */, - ); - name = Debugging; - sourceTree = ""; - }; 9D4DF13B1AAB57430065F004 /* MIKMIDI Tests */ = { isa = PBXGroup; children = ( @@ -509,6 +495,7 @@ 9D4DF14C1AAB57800065F004 /* MIKMIDISequenceTests.m */, 9D4DF1531AAB60490065F004 /* MIKMIDITrackTests.m */, 9DCDDB591AB3514100F8347E /* MIKMIDISequencerTests.m */, + 9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */, 9D4DF13C1AAB57430065F004 /* Supporting Files */, 9D4DF1501AAB57CD0065F004 /* Resources */, ); @@ -532,6 +519,14 @@ name = Resources; sourceTree = ""; }; + 9D7027D11ACC9D4C009AFAED /* Debugging */ = { + isa = PBXGroup; + children = ( + 9D7027D21ACC9D7A009AFAED /* MIKMIDIMacDebugQuickLookSupport.m */, + ); + name = Debugging; + sourceTree = ""; + }; 9D74EE9B17A7129300BEE89F = { isa = PBXGroup; children = ( @@ -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 */, );