PageRenderTime 46ms CodeModel.GetById 10ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 1ms

/core/externals/google-toolbox-for-mac/AppKit/GTMLargeTypeWindowTest.m

http://macfuse.googlecode.com/
Objective C | 194 lines | 154 code | 19 blank | 21 comment | 4 complexity | 7202b055ff10b1f392290c3c7cae9c2a MD5 | raw file
  1//
  2//  GTMLargeTypeWindowTest.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 "GTMSenTestCase.h"
 20#import "GTMLargeTypeWindow.h"
 21#import "GTMNSObject+UnitTesting.h"
 22#import "GTMUnitTestDevLog.h"
 23#import "GTMSystemVersion.h"
 24
 25NSString *const kLongTextBlock = 
 26  @"`Twas brillig, and the slithy toves "
 27  "Did gyre and gimble in the wabe: "
 28  "all mimsy were the borogoves, "
 29  "and the mome raths outgrabe. "
 30  "Beware the Jabberwock, my son! "
 31  "The jaws that bite, the claws that catch! "
 32  "Beware the Jubjub bird, and shun "
 33  "the frumious Bandersnatch! "
 34  "He took his vorpal sword in hand: "
 35  "long time the manxome foe he sought -- "
 36  "so rested he by the Tumtum tree, "
 37  "and stood awhile in thought. "
 38  "And, as in uffish thought he stood, "
 39  "the Jabberwock, with eyes of flame, "
 40  "came whiffling through the tulgey wood, "
 41  "and burbled as it came! "
 42  "One, two! One, two! And through and through "
 43  "the vorpal blade went snicker-snack! "
 44  "He left it dead, and with its head "
 45  "he went galumphing back. "
 46  "And, has thou slain the Jabberwock? "
 47  "Come to my arms, my beamish boy! "
 48  "O frabjous day! Callooh! Callay! "
 49  "He chortled in his joy.";
 50
 51NSString *const kMediumTextBlock = @"For the Snark was a Boojum, you see.";
 52
 53NSString *const kShortTextBlock = @"Short";
 54
 55@interface GTMLargeTypeWindowTest : GTMTestCase
 56@end
 57
 58@implementation GTMLargeTypeWindowTest
 59- (BOOL)shouldDoAnimateCopy {
 60  // This method previously checked for incompatibilities with garbage collection.
 61  return YES;
 62}
 63
 64- (void)setUp {
 65  [GTMLargeTypeWindow setCopyAnimationDuration:0];
 66  [GTMLargeTypeWindow setFadeAnimationDuration:0];
 67}
 68
 69- (void)tearDown {
 70  [GTMLargeTypeWindow setCopyAnimationDuration:0.5];
 71  [GTMLargeTypeWindow setFadeAnimationDuration:0.333];
 72}
 73
 74- (void)testLargeTypeWindowIllegalInits {
 75  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty string"];
 76  GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc] 
 77                                 initWithString:@""] autorelease];
 78  STAssertNil(window, nil);
 79  
 80  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty string"];
 81  window = [[[GTMLargeTypeWindow alloc] initWithString:nil] autorelease];
 82  STAssertNil(window, nil);
 83  
 84  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty string"];
 85  NSAttributedString *attrString = [[[NSAttributedString alloc] 
 86                                     initWithString:@""] autorelease];
 87  window = [[[GTMLargeTypeWindow alloc] 
 88             initWithAttributedString:attrString] autorelease];
 89  STAssertNil(window, nil);
 90  
 91  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty string"];
 92  window = [[[GTMLargeTypeWindow alloc] 
 93             initWithAttributedString:nil] autorelease];
 94  STAssertNil(window, nil);
 95
 96  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty view"];
 97  window = [[[GTMLargeTypeWindow alloc] initWithContentView:nil] autorelease];
 98  STAssertNil(window, nil);
 99
