diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-16 14:30:21 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-16 14:30:21 +0000 |
commit | 711247f40bf28cc93e8be3e74bc5d654884c9ce4 (patch) | |
tree | bc5bc9f7fa4f47b49bd547a031535da7c6f8074e /iPhone/GTMUILocalizerTest.m | |
parent | 73d9542bde42d7b172f5db221d3403ceb4bdcf51 (diff) |
[Author: qsr]
Handle UIButton in GTMUILocalizer
To be noted: UISegmented Controls and UISearchBars were alredy
working. UISwitch doesn't have any strings to be localized.
R=dmaclach,thomasvl
APPROVED=thomasvl
Diffstat (limited to 'iPhone/GTMUILocalizerTest.m')
-rw-r--r-- | iPhone/GTMUILocalizerTest.m | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/iPhone/GTMUILocalizerTest.m b/iPhone/GTMUILocalizerTest.m index 682285d..dfe1f32 100644 --- a/iPhone/GTMUILocalizerTest.m +++ b/iPhone/GTMUILocalizerTest.m @@ -24,7 +24,10 @@ @implementation TestUILocalizer - (NSString *)localizedStringForString:(NSString *)string { - return [string substringFromIndex:5]; + if ([string length] >= 5) + return [string substringFromIndex:5]; + else + return string; } - (void)localize:(id)object { @@ -36,6 +39,9 @@ @implementation GTMUILocalizerTestViewController @synthesize label = label_; +@synthesize button = button_; +@synthesize segmentedControl = segmentedControl_; +@synthesize searchBar = searchBar_; - (id)init { NSBundle *bundle = [NSBundle bundleForClass:[self class]]; @@ -44,44 +50,64 @@ @end @interface GTMUILocalizerTest : GTMTestCase +- (void)checkValues:(NSString *)value + onController:(GTMUILocalizerTestViewController *)controller; @end @implementation GTMUILocalizerTest -- (void)testLocalization { - GTMUILocalizerTestViewController* controller = - [[GTMUILocalizerTestViewController alloc] init]; - - // Load the view. - [controller view]; - - STAssertEqualStrings(@"^IDS_FOO", [[controller label] text], nil); +- (void)checkValues:(NSString *)value + onController:(GTMUILocalizerTestViewController *)controller { + // Label + STAssertEqualStrings(value, [[controller label] text], nil); + // Button + UIControlState allStates[] = { UIControlStateNormal, + UIControlStateHighlighted, + UIControlStateDisabled, + UIControlStateSelected }; + for (size_t idx = 0; idx < (sizeof(allStates)/sizeof(allStates[0])) ; ++idx) { + UIControlState state = allStates[idx]; + STAssertEqualStrings(value, [[controller button] titleForState:state], nil); + } + // SegementedControl + for (NSUInteger i = 0; + i < [[controller segmentedControl] numberOfSegments]; + ++i) { + STAssertEqualStrings(value, + [[controller segmentedControl] titleForSegmentAtIndex:i], nil); + } + // SearchBar + STAssertEqualStrings(value, [[controller searchBar] text], nil); + STAssertEqualStrings(value, [[controller searchBar] placeholder], nil); + STAssertEqualStrings(value, [[controller searchBar] prompt], nil); // Accessibility label seems to not be working at all. They always are nil. -// Even when setting those explicitely there, the getter always returns nil. +// Even when setting those explicitly there, the getter always returns nil. // This might cause because the gobal accessibility switch is not on during the // tests. #if 0 - STAssertEqualStrings(@"^IDS_FOO", [[controller view] accessibilityLabel], + STAssertEqualStrings(value, [[controller view] accessibilityLabel], nil); - STAssertEqualStrings(@"^IDS_FOO", [[controller view] accessibilityHint], + STAssertEqualStrings(value, [[controller view] accessibilityHint], nil); - STAssertEqualStrings(@"^IDS_FOO", [[controller label] accessibilityLabel], + STAssertEqualStrings(value, [[controller label] accessibilityLabel], nil); - STAssertEqualStrings(@"^IDS_FOO", [[controller label] accessibilityHint], + STAssertEqualStrings(value, [[controller label] accessibilityHint], nil); #endif +} + +- (void)testLocalization { + GTMUILocalizerTestViewController *controller = + [[GTMUILocalizerTestViewController alloc] init]; + + // Load the view. + [controller view]; + + [self checkValues:@"^IDS_FOO" onController:controller]; TestUILocalizer *localizer = [[TestUILocalizer alloc] init]; [localizer localize:[controller view]]; - STAssertEqualStrings(@"FOO", [[controller label] text], nil); - -// Accessibility label seems to not be working at all. They always are nil. -#if 0 - STAssertEqualStrings(@"FOO", [[controller view] accessibilityLabel], nil); - STAssertEqualStrings(@"FOO", [[controller view] accessibilityHint], nil); - STAssertEqualStrings(@"FOO", [[controller label] accessibilityLabel], nil); - STAssertEqualStrings(@"FOO", [[controller label] accessibilityHint], nil); -#endif + [self checkValues:@"FOO" onController:controller]; } @end |