PageRenderTime 49ms CodeModel.GetById 6ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 108 lines | 68 code | 18 blank | 22 comment | 0 complexity | 78cdeea3268495ca158015212e28f78b MD5 | raw file
  1//  GTMFadeTruncatingTextFieldCellTest.m
  2//
  3//  Copyright 2009 Google Inc.
  4//
  5//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6//  use this file except in compliance with the License.  You may obtain a copy
  7//  of the License at
  8//
  9//  http://www.apache.org/licenses/LICENSE-2.0
 10//
 11//  Unless required by applicable law or agreed to in writing, software
 12//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 13//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 14//  License for the specific language governing permissions and limitations under
 15//  the License.
 16//
 17
 18#import "GTMDefines.h"
 19
 20#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
 21
 22#import "GTMSenTestCase.h"
 23#import "GTMAppKit+UnitTesting.h"
 24#import "GTMFadeTruncatingTextFieldCell.h"
 25
 26@interface GTMFadeTruncatingTextFieldCellTest : GTMTestCase
 27@end
 28
 29@implementation GTMFadeTruncatingTextFieldCellTest
 30
 31- (void)testFadeCellRight {
 32  NSTextField *field = [[[NSTextField alloc] initWithFrame:
 33                         NSMakeRect(0, 0, 100, 16)] autorelease];
 34  [field setCell:[[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""]
 35                  autorelease]];
 36
 37  [field setStringValue:@"A very long string that won't fit"];
 38  GTMAssertObjectImageEqualToImageNamed(field,
 39                                        @"GTMFadeTruncatingTextFieldCellTest1",
 40                                        nil);
 41
 42  [field setStringValue:@"A short string"];
 43  GTMAssertObjectImageEqualToImageNamed(field,
 44                                        @"GTMFadeTruncatingTextFieldCellTest2",
 45                                        nil);
 46
 47  // Dark background, light text (force the background to draw (which is odd
 48  // for a text cell), but this is to make sure the support for light on dark
 49  // is tested.
 50  [field setTextColor:[NSColor whiteColor]];
 51  [field setDrawsBackground:YES];
 52  [field setBackgroundColor:[NSColor blackColor]];
 53
 54  [field setStringValue:@"A very long string that won't fit"];
 55  GTMAssertObjectImageEqualToImageNamed(field,
 56                                        @"GTMFadeTruncatingTextFieldCellTest3",
 57                                        nil);
 58  [field setStringValue:@"A short string"];
 59  GTMAssertObjectImageEqualToImageNamed(field,
 60                                        @"GTMFadeTruncatingTextFieldCellTest4",
 61                                        nil);
 62}
 63
 64- (void)testFadeCellLeftAndRight {
 65  NSTextField *field = [[[NSTextField alloc] initWithFrame:
 66                         NSMakeRect(0, 0, 100, 16)] autorelease];
 67  GTMFadeTruncatingTextFieldCell *cell =
 68      [[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""] autorelease];
 69  [cell setTruncateMode:GTMFadeTruncatingHeadAndTail];
 70  [cell setDesiredCharactersToTruncateFromHead:5];
 71  [field setCell:cell];
 72
 73  [field setStringValue:@"Fade on both left and right AAAA"];
 74  GTMAssertObjectImageEqualToImageNamed(field,
 75                                        @"GTMFadeTruncatingTextFieldCellTest5",
 76                                        nil);
 77
 78  [field setStringValue:@"Fade on left only A"];
 79  GTMAssertObjectImageEqualToImageNamed(field,
 80                                        @"GTMFadeTruncatingTextFieldCellTest6",
 81                                        nil);
 82
 83  [field setStringValue:@"A short string"];
 84  GTMAssertObjectImageEqualToImageNamed(field,
 85                                        @"GTMFadeTruncatingTextFieldCellTest2",
 86                                        nil);
 87
 88  // Test the case where the number of characters to truncate from head is not
 89  // specified. This should cause the string to be drawn centered.
 90  [cell setDesiredCharactersToTruncateFromHead:0];
 91  [field setStringValue:@"Fade on both left and right AAAA"];
 92  GTMAssertObjectImageEqualToImageNamed(field,
 93                                        @"GTMFadeTruncatingTextFieldCellTest7",
 94                                        nil);
 95
 96  // Border with a solid background color.
 97  [field setTextColor:[NSColor whiteColor]];
 98  [field setDrawsBackground:YES];
 99  [field setBackgroundColor:[NSColor blackColor]];
100  [field setBordered:YES];
101  GTMAssertObjectImageEqualToImageNamed(field,
102                                        @"GTMFadeTruncatingTextFieldCellTest8",
103                                        nil);
104}
105
106@end
107
108#endif  // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5