PageRenderTime 26ms CodeModel.GetById 1ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMUILocalizerTest.m

http://macfuse.googlecode.com/
Objective C | 153 lines | 114 code | 19 blank | 20 comment | 1 complexity | a7c26264a9b09add9190e0930e627502 MD5 | raw file
  1//
  2//  GTMUILocalizerTest.m
  3//
  4//  Copyright 2009 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
 19
 20#import "GTMSenTestCase.h"
 21#import "GTMUILocalizerTest.h"
 22#import "GTMNSObject+UnitTesting.h"
 23#import "GTMUILocalizer.h"
 24
 25@interface GTMUILocalizerTest : GTMTestCase
 26@end
 27
 28@implementation GTMUILocalizerTest
 29// Utility method to verify that all the options for |binding| on |object| have
 30// been localized.
 31- (void)verifyBinding:(NSString *)binding forObject:(id)object {
 32  NSDictionary *bindingInfo 
 33    = [object infoForBinding:binding];
 34  STAssertNotNil(bindingInfo, 
 35                 @"Can't get binding info for %@ from %@.\nExposed bindings: %@",
 36                 binding, object, [object exposedBindings]);
 37  NSDictionary *bindingOptions = [bindingInfo objectForKey:NSOptionsKey];
 38  STAssertNotNil(bindingOptions, nil);
 39  NSString *key = nil;
 40  GTM_FOREACH_KEY(key, bindingOptions) {
 41    id value = [bindingOptions objectForKey:key];
 42    if ([value isKindOfClass:[NSString class]]) {
 43      STAssertFalse([value hasPrefix:@"^"], 
 44                    @"Binding option %@ not localized. Has value %@.", 
 45                    key, value);
 46    }
 47  }  
 48}
 49
 50- (void)testWindowLocalization {
 51  GTMUILocalizerTestWindowController *controller 
 52    = [[GTMUILocalizerTestWindowController alloc] init];
 53  NSWindow *window = [controller window];
 54  STAssertNotNil(window, nil);
 55  GTMAssertObjectStateEqualToStateNamed(window,
 56                                        @"GTMUILocalizerWindow1State", nil);
 57  
 58  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
 59  GTMUILocalizer *localizer = [[GTMUILocalizer alloc] initWithBundle:bundle];
 60  window = [controller otherWindow];
 61  STAssertNotNil(window, nil);
 62  [localizer localizeObject:window recursively:YES];
 63  GTMAssertObjectStateEqualToStateNamed(window, 
 64                                        @"GTMUILocalizerWindow2State", nil);
 65  window = [controller anotherWindow];
 66  STAssertNotNil(window, nil);
 67  [localizer localizeObject:window recursively:YES];
 68  GTMAssertObjectStateEqualToStateNamed(window, 
 69                                        @"GTMUILocalizerWindow3State", nil);
 70  NSMenu *menu = [controller otherMenu];
 71  STAssertNotNil(menu, nil);
 72  [localizer localizeObject:menu recursively:YES];
 73  GTMAssertObjectStateEqualToStateNamed(menu, 
 74                                        @"GTMUILocalizerMenuState", nil);
 75  
 76  // Test binding localization.
 77  NSTextField *textField = [controller bindingsTextField];
 78  STAssertNotNil(textField, nil);
 79  NSString *displayPatternValue1Binding 
 80    = [NSString stringWithFormat:@"%@1", NSDisplayPatternValueBinding];  
 81  [self verifyBinding:displayPatternValue1Binding forObject:textField];
 82  
 83  NSSearchField *searchField = [controller bindingsSearchField];
 84  STAssertNotNil(searchField, nil);
 85  [self verifyBinding:NSPredicateBinding forObject:searchField];
 86  
 87  [localizer release];
 88  [controller release];
 89}
 90
 91#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
 92- (void)testViewLocalization {
 93  GTMUILocalizerTestViewController *controller 
 94    = [[GTMUILocalizerTestViewController alloc] init];
 95  NSView *view = [controller view];
 96  STAssertNotNil(view, nil);
 97  GTMAssertObjectStateEqualToStateNamed(view, 
 98                                        @"GTMUILocalizerView1State", nil);
 99  
100  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
101  GTMUILocalizer *localizer = [[GTMUILocalizer alloc] initWithBundle:bundle];
102  view = [controller otherView];
103  STAssertNotNil(view, nil);
104  [localizer localizeObject:view recursively:YES];
105  GTMAssertObjectStateEqualToStateNamed(view, @"GTMUILocalizerView2State", nil);
106  [localizer release];
107  [controller release];
108}
109#endif  // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
110@end
111
112@implementation GTMUILocalizerTestWindowController
113- (id)init {
114#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
115  return [self initWithWindowNibName:@"GTMUILocalizerTestWindow"];
116#else
117  return [self initWithWindowNibName:@"GTMUILocalizerTestWindow_10_4"];
118#endif  // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
119}
120
121- (NSWindow *)otherWindow {
122  return otherWindow_;
123}
124
125- (NSWindow *)anotherWindow {
126  return anotherWindow_;
127}
128
129- (NSMenu *)otherMenu {
130  return otherMenu_;
131}
132
133- (NSTextField *)bindingsTextField {
134  return bindingsTextField_;
135}
136
137- (NSSearchField *)bindingsSearchField {
138  return bindingsSearchField_;
139}
140@end
141
142#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
143@implementation GTMUILocalizerTestViewController
144- (id)init {
145  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
146  return [self initWithNibName:@"GTMUILocalizerTestView" bundle:bundle];
147}
148
149- (NSView *)otherView {
150  return otherView_;
151}
152@end
153#endif