Files
cappuccino/Tests/AppKit/CPLevelIndicatorTest.j
T
Alexandre Wilhelm 6fe9dae3d6 Fixed: AppKit unit-tests are not standalone
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.
2015-07-07 14:12:19 -07:00

97 lines
3.5 KiB
Plaintext

@import <AppKit/CPLevelIndicator.j>
// You should never do this. This is only for testing purposes.
#define GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, i) [(levelIndicator) layoutEphemeralSubviewNamed:@"segment-bezel-" + (i) positioned:CPWindowAbove relativeToEphemeralSubviewNamed:"bezel"]
@implementation CPLevelIndicatorTest : OJTestCase
{
}
+ (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
}
+ (CPLevelIndicator)indicatorWithLowWarning
{
var levelIndicator = [[CPLevelIndicator alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[levelIndicator setMinValue:0];
[levelIndicator setMaxValue:10];
[levelIndicator setWarningValue:4];
[levelIndicator setCriticalValue:2];
[levelIndicator setValue:[CPColor greenColor] forThemeAttribute:@"color-normal"];
[levelIndicator setValue:[CPColor yellowColor] forThemeAttribute:@"color-warning"];
[levelIndicator setValue:[CPColor redColor] forThemeAttribute:@"color-critical"];
return levelIndicator;
}
+ (CPLevelIndicator)indicatorWithHighWarning
{
var levelIndicator = [self indicatorWithLowWarning];
[levelIndicator setWarningValue:6];
[levelIndicator setCriticalValue:8];
return levelIndicator;
}
- (void)testLevelIndicatorWithLowWarningAndCriticalShouldShowNormalColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithLowWarning];
[levelIndicator setObjectValue:5];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor greenColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
- (void)testLevelIndicatorWithLowWarningAndCriticalShouldShowWarningColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithLowWarning];
[levelIndicator setObjectValue:4];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor yellowColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
- (void)testLevelIndicatorWithLowWarningAndCriticalShouldShowCriticalColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithLowWarning];
[levelIndicator setObjectValue:2];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor redColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
- (void)testLevelIndicatorWithHighWarningAndCriticalShouldShowNormalColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithHighWarning];
[levelIndicator setObjectValue:5];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor greenColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
- (void)testLevelIndicatorWithHighWarningAndCriticalShouldShowWarningColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithHighWarning];
[levelIndicator setObjectValue:6];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor yellowColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
- (void)testLevelIndicatorWithHighWarningAndCriticalShouldShowCriticalColor
{
var levelIndicator = [CPLevelIndicatorTest indicatorWithHighWarning];
[levelIndicator setObjectValue:8];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self assert:[CPColor redColor] equals:[GET_LEVEL_INDICATOR_SEGMENT(levelIndicator, 0) backgroundColor]];
}
@end