100  [GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty image"];
101  window = [[[GTMLargeTypeWindow alloc] initWithImage:nil] autorelease];
102  STAssertNil(window, nil);
103}
104
105- (void)testLargeTypeWindowMediumText {
106  GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc] 
107                                 initWithString:kMediumTextBlock] autorelease];
108  STAssertNotNil(window, nil);
109  STAssertTrue([window canBecomeKeyWindow], nil);
110  [window makeKeyAndOrderFront:nil];
111  NSDate *endDate 
112    = [NSDate dateWithTimeIntervalSinceNow:.1];
113  [[NSRunLoop currentRunLoop] runUntilDate:endDate];
114  GTMAssertObjectStateEqualToStateNamed(window, 
115                                        @"GTMLargeTypeWindowMediumTextTest",
116                                        nil); 
117  if ([self shouldDoAnimateCopy]) {
118    [window copy:nil];
119    NSPasteboard *pb = [NSPasteboard generalPasteboard];
120    NSString *pbString = [pb stringForType:NSStringPboardType];
121    STAssertEqualObjects(pbString, kMediumTextBlock, nil);
122  }
123  [window keyDown:nil];
124}
125
126- (void)testLargeTypeWindowShortText {
127  GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc] 
128                                 initWithString:kShortTextBlock] autorelease];
129  STAssertNotNil(window, nil);
130  STAssertTrue([window canBecomeKeyWindow], nil);
131  [window makeKeyAndOrderFront:nil];
132  NSDate *endDate 
133    = [NSDate dateWithTimeIntervalSinceNow:.1];
134  [[NSRunLoop currentRunLoop] runUntilDate:endDate];
135  GTMAssertObjectStateEqualToStateNamed(window, 
136                                        @"GTMLargeTypeWindowShortTextTest",
137                                        nil); 
138  if ([self shouldDoAnimateCopy]) {
139    [window copy:nil];
140    NSPasteboard *pb = [NSPasteboard generalPasteboard];
141    NSString *pbString = [pb stringForType:NSStringPboardType];
142    STAssertEqualObjects(pbString, kShortTextBlock, nil);
143  }
144  [window resignKeyWindow];
145}
146
147- (void)testLargeTypeWindowLongText {
148  GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc] 
149                                 initWithString:kLongTextBlock] autorelease];
150  STAssertNotNil(window, nil);
151  [window orderFront:nil];
152  NSDate *endDate
153    = [NSDate dateWithTimeIntervalSinceNow:.1];
154  [[NSRunLoop currentRunLoop] runUntilDate:endDate];
155  // Can't do state for long text as it will wrap differently on different
156  // sized screens.
157  GTMAssertObjectStateEqualToStateNamed(window,
158                                        @"GTMLargeTypeWindowLongTextTest", 
159                                        nil); 
160  if ([self shouldDoAnimateCopy]) {
161    [window copy:nil];
162    NSPasteboard *pb = [NSPasteboard generalPasteboard];
163    NSString *pbString = [pb stringForType:NSStringPboardType];
164    STAssertEqualObjects(pbString, kLongTextBlock, nil);
165  }
166  [window keyDown:nil];
167}
168
169- (void)testLargeTypeWindowImageText {
170  NSImage *image = [NSApp applicationIconImage];
171  GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc] 
172                                 initWithImage:image] autorelease];
173  STAssertNotNil(window, nil);
174  [window makeKeyAndOrderFront:nil];
175  NSDate *endDate 
176    = [NSDate dateWithTimeIntervalSinceNow:.1];
177  [[NSRunLoop currentRunLoop] runUntilDate:endDate];
178  GTMAssertObjectStateEqualToStateNamed(window, 
179                                        @"GTMLargeTypeWindowImageTest",
180                                        nil);
181  NSString *testString = @"TestString";
182  NSPasteboard *pb = [NSPasteboard generalPasteboard];
183  [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
184  [pb setString:testString forType:NSStringPboardType];
185  if ([self shouldDoAnimateCopy]) {
186    [window copy:nil];
187    // Pasteboard should not change for an image
188    NSString *pbString = [pb stringForType:NSStringPboardType];
189    STAssertEqualObjects(pbString, testString, nil);
190  }
191  [window resignKeyWindow];
192}
193
194@end