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