mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-06 14:07:32 +00:00
[Mac] Added unit tests for checkPlatform
This commit is contained in:
parent
7857e34676
commit
3bb54d4943
6 changed files with 166 additions and 0 deletions
|
|
@ -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 = "<group>"; };
|
||||
984C2B031A79CA4F0023F89D /* KVKFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KVKFile.m; sourceTree = "<group>"; };
|
||||
984C2B181A79CB020023F89D /* WindowsVKCodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowsVKCodes.h; sourceTree = "<group>"; };
|
||||
E224323E20D37E97006940A1 /* PlatformTest.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = PlatformTest.kmx; sourceTree = "<group>"; };
|
||||
E22A5A1020113DC100233965 /* KMEngineTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KMEngineTests.m; sourceTree = "<group>"; };
|
||||
E22A5A1220113F8100233965 /* KeymanEngineTestsStaticHelperMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeymanEngineTestsStaticHelperMethods.h; sourceTree = "<group>"; };
|
||||
E22A5A132011402E00233965 /* KeymanEngineTestsStaticHelperMethods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeymanEngineTestsStaticHelperMethods.m; sourceTree = "<group>"; };
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
@interface KeymanEngineTestsStaticHelperMethods : NSObject
|
||||
+ (KMXFile *)getKmxFileTestMacEngine;
|
||||
+ (KMXFile *)getKmxFileForPlatformTest;
|
||||
@end
|
||||
|
||||
#endif /* KeymanEngineTestsStaticHelperMethods_h */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
80
mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn
Executable file
80
mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmn
Executable file
|
|
@ -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]'
|
||||
BIN
mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmx
Normal file
BIN
mac/KeymanEngine4Mac/KeymanEngine4MacTests/PlatformTest.kmx
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue