PageRenderTime 28ms CodeModel.GetById 12ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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