PageRenderTime 30ms CodeModel.GetById 9ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/iPhone/GTMUILocalizerTest.m

http://macfuse.googlecode.com/
Objective C | 113 lines | 72 code | 16 blank | 25 comment | 3 complexity | 1307bb2257a3081396d1bb058d8926c3 MD5 | raw file
  1//
  2//  GTMUILocalizerTest.m
  3//
  4//  Copyright 2011 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 "GTMUILocalizerTest.h"
 19#import "GTMSenTestCase.h"
 20
 21@interface TestUILocalizer : GTMUILocalizer
 22- (void)localize:(id)object;
 23@end
 24
 25@implementation TestUILocalizer
 26- (NSString *)localizedStringForString:(NSString *)string {
 27  if ([string length] >= 5)
 28    return [string substringFromIndex:5];
 29  else
 30    return string;
 31}
 32
 33- (void)localize:(id)object {
 34  [self localizeObject:object recursively:YES];
 35}
 36@end
 37
 38
 39@implementation GTMUILocalizerTestViewController
 40
 41@synthesize label = label_;
 42@synthesize button = button_;
 43@synthesize segmentedControl = segmentedControl_;
 44@synthesize searchBar = searchBar_;
 45
 46- (id)init {
 47  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
 48  return [self initWithNibName:@"GTMUILocalizerTest" bundle:bundle];
 49}
 50@end
 51
 52@interface GTMUILocalizerTest : GTMTestCase
 53- (void)checkValues:(NSString *)value
 54       onController:(GTMUILocalizerTestViewController *)controller;
 55@end
 56
 57@implementation GTMUILocalizerTest
 58- (void)checkValues:(NSString *)value
 59       onController:(GTMUILocalizerTestViewController *)controller {
 60  // Label
 61  STAssertEqualStrings(value, [[controller label] text], nil);
 62  // Button
 63  UIControlState allStates[] = { UIControlStateNormal,
 64                                 UIControlStateHighlighted,
 65                                 UIControlStateDisabled,
 66                                 UIControlStateSelected };
 67  for (size_t idx = 0; idx < (sizeof(allStates)/sizeof(allStates[0])); ++idx) {
 68    UIControlState state = allStates[idx];
 69    STAssertEqualStrings(value, [[controller button] titleForState:state], nil);
 70  }
 71  // SegementedControl
 72  for (NSUInteger i = 0;
 73       i < [[controller segmentedControl] numberOfSegments];
 74       ++i) {
 75    STAssertEqualStrings(value,
 76        [[controller segmentedControl] titleForSegmentAtIndex:i], nil);
 77  }
 78  // SearchBar
 79  STAssertEqualStrings(value, [[controller searchBar] text], nil);
 80  STAssertEqualStrings(value, [[controller searchBar] placeholder], nil);
 81  STAssertEqualStrings(value, [[controller searchBar] prompt], nil);
 82
 83// Accessibility label seems to not be working at all. They always are nil.
 84// Even when setting those explicitly there, the getter always returns nil.
 85// This might be because the gobal accessibility switch is not on during the
 86// tests.
 87#if 0
 88  STAssertEqualStrings(value, [[controller view] accessibilityLabel],
 89      nil);
 90  STAssertEqualStrings(value, [[controller view] accessibilityHint],
 91      nil);
 92  STAssertEqualStrings(value, [[controller label] accessibilityLabel],
 93      nil);
 94  STAssertEqualStrings(value, [[controller label] accessibilityHint],
 95      nil);
 96#endif
 97}
 98
 99- (void)testLocalization {
100  GTMUILocalizerTestViewController *controller =
101    [[[GTMUILocalizerTestViewController alloc] init] autorelease];
102
103  // Load the view.
104  [controller view];
105
106  [self checkValues:@"^IDS_FOO" onController:controller];
107
108  TestUILocalizer *localizer = [[TestUILocalizer alloc] init];
109  [localizer localize:[controller view]];
110
111  [self checkValues:@"FOO" onController:controller];
112}
113@end