PageRenderTime 29ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  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. #import "GTMDefines.h"
  18. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  19. #import "GTMSenTestCase.h"
  20. #import "GTMAppKit+UnitTesting.h"
  21. #import "GTMFadeTruncatingTextFieldCell.h"
  22. @interface GTMFadeTruncatingTextFieldCellTest : GTMTestCase
  23. @end
  24. @implementation GTMFadeTruncatingTextFieldCellTest
  25. - (void)testFadeCellRight {
  26. NSTextField *field = [[[NSTextField alloc] initWithFrame:
  27. NSMakeRect(0, 0, 100, 16)] autorelease];
  28. [field setCell:[[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""]
  29. autorelease]];
  30. [field setStringValue:@"A very long string that won't fit"];
  31. GTMAssertObjectImageEqualToImageNamed(field,
  32. @"GTMFadeTruncatingTextFieldCellTest1",
  33. nil);
  34. [field setStringValue:@"A short string"];
  35. GTMAssertObjectImageEqualToImageNamed(field,
  36. @"GTMFadeTruncatingTextFieldCellTest2",
  37. nil);
  38. // Dark background, light text (force the background to draw (which is odd
  39. // for a text cell), but this is to make sure the support for light on dark
  40. // is tested.
  41. [field setTextColor:[NSColor whiteColor]];
  42. [field setDrawsBackground:YES];
  43. [field setBackgroundColor:[NSColor blackColor]];
  44. [field setStringValue:@"A very long string that won't fit"];
  45. GTMAssertObjectImageEqualToImageNamed(field,
  46. @"GTMFadeTruncatingTextFieldCellTest3",
  47. nil);
  48. [field setStringValue:@"A short string"];
  49. GTMAssertObjectImageEqualToImageNamed(field,
  50. @"GTMFadeTruncatingTextFieldCellTest4",
  51. nil);
  52. }
  53. - (void)testFadeCellLeftAndRight {
  54. NSTextField *field = [[[NSTextField alloc] initWithFrame:
  55. NSMakeRect(0, 0, 100, 16)] autorelease];
  56. GTMFadeTruncatingTextFieldCell *cell =
  57. [[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""] autorelease];
  58. [cell setTruncateMode:GTMFadeTruncatingHeadAndTail];
  59. [cell setDesiredCharactersToTruncateFromHead:5];
  60. [field setCell:cell];
  61. [field setStringValue:@"Fade on both left and right AAAA"];
  62. GTMAssertObjectImageEqualToImageNamed(field,
  63. @"GTMFadeTruncatingTextFieldCellTest5",
  64. nil);
  65. [field setStringValue:@"Fade on left only A"];
  66. GTMAssertObjectImageEqualToImageNamed(field,
  67. @"GTMFadeTruncatingTextFieldCellTest6",
  68. nil);
  69. [field setStringValue:@"A short string"];
  70. GTMAssertObjectImageEqualToImageNamed(field,
  71. @"GTMFadeTruncatingTextFieldCellTest2",
  72. nil);
  73. // Test the case where the number of characters to truncate from head is not
  74. // specified. This should cause the string to be drawn centered.
  75. [cell setDesiredCharactersToTruncateFromHead:0];
  76. [field setStringValue:@"Fade on both left and right AAAA"];
  77. GTMAssertObjectImageEqualToImageNamed(field,
  78. @"GTMFadeTruncatingTextFieldCellTest7",
  79. nil);
  80. // Border with a solid background color.
  81. [field setTextColor:[NSColor whiteColor]];
  82. [field setDrawsBackground:YES];
  83. [field setBackgroundColor:[NSColor blackColor]];
  84. [field setBordered:YES];
  85. GTMAssertObjectImageEqualToImageNamed(field,
  86. @"GTMFadeTruncatingTextFieldCellTest8",
  87. nil);
  88. }
  89. @end
  90. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5