/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMNSImage+ScalingTest.m

http://macfuse.googlecode.com/ · Objective C · 83 lines · 47 code · 14 blank · 22 comment · 0 complexity · 123b605741dc7c95aaf6699fa8d2ffc9 MD5 · raw file

  1. //
  2. // GTMNSImage+ScalingTest.m
  3. //
  4. // Copyright 2006-2008 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. #import "GTMSenTestCase.h"
  20. #import "GTMNSImage+Scaling.h"
  21. #import "GTMGeometryUtils.h"
  22. @interface GTMNSImage_ScalingTest : GTMTestCase
  23. @end
  24. @implementation GTMNSImage_ScalingTest
  25. - (void)testScaling {
  26. NSImage *testImage = [NSImage imageNamed:@"NSApplicationIcon"];
  27. NSImageRep *rep = nil;
  28. NSRect bestRepRect = NSMakeRect(0, 0, 99, 99);
  29. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  30. rep = [testImage bestRepresentationForRect:bestRepRect
  31. context:nil
  32. hints:nil];
  33. #else
  34. rep = [testImage gtm_bestRepresentationForSize:bestRepRect.size];
  35. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  36. STAssertTrue(NSEqualSizes([rep size], NSMakeSize(128, 128)), nil);
  37. [testImage gtm_createIconRepresentations];
  38. STAssertNotNil([testImage gtm_representationOfSize:NSMakeSize(16, 16)], nil);
  39. STAssertNotNil([testImage gtm_representationOfSize:NSMakeSize(32, 32)], nil);
  40. NSImage *duplicate = [testImage gtm_duplicateOfSize:NSMakeSize(48, 48)];
  41. bestRepRect = NSMakeRect(0, 0, 48, 48);
  42. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  43. rep = [duplicate bestRepresentationForRect:bestRepRect
  44. context:nil
  45. hints:nil];
  46. #else
  47. rep = [duplicate gtm_bestRepresentationForSize:bestRepRect.size];
  48. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  49. STAssertTrue(NSEqualSizes([rep size], NSMakeSize(48, 48)),
  50. @"Size is %@", NSStringFromSize([rep size]));
  51. // This should IMHO return 48,48 on both 10.6 and 10.5. It makes no sense
  52. // at all that it returns 32,32 on 10_6 when the above code works for 48,48.
  53. // rdar://8052200 "NSImage bestRepresentationForRect:context:hints: doesn't
  54. // return the best rep"
  55. // http://openradar.appspot.com/radar?id=394401
  56. bestRepRect = NSMakeRect(0, 0, 50, 50);
  57. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  58. rep = [duplicate bestRepresentationForRect:bestRepRect
  59. context:nil
  60. hints:nil];
  61. STAssertFalse(NSEqualSizes([rep size], NSMakeSize(48, 48)),
  62. @"Size is %@", NSStringFromSize([rep size]));
  63. #else
  64. rep = [duplicate gtm_bestRepresentationForSize:bestRepRect.size];
  65. STAssertTrue(NSEqualSizes([rep size], NSMakeSize(48, 48)),
  66. @"Size is %@", NSStringFromSize([rep size]));
  67. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  68. }
  69. @end