mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-01 08:23:35 +00:00
Previously, every AppKit tests used the same sharedApplication. Due to this implementation, a could not pass because a previous test made failed the current test. For instance, a test could fail because the window of the previous test resigned (just imagine a new window is the key window in the current test), and this resign could raise an error. The error was displayed for the current test thought this test was perfect ! We now instead of using sharedApplication create a new CPApplication per unit-test file in the class method setUp.
84 lines
2.9 KiB
Plaintext
84 lines
2.9 KiB
Plaintext
@import <AppKit/CPApplication.j>
|
|
@import <AppKit/CPWindow.j>
|
|
@import <AppKit/CPEvent.j>
|
|
@import <AppKit/CPButton.j>
|
|
|
|
@implementation CPKeyEquivalentPerformance : OJTestCase
|
|
{
|
|
|
|
}
|
|
|
|
+ (void)setUp
|
|
{
|
|
// This will init the global var CPApp which are used internally in the AppKit
|
|
[[CPApplication alloc] init];
|
|
}
|
|
|
|
- (void)testKeyEquivalentSpeed
|
|
{
|
|
var REPEATS = 1000,
|
|
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,200,150)
|
|
styleMask:CPWindowNotSizable],
|
|
contentView = [theWindow contentView],
|
|
subView1 = [[CPView alloc] initWithFrame:CGRectMakeZero()],
|
|
subView2 = [[CPView alloc] initWithFrame:CGRectMakeZero()],
|
|
button1 = [CPButton buttonWithTitle:"when"],
|
|
button2 = [CPButton buttonWithTitle:"you have eliminated"],
|
|
button3 = [CPButton buttonWithTitle:"the impossible"];
|
|
|
|
[contentView addSubview:subView1];
|
|
[contentView addSubview:subView2];
|
|
[subView1 addSubview:button1];
|
|
[subView2 addSubview:button2];
|
|
[subView2 addSubview:button3];
|
|
|
|
[button1 setTarget:self];
|
|
[button1 setAction:@selector(clicked:)];
|
|
[button1 setKeyEquivalent:"a"];
|
|
[button1 setKeyEquivalentModifierMask:CPControlKeyMask];
|
|
button1.clicks = 0;
|
|
|
|
[button2 setTarget:self];
|
|
[button2 setAction:@selector(clicked:)];
|
|
[button2 setKeyEquivalent:"a"];
|
|
[button2 setKeyEquivalentModifierMask:CPAlternateKeyMask | CPCommandKeyMask];
|
|
button2.clicks = 0;
|
|
|
|
[button3 setTarget:self];
|
|
[button3 setAction:@selector(clicked:)];
|
|
[button3 setKeyEquivalent:"A"];
|
|
[button3 setKeyEquivalentModifierMask:CPControlKeyMask];
|
|
button3.clicks = 0;
|
|
|
|
var start = (new Date).getTime();
|
|
|
|
for (var i = 0; i < REPEATS; i++)
|
|
{
|
|
[theWindow sendEvent:[CPEvent keyEventWithType:CPKeyDown location:CGPointMakeZero() modifierFlags:CPControlKeyMask
|
|
timestamp:0 windowNumber:0 context:nil
|
|
characters:"a" charactersIgnoringModifiers:"a" isARepeat:NO keyCode:0]];
|
|
[theWindow sendEvent:[CPEvent keyEventWithType:CPKeyDown location:CGPointMakeZero() modifierFlags:CPAlternateKeyMask | CPCommandKeyMask
|
|
timestamp:0 windowNumber:0 context:nil
|
|
characters:"a" charactersIgnoringModifiers:"a" isARepeat:NO keyCode:0]];
|
|
[theWindow sendEvent:[CPEvent keyEventWithType:CPKeyDown location:CGPointMakeZero() modifierFlags:CPControlKeyMask | CPShiftKeyMask
|
|
timestamp:0 windowNumber:0 context:nil
|
|
characters:"a" charactersIgnoringModifiers:"a" isARepeat:NO keyCode:0]];
|
|
}
|
|
|
|
var end = (new Date).getTime();
|
|
|
|
[self assert:REPEATS equals:button1.clicks message:"button1"];
|
|
[self assert:REPEATS equals:button2.clicks message:"button2"];
|
|
[self assert:REPEATS equals:button3.clicks message:"button3"];
|
|
|
|
CPLog.warn("testKeyEquivalentSpeed: "+(end-start)+"ms");
|
|
|
|
}
|
|
|
|
- (void)clicked:(id)sender
|
|
{
|
|
sender.clicks++;
|
|
}
|
|
|
|
@end
|