/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. #import <Cocoa/Cocoa.h>
  19. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  20. #import "GTMSenTestCase.h"
  21. #import "GTMNSColor+Luminance.h"
  22. @interface GTMNSColor_LuminanceTest : GTMTestCase
  23. @end
  24. @implementation GTMNSColor_LuminanceTest
  25. - (void)testLuminance {
  26. NSColor *midtone = [NSColor blueColor];
  27. NSColor *darker = [midtone gtm_colorAdjustedFor:GTMColorationBaseShadow];
  28. NSColor *lighter = [midtone gtm_colorAdjustedFor:GTMColorationBaseHighlight];
  29. NSColor *lightest = [midtone gtm_colorAdjustedFor:GTMColorationLightHighlight];
  30. NSColor *darkest = [midtone gtm_colorAdjustedFor:GTMColorationDarkShadow];
  31. // The relationships of the other values are not set, so we don't test them yet
  32. STAssertGreaterThanOrEqual([lightest gtm_luminance],
  33. [lighter gtm_luminance], nil);
  34. STAssertGreaterThanOrEqual([lighter gtm_luminance],
  35. [midtone gtm_luminance], nil);
  36. STAssertGreaterThanOrEqual([midtone gtm_luminance],
  37. [darker gtm_luminance], nil);
  38. STAssertGreaterThanOrEqual([darker gtm_luminance],
  39. [darkest gtm_luminance], nil);
  40. STAssertGreaterThanOrEqual([[NSColor whiteColor] gtm_luminance],
  41. (CGFloat)0.95, nil);
  42. STAssertGreaterThanOrEqual([[NSColor yellowColor] gtm_luminance],
  43. (CGFloat)0.90, nil);
  44. STAssertEqualsWithAccuracy([[NSColor blueColor] gtm_luminance],
  45. (CGFloat)0.35, 0.10, nil);
  46. STAssertEqualsWithAccuracy([[NSColor redColor] gtm_luminance],
  47. (CGFloat)0.50, 0.10, nil);
  48. STAssertLessThanOrEqual([[NSColor blackColor] gtm_luminance],
  49. (CGFloat)0.30, nil);
  50. STAssertTrue([[NSColor blackColor] gtm_isDarkColor], nil);
  51. STAssertTrue([[NSColor blueColor] gtm_isDarkColor], nil);
  52. STAssertTrue([[NSColor redColor] gtm_isDarkColor], nil);
  53. STAssertTrue(![[NSColor whiteColor] gtm_isDarkColor], nil);
  54. STAssertTrue(![[NSColor yellowColor] gtm_isDarkColor], nil);
  55. STAssertGreaterThanOrEqual([[[NSColor blackColor] gtm_legibleTextColor]
  56. gtm_luminance],
  57. [[NSColor grayColor] gtm_luminance], nil);
  58. STAssertLessThanOrEqual([[[NSColor whiteColor] gtm_legibleTextColor]
  59. gtm_luminance],
  60. [[NSColor grayColor] gtm_luminance], nil);
  61. }
  62. @end
  63. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5