From 3bb54d49435fd69a48bb589f21d55b24d462dca6 Mon Sep 17 00:00:00 2001 From: Tom Bogle Date: Fri, 15 Jun 2018 02:34:03 -0400 Subject: [PATCH] [Mac] Added unit tests for checkPlatform --- .../project.pbxproj | 4 + .../KeymanEngine4MacTests/KMEngineTests.m | 75 ++++++++++++++++ .../KeymanEngineTestsStaticHelperMethods.h | 1 + .../KeymanEngineTestsStaticHelperMethods.m | 6 ++ .../KeymanEngine4MacTests/PlatformTest.kmn | 80 ++++++++++++++++++ .../KeymanEngine4MacTests/PlatformTest.kmx | Bin 0 -> 4962 bytes 6 files changed, 166 insertions(+) create mode 100755 mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn create mode 100644 mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmx diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj b/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj index 22ae755b62..2aa2eef6c4 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 984C2B161A79CA4F0023F89D /* KVKFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 984C2B021A79CA4F0023F89D /* KVKFile.h */; settings = {ATTRIBUTES = (Public, ); }; }; 984C2B171A79CA4F0023F89D /* KVKFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 984C2B031A79CA4F0023F89D /* KVKFile.m */; }; 984C2B191A79CB020023F89D /* WindowsVKCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 984C2B181A79CB020023F89D /* WindowsVKCodes.h */; }; + E224323F20D37E97006940A1 /* PlatformTest.kmx in Resources */ = {isa = PBXBuildFile; fileRef = E224323E20D37E97006940A1 /* PlatformTest.kmx */; }; E22A5A1120113DC100233965 /* KMEngineTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E22A5A1020113DC100233965 /* KMEngineTests.m */; }; E22A5A142011402E00233965 /* KeymanEngineTestsStaticHelperMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = E22A5A132011402E00233965 /* KeymanEngineTestsStaticHelperMethods.m */; }; E2537D9A201641DA0069FEA6 /* TestMacEngine.kmx in Resources */ = {isa = PBXBuildFile; fileRef = E2537D99201641DA0069FEA6 /* TestMacEngine.kmx */; }; @@ -102,6 +103,7 @@ 984C2B021A79CA4F0023F89D /* KVKFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KVKFile.h; sourceTree = ""; }; 984C2B031A79CA4F0023F89D /* KVKFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KVKFile.m; sourceTree = ""; }; 984C2B181A79CB020023F89D /* WindowsVKCodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowsVKCodes.h; sourceTree = ""; }; + E224323E20D37E97006940A1 /* PlatformTest.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = PlatformTest.kmx; sourceTree = ""; }; E22A5A1020113DC100233965 /* KMEngineTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KMEngineTests.m; sourceTree = ""; }; E22A5A1220113F8100233965 /* KeymanEngineTestsStaticHelperMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeymanEngineTestsStaticHelperMethods.h; sourceTree = ""; }; E22A5A132011402E00233965 /* KeymanEngineTestsStaticHelperMethods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeymanEngineTestsStaticHelperMethods.m; sourceTree = ""; }; @@ -197,6 +199,7 @@ 984C2AE21A79C98D0023F89D /* Supporting Files */ = { isa = PBXGroup; children = ( + E224323E20D37E97006940A1 /* PlatformTest.kmx */, E2537D99201641DA0069FEA6 /* TestMacEngine.kmx */, 984C2AE31A79C98D0023F89D /* Info.plist */, ); @@ -361,6 +364,7 @@ buildActionMask = 2147483647; files = ( E2537D9A201641DA0069FEA6 /* TestMacEngine.kmx in Resources */, + E224323F20D37E97006940A1 /* PlatformTest.kmx in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m index 6678cad933..2570371631 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m +++ b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m @@ -269,4 +269,79 @@ NSString * names[nCombinations]; } } } + +// The following checkPlatform tests all use the PlatformTest KMX file based on PlatformTest.kmn +// (not included in the project itself, but available in the source repo for reference. This +// keyboard has been craefully crafted to check for all the "wrong" values first, for which checkPlatform +// should return NO, so while these tests are ostensibly testing for YES for the platform components that +// should match on a Mac, they are also testing for NO for all the other non-matching values. + +- (NSString *)checkPlatform_getOutputForKeystroke: (NSString*) character modifierFlags: (NSEventModifierFlags) flag keyCode:(unsigned short)code { + KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForPlatformTest]; + KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@""]; + NSString *lcChar = [character lowercaseString]; + NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:flag timestamp:0 windowNumber:0 context:nil characters:character charactersIgnoringModifiers:lcChar isARepeat:NO keyCode:code]; + NSArray *actions = [engine processEvent:event]; + XCTAssert(actions.count == 1, @"Expected 1 action"); + NSDictionary *action = actions[0]; + NSString *actionType = [[action allKeys] objectAtIndex:0]; + XCTAssert([actionType isEqualToString:Q_STR], @"Expected Q_STR action"); + NSString *output = [action objectForKey:actionType]; + return output; +} + +- (void)testCheckPlatform_native_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"u" modifierFlags:0 keyCode:kVK_ANSI_U]; + XCTAssert([output isEqualToString:@" Native"], @"Expected checkPlatform to return YES for native."); +} + +- (void)testCheckPlatform_NATIVE_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"U" modifierFlags:NSEventModifierFlagShift keyCode:kVK_ANSI_U]; + XCTAssert([output isEqualToString:@" Native"], @"Expected checkPlatform to return YES for NATIVE."); +} + +- (void)testCheckPlatform_hardware_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"p" modifierFlags:0 keyCode:kVK_ANSI_P]; + XCTAssert([output isEqualToString:@" Hardware"], @"Expected checkPlatform to return YES for hardware."); +} + +- (void)testCheckPlatform_HARDWARE_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"P" modifierFlags:NSEventModifierFlagShift keyCode:kVK_ANSI_P]; + XCTAssert([output isEqualToString:@" Hardware"], @"Expected checkPlatform to return YES for HARDWARE."); +} + +- (void)testCheckPlatform_desktop_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"I" modifierFlags:0 keyCode:kVK_ANSI_I]; + XCTAssert([output isEqualToString:@" Desktop"], @"Expected checkPlatform to return YES for desktop."); +} + +- (void)testCheckPlatform_Desktop_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"I" modifierFlags:NSEventModifierFlagShift keyCode:kVK_ANSI_I]; + XCTAssert([output isEqualToString:@" Desktop"], @"Expected checkPlatform to return YES for Desktop."); +} + +- (void)testCheckPlatform_macosx_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"o" modifierFlags:0 keyCode:kVK_ANSI_O]; + XCTAssert([output isEqualToString:@" macOS"], @"Expected checkPlatform to return YES for macosx."); +} + +- (void)testCheckPlatform_MacOS_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"K" modifierFlags:NSEventModifierFlagShift keyCode:kVK_ANSI_K]; + XCTAssert([output isEqualToString:@" macOS"], @"Expected checkPlatform to return YES for MacOS."); +} + +- (void)testCheckPlatform_MAC_ReturnsYes { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"L" modifierFlags:NSEventModifierFlagShift keyCode:kVK_ANSI_L]; + XCTAssert([output isEqualToString:@" mac"], @"Expected checkPlatform to return YES for MAC."); +} + +- (void)testCheckPlatform_Browsers_ReturnsNo { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"y" modifierFlags:0 keyCode:kVK_ANSI_Y]; + XCTAssert([output isEqualToString:@" [Browser Undefined]"], @"Expected checkPlatform to return NO for all browsers (ie, chrome, firefox, safari, opera)."); +} + +- (void)testCheckPlatform_multipleTokens_MatchesCorrectOneForMac { + NSString *output = [self checkPlatform_getOutputForKeystroke:@"m" modifierFlags:0 keyCode:kVK_ANSI_M]; + XCTAssert([output isEqualToString:@" macOS native desktop hardware"], @"Expected checkPlatform to return YES for macOS native desktop hardware."); +} @end diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.h b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.h index 3e4c6fe7f6..a58f1f5953 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.h +++ b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.h @@ -21,6 +21,7 @@ @interface KeymanEngineTestsStaticHelperMethods : NSObject + (KMXFile *)getKmxFileTestMacEngine; ++ (KMXFile *)getKmxFileForPlatformTest; @end #endif /* KeymanEngineTestsStaticHelperMethods_h */ diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.m b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.m index 6806fb63f5..f2b32bc2b2 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.m +++ b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KeymanEngineTestsStaticHelperMethods.m @@ -16,4 +16,10 @@ KMXFile *kmxFile = [[KMXFile alloc] initWithFilePath:path]; return kmxFile; } + ++ (KMXFile *)getKmxFileForPlatformTest { + NSString *path = [[NSBundle bundleForClass:[KeymanEngineTestsStaticHelperMethods class]] pathForResource:@"PlatformTest.kmx" ofType:nil]; + KMXFile *kmxFile = [[KMXFile alloc] initWithFilePath:path]; + return kmxFile; +} @end diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn new file mode 100755 index 0000000000..265df6d634 --- /dev/null +++ b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn @@ -0,0 +1,80 @@ +store(&TARGETS) 'any' +store(&NAME) 'PlatformTest' +begin Unicode > use(main) + +group(main) using keys + +platform('touch') + [K_P] > ' Touch' +platform('hardware') + [K_P] > ' Hardware' ++ [K_P] > ' [UI Undefined]' + +platform('TOUCH') + [SHIFT K_P] > ' Touch' +platform('HARDWARE') + [SHIFT K_P] > ' Hardware' ++ [SHIFT K_P] > ' [UI Undefined]' + +platform('windows') + [K_O] > ' Windows' +platform('android') + [K_O] > ' Android' +platform('iOS') + [K_O] > ' iOS' +platform('linux') + [K_O] > ' Linux' +platform('macosx') + [K_O] > ' macOS' ++ [K_O] > ' [OS Undefined]' + +platform('WINDOWS') + [SHIFT K_O] > ' Windows' +platform('ANDROID') + [SHIFT K_O] > ' Android' +platform('IOS') + [SHIFT K_O] > ' iOS' +platform('LINUX') + [SHIFT K_O] > ' Linux' +platform('MacOSX') + [SHIFT K_O] > ' macOS' ++ [SHIFT K_O] > ' [OS Undefined]' + +platform('mac') + [K_L] > ' mac' ++ [K_L] > ' [Not a mac]' +platform('MAC') + [SHIFT K_L] > ' mac' ++ [SHIFT K_L] > ' [Not a mac]' +platform('macos') + [K_K] > ' macOS' ++ [K_K] > ' [Not macos]' +platform('MacOS') + [SHIFT K_K] > ' macOS' ++ [SHIFT K_K] > ' [Not macos]' + +platform('tablet') + [K_I] > ' Tablet' +platform('phone') + [K_I] > ' Phone' +platform('desktop') + [K_I] > ' Desktop' ++ [K_I] > ' [FF Undefined]' + +platform('TABLET') + [SHIFT K_I] > ' Tablet' +platform('Phone') + [SHIFT K_I] > ' Phone' +platform('DeskTop') + [SHIFT K_I] > ' Desktop' ++ [SHIFT K_I] > ' [FF Undefined]' + +platform('web') + [K_U] > ' Web' +platform('native') + [K_U] > ' Native' ++ [K_U] > ' [Nativeness Undefined]' + +platform('Web') + [SHIFT K_U] > ' Web' +platform('NATIVE') + [SHIFT K_U] > ' Native' ++ [SHIFT K_U] > ' [Nativeness Undefined]' + +platform('ie') + [K_Y] > ' IE' +platform('chrome') + [K_Y] > ' Chrome' +platform('firefox') + [K_Y] > ' Firefox' +platform('safari') + [K_Y] > ' Safari' +platform('opera') + [K_Y] > ' Opera' ++ [K_Y] > ' [Browser Undefined]' + +platform('IE') + [SHIFT K_Y] > ' IE' +platform('Chrome') + [SHIFT K_Y] > ' Chrome' +platform('FireFox') + [SHIFT K_Y] > ' Firefox' +platform('Safari') + [SHIFT K_Y] > ' Safari' +platform('OPERA') + [SHIFT K_Y] > ' Opera' ++ [SHIFT K_Y] > ' [Browser Undefined]' + +platform('tablet') + [K_T] > ' Mobile' +platform('phone') + [K_T] > ' Mobile' ++ [K_T] > ' [Mobile Undefined]' + +platform('tablet ie web') + [K_M] > ' tablet ie web' +platform('touch phone safari web') + [K_M] > ' phone safari web' +platform('Windows desktop native hardware') + [K_M] > ' Windows desktop native hardware' +platform('Linux desktop native') + [K_M] > ' Linux desktop native' +platform('macOS native desktop hardware Safari') + [K_M] > ' macOS native hardware Safari' +platform('macOS native desktop hardware') + [K_M] > ' macOS native desktop hardware' ++ [K_M] > ' [No match]' diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmx b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmx new file mode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