PageRenderTime 35ms CodeModel.GetById 14ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/AppKit/GTMNSColor+LuminanceTest.m

http://macfuse.googlecode.com/
Objective C | 72 lines | 45 code | 9 blank | 18 comment | 0 complexity | a2d4887680676a4d86cb3cbbb4016eee MD5 | raw file
 1//
 2//  GTMNSColor+LuminanceTest.m
 3//
 4//  Copyright 2006-2009 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import <Cocoa/Cocoa.h>
20
21#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
22
23#import "GTMSenTestCase.h"
24#import "GTMNSColor+Luminance.h"
25
26@interface GTMNSColor_LuminanceTest : GTMTestCase
27@end
28  
29@implementation GTMNSColor_LuminanceTest
30
31- (void)testLuminance {
32  NSColor *midtone = [NSColor blueColor];
33  NSColor *darker = [midtone gtm_colorAdjustedFor:GTMColorationBaseShadow];
34  NSColor *lighter = [midtone gtm_colorAdjustedFor:GTMColorationBaseHighlight];
35  NSColor *lightest = [midtone gtm_colorAdjustedFor:GTMColorationLightHighlight];
36  NSColor *darkest = [midtone gtm_colorAdjustedFor:GTMColorationDarkShadow];
37  
38  // The relationships of the other values are not set, so we don't test them yet
39  STAssertGreaterThanOrEqual([lightest gtm_luminance], 
40                             [lighter gtm_luminance], nil);
41  STAssertGreaterThanOrEqual([lighter gtm_luminance], 
42                             [midtone gtm_luminance], nil);
43  STAssertGreaterThanOrEqual([midtone gtm_luminance], 
44                             [darker gtm_luminance], nil);
45  STAssertGreaterThanOrEqual([darker gtm_luminance], 
46                             [darkest gtm_luminance], nil);
47  STAssertGreaterThanOrEqual([[NSColor whiteColor] gtm_luminance], 
48                             (CGFloat)0.95, nil);
49  STAssertGreaterThanOrEqual([[NSColor yellowColor] gtm_luminance], 
50                             (CGFloat)0.90, nil);
51  STAssertEqualsWithAccuracy([[NSColor blueColor] gtm_luminance], 
52                             (CGFloat)0.35, 0.10, nil);
53  STAssertEqualsWithAccuracy([[NSColor redColor] gtm_luminance], 
54                             (CGFloat)0.50, 0.10, nil);
55  STAssertLessThanOrEqual([[NSColor blackColor] gtm_luminance], 
56                          (CGFloat)0.30, nil);
57  STAssertTrue([[NSColor blackColor] gtm_isDarkColor], nil);
58  STAssertTrue([[NSColor blueColor] gtm_isDarkColor], nil);
59  STAssertTrue([[NSColor redColor] gtm_isDarkColor], nil);
60  STAssertTrue(![[NSColor whiteColor] gtm_isDarkColor], nil);
61  STAssertTrue(![[NSColor yellowColor] gtm_isDarkColor], nil);
62  STAssertGreaterThanOrEqual([[[NSColor blackColor] gtm_legibleTextColor]
63                               gtm_luminance],
64                             [[NSColor grayColor] gtm_luminance], nil);
65  STAssertLessThanOrEqual([[[NSColor whiteColor] gtm_legibleTextColor]
66                               gtm_luminance],
67                             [[NSColor grayColor] gtm_luminance], nil);
68}
69
70@end
71
72#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5