mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +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.
82 lines
3.4 KiB
Plaintext
82 lines
3.4 KiB
Plaintext
@import <AppKit/CPComboBox.j>
|
|
@import <AppKit/CPApplication.j>
|
|
@import <Foundation/Foundation.j>
|
|
|
|
@import "CPNotificationCenterHelper.j"
|
|
|
|
@implementation CPComboBoxTest : OJTestCase
|
|
{
|
|
CPComboBox comboBox;
|
|
BOOL wasClicked
|
|
}
|
|
|
|
+ (void)setUp
|
|
{
|
|
// This will init the global var CPApp which are used internally in the AppKit
|
|
[[CPApplication alloc] init];
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
comboBox = [[CPComboBox alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
|
|
}
|
|
|
|
- (void)testCanCreate
|
|
{
|
|
[self assertTrue:!!comboBox];
|
|
}
|
|
|
|
- (void)testPublicAccessors
|
|
{
|
|
[comboBox setHasVerticalScroller:YES];
|
|
[comboBox setIntercellSpacing:CGSizeMakeZero()];
|
|
[comboBox setButtonBordered:YES];
|
|
[comboBox setItemHeight:30];
|
|
[comboBox setNumberOfVisibleItems:10];
|
|
}
|
|
|
|
- (void)testPerformClick
|
|
{
|
|
[comboBox setTarget:self];
|
|
[comboBox setAction:@selector(clickMe:)];
|
|
[comboBox performClick:nil];
|
|
[self assertTrue:wasClicked];
|
|
}
|
|
|
|
- (void)clickMe:(id)sender
|
|
{
|
|
wasClicked = YES;
|
|
}
|
|
|
|
- (void)testNotificationsRegistered
|
|
{
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
[comboBox setListDelegate:[[_CPPopUpList alloc] initWithDataSource:comboBox]];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
|
|
styleMask:CPWindowNotSizable];
|
|
|
|
[[theWindow contentView] addSubview:comboBox];
|
|
|
|
var expectedNotifications = [@"_CPPopUpListWillPopUpNotification", @"_CPPopUpListWillDismissNotification", @"_CPPopUpListDidDismissNotification", @"_CPPopUpListItemWasClickedNotification", @"CPTableViewSelectionIsChangingNotification", @"CPTableViewSelectionDidChangeNotification"].sort();
|
|
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
[comboBox removeFromSuperview];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
[[theWindow contentView] addSubview:comboBox];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
[[theWindow contentView] addSubview:comboBox];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
[comboBox setListDelegate:nil];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
|
|
[comboBox setListDelegate:[[_CPPopUpList alloc] initWithDataSource:comboBox]];
|
|
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"];
|
|
}
|
|
|
|
@end |