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