From f736aed5642b3c7f19533653e1ddfd4599f1ee7d Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Tue, 9 Mar 2010 20:36:55 +0000 Subject: [Author: thomasvl] Add an api for forcing a NSTextField to a fixed height but what ever width is needed. R=dmaclach DELTA=634 (631 added, 0 deleted, 3 changed) --- AppKit/GTMUILocalizerAndLayoutTweakerTest.m | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'AppKit/GTMUILocalizerAndLayoutTweakerTest.m') diff --git a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m index fed8359..d5b111c 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m +++ b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m @@ -211,6 +211,63 @@ static NSUInteger gTestPass = 0; } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 +- (void)testSizeToFitFixedHeightTextField { + struct { + const char *name; + NSUInteger minWidth; + } kTestModes[] = { + { "NoMin", 0 }, + { "Min", 450 }, + }; + NSString *kTestStrings[] = { + @"The fox jumps the dog.", + @"The quick brown fox jumps over the lazy dog.", + @"The quick brown fox jumps over the lazy dog. The quick brown fox jumps " + @"over the lazy dog. The quick brown fox jumps over the lazy dog. " + @"The quick brown fox jumps over the lazy dog. The quick brown fox " + @"jumps over the lazy dog.", + @"The quick brown fox jumps over the lazy dog. The quick brown fox jumps " + @"over the lazy dog. The quick brown fox jumps over the lazy dog. " + @"The quick brown fox jumps over the lazy dog. The quick brown fox " + @"jumps over the lazy dog. The quick brown fox jumps over the lazy " + @"dog. The quick brown fox jumps over the lazy dog. The End.", + }; + for (size_t modeLoop = 0; + modeLoop < (sizeof(kTestModes) / sizeof(kTestModes[0])); + ++modeLoop) { + for (size_t lp = 0; + lp < (sizeof(kTestStrings) / sizeof(kTestStrings[0])); + ++lp) { + GTMUILocalizerAndLayoutTweakerTestWindowController *controller = + [[GTMUILocalizerAndLayoutTweakerTestWindowController alloc] + initWithWindowNibName:@"GTMUILocalizerAndLayoutTweakerTest7"]; + NSWindow *window = [controller window]; + STAssertNotNil(window, @"Pass %zu", lp); + NSTextField *field; + GTM_FOREACH_OBJECT(field, [[window contentView] subviews]) { + STAssertTrue([field isMemberOfClass:[NSTextField class]], + @"Pass %zu", lp); + [field setStringValue:kTestStrings[lp]]; + NSUInteger minWidth = kTestModes[modeLoop].minWidth; + if (minWidth) { + [GTMUILocalizerAndLayoutTweaker sizeToFitFixedHeightTextField:field + minWidth:minWidth]; + } else { + [GTMUILocalizerAndLayoutTweaker sizeToFitFixedHeightTextField:field]; + } + } + NSString *imageName = + [NSString stringWithFormat:@"GTMUILocalizerAndLayoutTweakerTest7-%s-%ld", + kTestModes[modeLoop].name, (long)lp]; + GTMAssertObjectImageEqualToImageNamed(window, imageName, + @"Pass %zu-%zu", modeLoop, lp); + [controller release]; + } + } +} +#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + @end @implementation GTMUILocalizerAndLayoutTweakerTestWindowController -- cgit v1.2.3