diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
commit | 1204639d4aeeac3d3dda7b0c53b8941266b9e685 (patch) | |
tree | 37db0dee0bdaad00e3c6faf9c50d2c3804b598b6 | |
parent | fe8209a1d04223c70727a4e87cfe53d5bd4192c0 (diff) |
[Author: thomasvl]
- Support for localizing non datasource versions of NSComboxBox (http://code.google.com/p/google-toolbox-for-mac/issues/detail?id=77).
- Fix up some category names.
- Avoid conflicting category names.
- Move placeholder string support down to NSTextField instead of NSSearchField.
- Support for NSTextField placeholder in unittesting state.
- Support for non datasource combobox values in unittesting state.
- Fix NSSegmentControl localization support.
- Add explicit tests for no localized values and document it in the strings file.
- Unittesting for as much as possible of the above.
R=dmaclach
DELTA=762 (660 added, 55 deleted, 47 changed)
-rw-r--r-- | AppKit/GTMUILocalizer.m | 53 | ||||
-rw-r--r-- | AppKit/GTMUILocalizerTestWindow.xib | 258 | ||||
-rw-r--r-- | AppKit/GTMUILocalizerTestWindow_10_4.xib | 246 | ||||
-rw-r--r-- | AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState | 40 | ||||
-rw-r--r-- | AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState | 42 | ||||
-rw-r--r-- | AppKit/TestData/Resources/English.lproj/Localizable.strings | 8 | ||||
-rw-r--r-- | UnitTesting/GTMAppKit+UnitTesting.h | 51 | ||||
-rw-r--r-- | UnitTesting/GTMAppKit+UnitTesting.m | 197 | ||||
-rw-r--r-- | UnitTesting/GTMAppKitUnitTestingUtilities.h | 30 | ||||
-rw-r--r-- | UnitTesting/GTMAppKitUnitTestingUtilities.m | 96 |
10 files changed, 813 insertions, 208 deletions
diff --git a/AppKit/GTMUILocalizer.m b/AppKit/GTMUILocalizer.m index 56b0b7d..ffcc11d 100644 --- a/AppKit/GTMUILocalizer.m +++ b/AppKit/GTMUILocalizer.m @@ -23,7 +23,7 @@ - (void)localizeAccessibility:(id)object; - (void)localizeBindings:(id)object; -// Never recursively call any of these methods. Always call +// Never recursively call any of these methods. Always call // -[self localizeObject:recursively:] otherwise bindings will not be // localized properly. - (void)localizeWindow:(NSWindow *)window recursively:(BOOL)recursive; @@ -240,12 +240,12 @@ } } - // Do NSSearchField placeholders - if ([view isKindOfClass:[NSSearchField class]]) { - NSString *placeholder = [[(NSSearchField *)view cell] placeholderString]; + // Do NSTextField placeholders + if ([view isKindOfClass:[NSTextField class]]) { + NSString *placeholder = [[(NSTextField *)view cell] placeholderString]; NSString *localizedPlaceholer = [self localizedStringForString:placeholder]; if (localizedPlaceholer) { - [[(NSSearchField *)view cell] setPlaceholderString:localizedPlaceholer]; + [[(NSTextField *)view cell] setPlaceholderString:localizedPlaceholer]; } } @@ -282,8 +282,37 @@ NSSegmentedControl *segmentedControl = (NSSegmentedControl *)view; for (NSInteger i = 0; i < [segmentedControl segmentCount]; ++i) { NSString *label = [segmentedControl labelForSegment:i]; - [segmentedControl setLabel:[self localizedStringForString:label] - forSegment:i]; + NSString *localizedLabel = [self localizedStringForString:label]; + if (localizedLabel) { + [segmentedControl setLabel:localizedLabel forSegment:i]; + } + } + } + + // Do NSComboBox items. + if ([view isKindOfClass:[NSComboBox class]]) { + NSComboBox *combobox = (NSComboBox*)view; + // Make sure it doesn't use a DataSource. + if (![combobox usesDataSource]) { + NSMutableArray *localizedValues = [NSMutableArray array]; + BOOL replaceValues = NO; + NSString *value; + GTM_FOREACH_OBJECT(value, [combobox objectValues]) { + NSString *localizedValue = nil; + if ([value isKindOfClass:[NSString class]]) { + localizedValue = [self localizedStringForString:value]; + } + if (localizedValue) { + replaceValues = YES; + [localizedValues addObject:localizedValue]; + } else { + [localizedValues addObject:value]; + } + } + if (replaceValues) { + [combobox removeAllItems]; + [combobox addItemsWithObjectValues:localizedValues]; + } } } } @@ -343,10 +372,10 @@ NSString *path = [bindingInfo objectForKey:NSObservedKeyPathKey]; NSDictionary *options = [bindingInfo objectForKey:NSOptionsKey]; if (observedObject && path && options) { - NSMutableDictionary *newOptions + NSMutableDictionary *newOptions = [NSMutableDictionary dictionaryWithDictionary:options]; BOOL valueChanged = NO; - for (size_t i = 0; + for (size_t i = 0; i < sizeof(optionsToLocalize) / sizeof(optionsToLocalize[0]); ++i) { NSString *key = optionsToLocalize[i]; @@ -362,9 +391,9 @@ if (valueChanged) { // Only unbind and rebind if there is a change. [object unbind:exposedBinding]; - [object bind:exposedBinding - toObject:observedObject - withKeyPath:path + [object bind:exposedBinding + toObject:observedObject + withKeyPath:path options:newOptions]; } } diff --git a/AppKit/GTMUILocalizerTestWindow.xib b/AppKit/GTMUILocalizerTestWindow.xib index 6161945..8bb4172 100644 --- a/AppKit/GTMUILocalizerTestWindow.xib +++ b/AppKit/GTMUILocalizerTestWindow.xib @@ -2,18 +2,18 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">10D2063a</string> - <string key="IBDocument.InterfaceBuilderVersion">762</string> - <string key="IBDocument.AppKitVersion">1038.29</string> - <string key="IBDocument.HIToolboxVersion">460.00</string> + <string key="IBDocument.SystemVersion">10K549</string> + <string key="IBDocument.InterfaceBuilderVersion">851</string> + <string key="IBDocument.AppKitVersion">1038.36</string> + <string key="IBDocument.HIToolboxVersion">461.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">762</string> + <string key="NS.object.0">851</string> </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="23"/> <integer value="52"/> - <integer value="22"/> <integer value="41"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> @@ -196,7 +196,7 @@ <int key="NSColorSpace">6</int> <string key="NSCatalogName">System</string> <string key="NSColorName">controlColor</string> - <object class="NSColor" key="NSColor"> + <object class="NSColor" key="NSColor" id="125228242"> <int key="NSColorSpace">3</int> <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes> </object> @@ -1204,6 +1204,107 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <int key="NSSegmentStyle">1</int> </object> </object> + <object class="NSComboBox" id="931776629"> + <reference key="NSNextResponder" ref="405137086"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{371, 180}, {92, 26}}</string> + <reference key="NSSuperview" ref="405137086"/> + <bool key="NSEnabled">YES</bool> + <object class="NSComboBoxCell" key="NSCell" id="763797856"> + <int key="NSCellFlags">343014976</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents">^Label1</string> + <reference key="NSSupport" ref="168773824"/> + <string key="NSPlaceholderString">^Placeholder1</string> + <reference key="NSControlView" ref="931776629"/> + <bool key="NSDrawsBackground">YES</bool> + <reference key="NSBackgroundColor" ref="854948635"/> + <reference key="NSTextColor" ref="50010148"/> + <int key="NSVisibleItemCount">4</int> + <bool key="NSHasVerticalScroller">YES</bool> + <object class="NSMutableArray" key="NSPopUpListData"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>^Choice1</string> + <string>^Choice2</string> + <string>^Choice3</string> + <string>^Choice4</string> + <string>^Choice5</string> + </object> + <reference key="NSDelegate" ref="931776629"/> + <object class="NSComboTableView" key="NSTableView" id="452420746"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">274</int> + <string key="NSFrameSize">{13, 105}</string> + <reference key="NSSuperview"/> + <reference key="NSWindow"/> + <bool key="NSEnabled">YES</bool> + <object class="NSMutableArray" key="NSTableColumns"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTableColumn"> + <integer value="0" key="NSIdentifier"/> + <double key="NSWidth">10</double> + <double key="NSMinWidth">10</double> + <double key="NSMaxWidth">1000</double> + <object class="NSTableHeaderCell" key="NSHeaderCell"> + <int key="NSCellFlags">75628032</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents"/> + <object class="NSFont" key="NSSupport"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">12</double> + <int key="NSfFlags">16</int> + </object> + <object class="NSColor" key="NSBackgroundColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC4zMzMzMzI5ODU2AA</bytes> + </object> + <reference key="NSTextColor" ref="695371698"/> + </object> + <object class="NSTextFieldCell" key="NSDataCell"> + <int key="NSCellFlags">338820672</int> + <int key="NSCellFlags2">1024</int> + <reference key="NSSupport" ref="168773824"/> + <reference key="NSControlView" ref="452420746"/> + <bool key="NSDrawsBackground">YES</bool> + <object class="NSColor" key="NSBackgroundColor" id="156860821"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlBackgroundColor</string> + <reference key="NSColor" ref="125228242"/> + </object> + <reference key="NSTextColor" ref="50010148"/> + </object> + <int key="NSResizingMask">3</int> + <bool key="NSIsResizeable">YES</bool> + <reference key="NSTableView" ref="452420746"/> + </object> + </object> + <double key="NSIntercellSpacingWidth">3</double> + <double key="NSIntercellSpacingHeight">2</double> + <reference key="NSBackgroundColor" ref="156860821"/> + <object class="NSColor" key="NSGridColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">gridColor</string> + <object class="NSColor" key="NSColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC41AA</bytes> + </object> + </object> + <double key="NSRowHeight">19</double> + <string key="NSAction">tableViewAction:</string> + <int key="NSTvFlags">-765427712</int> + <reference key="NSDelegate" ref="763797856"/> + <reference key="NSDataSource" ref="763797856"/> + <reference key="NSTarget" ref="763797856"/> + <int key="NSColumnAutoresizingStyle">1</int> + <int key="NSDraggingSourceMaskForLocal">15</int> + <int key="NSDraggingSourceMaskForNonLocal">0</int> + <bool key="NSAllowsTypeSelect">YES</bool> + <int key="NSTableViewDraggingDestinationStyle">0</int> + </object> + </object> + </object> </object> <string key="NSFrameSize">{480, 270}</string> <reference key="NSSuperview"/> @@ -1631,6 +1732,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference ref="846591189"/> <reference ref="161950549"/> <reference ref="632547328"/> + <reference ref="931776629"/> </object> <reference key="parent" ref="158765462"/> </object> @@ -1873,6 +1975,20 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="object" ref="907223470"/> <reference key="parent" ref="632547328"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">173</int> + <reference key="object" ref="931776629"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="763797856"/> + </object> + <reference key="parent" ref="405137086"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">174</int> + <reference key="object" ref="763797856"/> + <reference key="parent" ref="931776629"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -1900,6 +2016,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>16.IBPluginDependency</string> <string>169.IBPluginDependency</string> <string>170.IBPluginDependency</string> + <string>173.IBPluginDependency</string> + <string>173.IBViewBoundsToFrameTransform</string> + <string>174.IBPluginDependency</string> <string>2.IBPluginDependency</string> <string>22.IBEditorWindowLastContentRect</string> <string>22.IBPluginDependency</string> @@ -1962,9 +2081,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{329, 451}, {480, 270}}</string> + <string>{{387, 451}, {480, 270}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{329, 451}, {480, 270}}</string> + <string>{{387, 451}, {480, 270}}</string> <boolean value="NO"/> <string>{196, 240}</string> <string>{{357, 418}, {480, 270}}</string> @@ -1981,9 +2100,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{960, 479}, {480, 270}}</string> + <object class="NSAffineTransform"> + <bytes key="NSTransformStruct">P4AAAL+AAABDuYAAw0wAAA</bytes> + </object> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{948, 629}, {480, 270}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{960, 479}, {480, 270}}</string> + <string>{{948, 629}, {480, 270}}</string> <boolean value="NO"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{126, 673}, {161, 23}}</string> @@ -2054,7 +2178,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">170</int> + <int key="maxID">174</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -2077,6 +2201,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>id</string> </object> </object> + <object class="NSMutableDictionary" key="toOneOutletInfosByName"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>otherObjectToLocalize_</string> + <string>owner_</string> + <string>yetAnotherObjectToLocalize_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBToOneOutletInfo"> + <string key="name">otherObjectToLocalize_</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">owner_</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">yetAnotherObjectToLocalize_</string> + <string key="candidateClassName">id</string> + </object> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">AppKit/GTMUILocalizer.h</string> @@ -2104,6 +2252,40 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>NSWindow</string> </object> </object> + <object class="NSMutableDictionary" key="toOneOutletInfosByName"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>anotherWindow_</string> + <string>bindingsSearchField_</string> + <string>bindingsTextField_</string> + <string>otherMenu_</string> + <string>otherWindow_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBToOneOutletInfo"> + <string key="name">anotherWindow_</string> + <string key="candidateClassName">NSWindow</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">bindingsSearchField_</string> + <string key="candidateClassName">NSSearchField</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">bindingsTextField_</string> + <string key="candidateClassName">NSTextField</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">otherMenu_</string> + <string key="candidateClassName">NSMenu</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">otherWindow_</string> + <string key="candidateClassName">NSWindow</string> + </object> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">AppKit/GTMUILocalizerTest.h</string> @@ -2124,6 +2306,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSBox</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSButton</string> <reference key="sourceIdentifier" ref="485269976"/> </object> @@ -2132,6 +2318,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="sourceIdentifier" ref="485269976"/> </object> <object class="IBPartialClassDescription"> + <string key="className">NSComboBox</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSControl</string> <reference key="sourceIdentifier" ref="485269976"/> </object> @@ -2165,13 +2355,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">Foundation/GTMHTTPServer.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">NSObject</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> <string key="minorKey">Foundation/GTMNSAppleEventDescriptor+Foundation.h</string> </object> </object> @@ -2204,6 +2387,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSSegmentedControl</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSTabView</string> <reference key="sourceIdentifier" ref="485269976"/> </object> @@ -2216,6 +2403,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="sourceIdentifier" ref="485269976"/> </object> <object class="IBPartialClassDescription"> + <string key="className">NSToolbar</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSToolbarItem</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSView</string> <object class="IBClassDescriptionSource" key="sourceIdentifier" id="308904550"> <string key="majorKey">IBProjectSource</string> @@ -2321,6 +2516,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSComboBox</string> + <string key="superclassName">NSTextField</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSComboBox.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSComboBoxCell</string> + <string key="superclassName">NSTextFieldCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSComboBoxCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSControl</string> <string key="superclassName">NSView</string> <object class="IBClassDescriptionSource" key="sourceIdentifier" id="498926182"> @@ -2847,6 +3058,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="NS.key.0">showWindow:</string> <string key="NS.object.0">id</string> </object> + <object class="NSMutableDictionary" key="actionInfosByName"> + <string key="NS.key.0">showWindow:</string> + <object class="IBActionInfo" key="NS.object.0"> + <string key="name">showWindow:</string> + <string key="candidateClassName">id</string> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBFrameworkSource</string> <string key="minorKey">AppKit.framework/Headers/NSWindowController.h</string> @@ -2862,7 +3080,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string> - <integer value="1060" key="NS.object.0"/> + <integer value="1050" key="NS.object.0"/> </object> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string> diff --git a/AppKit/GTMUILocalizerTestWindow_10_4.xib b/AppKit/GTMUILocalizerTestWindow_10_4.xib index 93cb909..6316e33 100644 --- a/AppKit/GTMUILocalizerTestWindow_10_4.xib +++ b/AppKit/GTMUILocalizerTestWindow_10_4.xib @@ -2,18 +2,18 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1040</int> - <string key="IBDocument.SystemVersion">10D2063a</string> - <string key="IBDocument.InterfaceBuilderVersion">762</string> - <string key="IBDocument.AppKitVersion">1038.29</string> - <string key="IBDocument.HIToolboxVersion">460.00</string> + <string key="IBDocument.SystemVersion">10K549</string> + <string key="IBDocument.InterfaceBuilderVersion">851</string> + <string key="IBDocument.AppKitVersion">1038.36</string> + <string key="IBDocument.HIToolboxVersion">461.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">762</string> + <string key="NS.object.0">851</string> </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> <integer value="35"/> - <integer value="54"/> + <integer value="120"/> <integer value="22"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> @@ -117,7 +117,7 @@ <int key="NSColorSpace">6</int> <string key="NSCatalogName">System</string> <string key="NSColorName">controlColor</string> - <object class="NSColor" key="NSColor"> + <object class="NSColor" key="NSColor" id="792644860"> <int key="NSColorSpace">3</int> <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes> </object> @@ -1089,6 +1089,107 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="NSFrame">{{42, 66}, {106, 45}}</string> <reference key="NSSuperview" ref="405137086"/> </object> + <object class="NSComboBox" id="311378109"> + <reference key="NSNextResponder" ref="405137086"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{371, 180}, {92, 26}}</string> + <reference key="NSSuperview" ref="405137086"/> + <bool key="NSEnabled">YES</bool> + <object class="NSComboBoxCell" key="NSCell" id="693732256"> + <int key="NSCellFlags">343014976</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents">^Label1</string> + <reference key="NSSupport" ref="168773824"/> + <string key="NSPlaceholderString">^Placeholder1</string> + <reference key="NSControlView" ref="311378109"/> + <bool key="NSDrawsBackground">YES</bool> + <reference key="NSBackgroundColor" ref="407928047"/> + <reference key="NSTextColor" ref="50010148"/> + <int key="NSVisibleItemCount">4</int> + <bool key="NSHasVerticalScroller">YES</bool> + <object class="NSMutableArray" key="NSPopUpListData"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>^Choice1</string> + <string>^Choice2</string> + <string>^Choice3</string> + <string>^Choice4</string> + <string>^Choice5</string> + </object> + <reference key="NSDelegate" ref="311378109"/> + <object class="NSComboTableView" key="NSTableView" id="743163681"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">274</int> + <string key="NSFrameSize">{13, 105}</string> + <reference key="NSSuperview"/> + <reference key="NSWindow"/> + <bool key="NSEnabled">YES</bool> + <object class="NSMutableArray" key="NSTableColumns"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTableColumn"> + <integer value="0" key="NSIdentifier"/> + <double key="NSWidth">10</double> + <double key="NSMinWidth">10</double> + <double key="NSMaxWidth">1000</double> + <object class="NSTableHeaderCell" key="NSHeaderCell"> + <int key="NSCellFlags">75628032</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents"/> + <object class="NSFont" key="NSSupport"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">12</double> + <int key="NSfFlags">16</int> + </object> + <object class="NSColor" key="NSBackgroundColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC4zMzMzMzI5ODU2AA</bytes> + </object> + <reference key="NSTextColor" ref="695371698"/> + </object> + <object class="NSTextFieldCell" key="NSDataCell"> + <int key="NSCellFlags">338820672</int> + <int key="NSCellFlags2">1024</int> + <reference key="NSSupport" ref="168773824"/> + <reference key="NSControlView" ref="743163681"/> + <bool key="NSDrawsBackground">YES</bool> + <object class="NSColor" key="NSBackgroundColor" id="619521113"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlBackgroundColor</string> + <reference key="NSColor" ref="792644860"/> + </object> + <reference key="NSTextColor" ref="50010148"/> + </object> + <int key="NSResizingMask">3</int> + <bool key="NSIsResizeable">YES</bool> + <reference key="NSTableView" ref="743163681"/> + </object> + </object> + <double key="NSIntercellSpacingWidth">3</double> + <double key="NSIntercellSpacingHeight">2</double> + <reference key="NSBackgroundColor" ref="619521113"/> + <object class="NSColor" key="NSGridColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">gridColor</string> + <object class="NSColor" key="NSColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC41AA</bytes> + </object> + </object> + <double key="NSRowHeight">19</double> + <string key="NSAction">tableViewAction:</string> + <int key="NSTvFlags">-765427712</int> + <reference key="NSDelegate" ref="693732256"/> + <reference key="NSDataSource" ref="693732256"/> + <reference key="NSTarget" ref="693732256"/> + <int key="NSColumnAutoresizingStyle">1</int> + <int key="NSDraggingSourceMaskForLocal">15</int> + <int key="NSDraggingSourceMaskForNonLocal">0</int> + <bool key="NSAllowsTypeSelect">YES</bool> + <int key="NSTableViewDraggingDestinationStyle">0</int> + </object> + </object> + </object> </object> <string key="NSFrameSize">{480, 270}</string> <reference key="NSSuperview"/> @@ -1549,6 +1650,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference ref="735149545"/> <reference ref="846591189"/> <reference ref="161950549"/> + <reference ref="311378109"/> </object> <reference key="parent" ref="158765462"/> </object> @@ -1757,6 +1859,20 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="object" ref="129694561"/> <reference key="parent" ref="0"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">120</int> + <reference key="object" ref="311378109"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="693732256"/> + </object> + <reference key="parent" ref="405137086"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">121</int> + <reference key="object" ref="693732256"/> + <reference key="parent" ref="311378109"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -1777,6 +1893,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>101.IBPluginDependency</string> <string>11.IBPluginDependency</string> <string>12.IBPluginDependency</string> + <string>120.IBPluginDependency</string> + <string>120.IBViewBoundsToFrameTransform</string> + <string>121.IBPluginDependency</string> <string>13.IBPluginDependency</string> <string>14.IBPluginDependency</string> <string>15.IBPluginDependency</string> @@ -1840,9 +1959,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{174, 487}, {480, 270}}</string> + <string>{{174, 328}, {480, 270}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{174, 487}, {480, 270}}</string> + <string>{{174, 328}, {480, 270}}</string> <boolean value="NO"/> <string>{196, 240}</string> <string>{{357, 418}, {480, 270}}</string> @@ -1852,13 +1971,18 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <object class="NSAffineTransform"> + <bytes key="NSTransformStruct">P4AAAL+AAABDuYAAw0wAAA</bytes> + </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{324, 479}, {480, 270}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{324, 479}, {480, 270}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{387, 479}, {480, 270}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{387, 479}, {480, 270}}</string> <boolean value="NO"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{126, 673}, {161, 23}}</string> @@ -1926,7 +2050,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">119</int> + <int key="maxID">121</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -1949,6 +2073,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>id</string> </object> </object> + <object class="NSMutableDictionary" key="toOneOutletInfosByName"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>otherObjectToLocalize_</string> + <string>owner_</string> + <string>yetAnotherObjectToLocalize_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBToOneOutletInfo"> + <string key="name">otherObjectToLocalize_</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">owner_</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">yetAnotherObjectToLocalize_</string> + <string key="candidateClassName">id</string> + </object> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">AppKit/GTMUILocalizer.h</string> @@ -1976,6 +2124,40 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>NSWindow</string> </object> </object> + <object class="NSMutableDictionary" key="toOneOutletInfosByName"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>anotherWindow_</string> + <string>bindingsSearchField_</string> + <string>bindingsTextField_</string> + <string>otherMenu_</string> + <string>otherWindow_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBToOneOutletInfo"> + <string key="name">anotherWindow_</string> + <string key="candidateClassName">NSWindow</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">bindingsSearchField_</string> + <string key="candidateClassName">NSSearchField</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">bindingsTextField_</string> + <string key="candidateClassName">NSTextField</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">otherMenu_</string> + <string key="candidateClassName">NSMenu</string> + </object> + <object class="IBToOneOutletInfo"> + <string key="name">otherWindow_</string> + <string key="candidateClassName">NSWindow</string> + </object> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">AppKit/GTMUILocalizerTest.h</string> @@ -1996,6 +2178,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSBox</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSButton</string> <reference key="sourceIdentifier" ref="485269976"/> </object> @@ -2004,6 +2190,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="sourceIdentifier" ref="485269976"/> </object> <object class="IBPartialClassDescription"> + <string key="className">NSComboBox</string> + <reference key="sourceIdentifier" ref="485269976"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSControl</string> <reference key="sourceIdentifier" ref="485269976"/> </object> @@ -2037,13 +2227,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">Foundation/GTMHTTPServer.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">NSObject</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> <string key="minorKey">Foundation/GTMNSAppleEventDescriptor+Foundation.h</string> </object> </object> @@ -2193,6 +2376,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSComboBox</string> + <string key="superclassName">NSTextField</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSComboBox.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSComboBoxCell</string> + <string key="superclassName">NSTextFieldCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSComboBoxCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSControl</string> <string key="superclassName">NSView</string> <object class="IBClassDescriptionSource" key="sourceIdentifier" id="187673849"> @@ -2690,6 +2889,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="NS.key.0">showWindow:</string> <string key="NS.object.0">id</string> </object> + <object class="NSMutableDictionary" key="actionInfosByName"> + <string key="NS.key.0">showWindow:</string> + <object class="IBActionInfo" key="NS.object.0"> + <string key="name">showWindow:</string> + <string key="candidateClassName">id</string> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBFrameworkSource</string> <string key="minorKey">AppKit.framework/Headers/NSWindowController.h</string> @@ -2705,7 +2911,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string> - <integer value="1060" key="NS.object.0"/> + <integer value="1050" key="NS.object.0"/> </object> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string> diff --git a/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState b/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState index ed88b68..ea1d10c 100644 --- a/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState +++ b/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState @@ -293,6 +293,46 @@ <false/> </dict> </dict> + <key>ViewSubView 3</key> + <dict> + <key>ComboBoxNumberOfItems</key> + <integer>5</integer> + <key>ComboBoxNumberOfVisibleItems</key> + <integer>4</integer> + <key>ComboBoxObjectValue 0</key> + <string>Localized Choice 1</string> + <key>ComboBoxObjectValue 1</key> + <string>Localized Choice 2</string> + <key>ComboBoxObjectValue 2</key> + <string>Localized Choice 3</string> + <key>ComboBoxObjectValue 3</key> + <string>^Choice4</string> + <key>ComboBoxObjectValue 4</key> + <string>^Choice5</string> + <key>ControlIsEnabled</key> + <true/> + <key>ControlSelectedCell</key> + <dict> + <key>CellState</key> + <integer>0</integer> + <key>CellTag</key> + <integer>0</integer> + <key>CellTitle</key> + <string>Localized Label</string> + <key>CellValue</key> + <string>Localized Label</string> + </dict> + <key>ControlTag</key> + <integer>0</integer> + <key>ControlType</key> + <string>NSComboBox</string> + <key>ControlValue</key> + <string>Localized Label</string> + <key>PlaceHolderString</key> + <string>Localized Placeholder</string> + <key>ViewIsHidden</key> + <false/> + </dict> </dict> <key>WindowIsMain</key> <false/> diff --git a/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState b/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState index 8352b5e..6958e6e 100644 --- a/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState +++ b/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState @@ -319,12 +319,52 @@ <key>Segment 1</key> <string>Localized Segment 2</string> <key>Segment 2</key> - <string>Localized Segment 3</string> + <string>^Seg3</string> <key>SegmentCount</key> <integer>3</integer> <key>ViewIsHidden</key> <false/> </dict> + <key>ViewSubView 4</key> + <dict> + <key>ComboBoxNumberOfItems</key> + <integer>5</integer> + <key>ComboBoxNumberOfVisibleItems</key> + <integer>4</integer> + <key>ComboBoxObjectValue 0</key> + <string>Localized Choice 1</string> + <key>ComboBoxObjectValue 1</key> + <string>Localized Choice 2</string> + <key>ComboBoxObjectValue 2</key> + <string>Localized Choice 3</string> + <key>ComboBoxObjectValue 3</key> + <string>^Choice4</string> + <key>ComboBoxObjectValue 4</key> + <string>^Choice5</string> + <key>ControlIsEnabled</key> + <true/> + <key>ControlSelectedCell</key> + <dict> + <key>CellState</key> + <integer>0</integer> + <key>CellTag</key> + <integer>0</integer> + <key>CellTitle</key> + <string>Localized Label</string> + <key>CellValue</key> + <string>Localized Label</string> + </dict> + <key>ControlTag</key> + <integer>0</integer> + <key>ControlType</key> + <string>NSComboBox</string> + <key>ControlValue</key> + <string>Localized Label</string> + <key>PlaceHolderString</key> + <string>Localized Placeholder</string> + <key>ViewIsHidden</key> + <false/> + </dict> </dict> <key>WindowIsMain</key> <false/> diff --git a/AppKit/TestData/Resources/English.lproj/Localizable.strings b/AppKit/TestData/Resources/English.lproj/Localizable.strings index e6452a8..b45dc87 100644 --- a/AppKit/TestData/Resources/English.lproj/Localizable.strings +++ b/AppKit/TestData/Resources/English.lproj/Localizable.strings @@ -16,6 +16,9 @@ // the License. // +// NOTE: Some things in the UI aren't here to confirm that they get left +// along instead of replaced with an empty string. + // GTMUILocalizerTest strings "Button1" = "Localized Button"; "Label1" = "Localized Label"; @@ -39,7 +42,10 @@ "Box" = "Localized Box"; "Seg1" = "Localized Segment 1"; "Seg2" = "Localized Segment 2"; -"Seg3" = "Localized Segment 3"; +"Choice1" = "Localized Choice 1"; +"Choice2" = "Localized Choice 2"; +"Choice3" = "Localized Choice 3"; +"Placeholder1" = "Localized Placeholder"; // Binding localization strings. "MultipleValuesPlaceholder" = "MultipleValuesPlaceholder"; diff --git a/UnitTesting/GTMAppKit+UnitTesting.h b/UnitTesting/GTMAppKit+UnitTesting.h index 7ef5512..7f6bd26 100644 --- a/UnitTesting/GTMAppKit+UnitTesting.h +++ b/UnitTesting/GTMAppKit+UnitTesting.h @@ -1,16 +1,16 @@ // // GTMAppKit+UnitTesting.m -// +// // Categories for making unit testing of graphics/UI easier. -// +// // Copyright 2006-2008 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -31,13 +31,13 @@ @interface NSWindow (GTMUnitTestingAdditions) <GTMUnitTestingImaging> @end -@interface NSControl (GTMUnitTestingAdditions) +@interface NSControl (GTMUnitTestingAdditions) @end -@interface NSTextField (GTMUnitTestingAdditions) +@interface NSButton (GTMUnitTestingAdditions) @end -@interface NSButton (GTMUnitTestingAdditions) +@interface NSTextField (GTMUnitTestingAdditions) @end @interface NSCell (GTMUnitTestingAdditions) @@ -46,7 +46,7 @@ @interface NSImage (GTMUnitTestingAdditions) <GTMUnitTestingImaging> @end -@interface NSMenu (GTMUnitTestingAdditions) +@interface NSMenu (GTMUnitTestingAdditions) @end @interface NSMenuItem (GTMUnitTestingAdditions) @@ -58,9 +58,24 @@ @interface NSTabViewItem (GTMUnitTestingAdditions) @end +@interface NSToolbar (GTMUnitTestingAdditions) +@end + +@interface NSToolbarItem (GTMUnitTestingAdditions) +@end + @interface NSMatrix (GTMUnitTestingAdditions) @end +@interface NSBox (GTMUnitTestingAdditions) +@end + +@interface NSSegmentedControl (GTMUnitTestingAdditions) +@end + +@interface NSComboBox (GTMUnitTestingAdditions) +@end + @protocol GTMUnitTestViewDrawer; // Fails when the |a1|'s drawing in an area |a2| does not equal the image file named |a3|. @@ -77,8 +92,8 @@ // a3: The name of the image file to check against. // Do not include the extension // a4: contextInfo to pass to drawer -// description: A format string as in the printf() function. -// Can be nil or an empty string but must be present. +// description: A format string as in the printf() function. +// Can be nil or an empty string but must be present. // ...: A variable number of arguments to the format string. Can be absent. // @@ -99,11 +114,11 @@ // See NSObject+UnitTesting.h for details. @interface NSView (GTMUnitTestingAdditions) <GTMUnitTestingImaging> // Returns whether unitTestEncodeState should recurse into subviews -// -// If you have "Full keyboard access" in the -// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes -// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the -// case of NSTextFields we don't want to recurse into their subviews. There may +// +// If you have "Full keyboard access" in the +// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes +// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the +// case of NSTextFields we don't want to recurse into their subviews. There may // be other cases like this, so instead of specializing unitTestEncodeState: to // look for NSTextFields, NSTextFields will just not allow us to recurse into // their subviews. @@ -114,7 +129,7 @@ @end -// A view that allows you to delegate out drawing using the formal +// A view that allows you to delegate out drawing using the formal // GTMUnitTestViewDelegate protocol // This is useful when writing up unit tests for visual elements. // Your test will often end up looking like this: @@ -127,7 +142,7 @@ // the contents of the file Foo.tif to make sure it's valid @interface GTMUnitTestView : NSView { @private - id<GTMUnitTestViewDrawer> drawer_; // delegate for doing drawing (STRONG) + id<GTMUnitTestViewDrawer> drawer_; // delegate for doing drawing (STRONG) void* contextInfo_; // info passed in by user for them to use when drawing } @@ -137,7 +152,7 @@ // rect: the area to draw. // drawer: the object that will do the drawing via the GTMUnitTestViewDrawer // protocol -// contextInfo: +// contextInfo: - (id)initWithFrame:(NSRect)frame drawer:(id<GTMUnitTestViewDrawer>)drawer contextInfo:(void*)contextInfo; @end diff --git a/UnitTesting/GTMAppKit+UnitTesting.m b/UnitTesting/GTMAppKit+UnitTesting.m index 1fc0dc1..8bca7ca 100644 --- a/UnitTesting/GTMAppKit+UnitTesting.m +++ b/UnitTesting/GTMAppKit+UnitTesting.m @@ -1,16 +1,16 @@ // // GTMAppKit+UnitTesting.m -// +// // Categories for making unit testing of graphics/UI easier. -// +// // Copyright 2006-2008 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -30,13 +30,13 @@ #define ENCODE_NSINTEGER(coder, i, key) [(coder) encodeInteger:(i) forKey:(key)] #endif -@implementation NSApplication (GMUnitTestingAdditions) +@implementation NSApplication (GTMUnitTestingAdditions) GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); - (void)gtm_unitTestEncodeState:(NSCoder*)inCoder { [super gtm_unitTestEncodeState:inCoder]; ENCODE_NSINTEGER(inCoder, [[self mainWindow] windowNumber], @"ApplicationMainWindow"); - + // Descend down into the windows allowing them to store their state NSWindow *window = nil; int i = 0; @@ -44,15 +44,15 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); if ([window isVisible]) { // Only record visible windows because invisible windows may be closing on us // This appears to happen differently in 64 bit vs 32 bit, and items - // in the window may hold an extra retain count for a while until the + // in the window may hold an extra retain count for a while until the // event loop is spun. To avoid all this, we just don't record non // visible windows. - // See rdar://5851458 for details. + // See rdar://5851458 for details. [inCoder encodeObject:window forKey:[NSString stringWithFormat:@"Window %d", i]]; i = i + 1; } } - + // and encode the menu bar NSMenu *mainMenu = [self mainMenu]; if (mainMenu) { @@ -61,9 +61,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); } @end -@implementation NSWindow (GMUnitTestingAdditions) +@implementation NSWindow (GTMUnitTestingAdditions) -- (CGImageRef)gtm_unitTestImage { +- (CGImageRef)gtm_unitTestImage { return [[[self contentView] superview] gtm_unitTestImage]; } @@ -71,8 +71,8 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); [super gtm_unitTestEncodeState:inCoder]; [inCoder encodeObject:[self title] forKey:@"WindowTitle"]; [inCoder encodeBool:[self isVisible] forKey:@"WindowIsVisible"]; - // Do not record if window is key, because users running unit tests - // and clicking around to other apps, could change this mid test causing + // Do not record if window is key, because users running unit tests + // and clicking around to other apps, could change this mid test causing // issues. // [inCoder encodeBool:[self isKeyWindow] forKey:@"WindowIsKey"]; [inCoder encodeBool:[self isMainWindow] forKey:@"WindowIsMain"]; @@ -84,7 +84,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSControl (GTMUnitTestingAdditions) +@implementation NSControl (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -103,7 +103,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSButton (GTMUnitTestingAdditions) +@implementation NSButton (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -127,9 +127,25 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); return NO; } +// Encodes the state of an object in a manner suitable for comparing +// against a master state file so we can determine whether the +// object is in a suitable state. +// +// Arguments: +// inCoder - the coder to encode our state into +- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder { + [super gtm_unitTestEncodeState:inCoder]; + id controlCell = [self cell]; + if ([controlCell isKindOfClass:[NSTextFieldCell class]]) { + NSTextFieldCell *textFieldCell = controlCell; + [inCoder encodeObject:[textFieldCell placeholderString] + forKey:@"PlaceHolderString"]; + } +} + @end -@implementation NSCell (GTMUnitTestingAdditions) +@implementation NSCell (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -157,7 +173,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSImage (GTMUnitTestingAdditions) +@implementation NSImage (GTMUnitTestingAdditions) - (void)gtm_unitTestEncodeState:(NSCoder*)inCoder { [super gtm_unitTestEncodeState:inCoder]; @@ -172,14 +188,14 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); CGSize cgSize = GTMNSSizeToCGSize(size); CGContextRef contextRef = GTMCreateUnitTestBitmapContextOfSizeWithData(cgSize, NULL); - NSGraphicsContext *bitmapContext + NSGraphicsContext *bitmapContext = [NSGraphicsContext graphicsContextWithGraphicsPort:contextRef flipped:NO]; _GTMDevAssert(bitmapContext, @"Couldn't create ns bitmap context"); - + [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:bitmapContext]; [self drawInRect:rect fromRect:rect operation:NSCompositeCopy fraction:1.0]; - + CGImageRef image = CGBitmapContextCreateImage(contextRef); CFRelease(contextRef); [NSGraphicsContext restoreGraphicsState]; @@ -201,7 +217,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); // Hack here to work around // rdar://5881796 Application menu item title wrong when accessed programatically // which causes us to have different results on x86_64 vs x386. - // Hack is braced intentionally. We don't record the title of the + // Hack is braced intentionally. We don't record the title of the // "application" menu or it's menu title because they are wrong on 32 bit. // They appear to work right on 64bit. { @@ -246,7 +262,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); [inCoder encodeObject:[self toolTip] forKey:@"MenuItemTooltip"]; ENCODE_NSINTEGER(inCoder, [self tag], @"MenuItemTag"); ENCODE_NSINTEGER(inCoder, [self indentationLevel], @"MenuItemIndentationLevel"); - + // Do our submenu if neccessary if ([self hasSubmenu]) { [inCoder encodeObject:[self submenu] forKey:@"MenuItemSubmenu"]; @@ -255,7 +271,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSTabView (GTMUnitTestingAdditions) +@implementation NSTabView (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -276,7 +292,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSTabViewItem (GTMUnitTestingAdditions) +@implementation NSTabViewItem (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -292,7 +308,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSToolbar (GTMUnitTestingAdditions) +@implementation NSToolbar (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -313,7 +329,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSToolbarItem (GTMUnitTestingAdditions) +@implementation NSToolbarItem (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -334,7 +350,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSMatrix (GTMUnitTestingAdditions) +@implementation NSMatrix (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing // against a master state file so we can determine whether the @@ -355,7 +371,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); [inCoder encodeSize:[self intercellSpacing] forKey:@"MatrixIntercellSpacing"]; [inCoder encodeObject:[self prototype] forKey:@"MatrixCellPrototype"]; - + // Dump the list of cells NSCell *cell; long i = 0; @@ -368,43 +384,6 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -// A view that allows you to delegate out drawing using the formal -// GTMUnitTestViewDelegate protocol above. This is useful when writing up unit -// tests for visual elements. -// Your test will often end up looking like this: -// - (void)testFoo { -// GTMAssertDrawingEqualToFile(self, NSMakeSize(200, 200), @"Foo", nil, nil); -// } -// and your testSuite will also implement the unitTestViewDrawRect method to do -// it's actual drawing. The above creates a view of size 200x200 that draws -// it's content using |self|'s unitTestViewDrawRect method and compares it to -// the contents of the file Foo.tif to make sure it's valid -@implementation GTMUnitTestView - -- (id)initWithFrame:(NSRect)frame - drawer:(id<GTMUnitTestViewDrawer>)drawer - contextInfo:(void*)contextInfo { - self = [super initWithFrame:frame]; - if (self != nil) { - drawer_ = [drawer retain]; - contextInfo_ = contextInfo; - } - return self; -} - -- (void)dealloc { - [drawer_ release]; - [super dealloc]; -} - - -- (void)drawRect:(NSRect)rect { - [drawer_ gtm_unitTestViewDrawRect:rect contextInfo:contextInfo_]; -} - - -@end - @implementation NSBox (GTMUnitTestingAdditions) // Encodes the state of an object in a manner suitable for comparing @@ -445,7 +424,79 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); @end -@implementation NSView (GTMUnitTestingAdditions) +@implementation NSComboBox (GTMUnitTestingAdditions) + +- (BOOL)gtm_shouldEncodeStateForSubviews { + // Subclass of NSTextView, don't want subviews for the same reason. + return NO; +} + +// Encodes the state of an NSSegmentedControl and all its segments. +// +// Arguments: +// inCoder - the coder to encode state into +- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder { + [super gtm_unitTestEncodeState:inCoder]; + + NSInteger aCount = [self numberOfItems]; + ENCODE_NSINTEGER(inCoder, aCount, @"ComboBoxNumberOfItems"); + aCount = [self numberOfVisibleItems]; + ENCODE_NSINTEGER(inCoder, aCount, @"ComboBoxNumberOfVisibleItems"); + + // Include the objectValues if it doesn't use a data source. + if (![self usesDataSource]) { + NSArray *objectValues = [self objectValues]; + for (NSUInteger i = 0; i < [objectValues count]; ++i) { + id value = [objectValues objectAtIndex:i]; + if ([value isKindOfClass:[NSString class]]) { + NSString *key = [NSString stringWithFormat:@"ComboBoxObjectValue %u", i]; + [inCoder encodeObject:value forKey:key]; + } + } + } +} + +@end + + +// A view that allows you to delegate out drawing using the formal +// GTMUnitTestViewDelegate protocol above. This is useful when writing up unit +// tests for visual elements. +// Your test will often end up looking like this: +// - (void)testFoo { +// GTMAssertDrawingEqualToFile(self, NSMakeSize(200, 200), @"Foo", nil, nil); +// } +// and your testSuite will also implement the unitTestViewDrawRect method to do +// it's actual drawing. The above creates a view of size 200x200 that draws +// it's content using |self|'s unitTestViewDrawRect method and compares it to +// the contents of the file Foo.tif to make sure it's valid +@implementation GTMUnitTestView + +- (id)initWithFrame:(NSRect)frame + drawer:(id<GTMUnitTestViewDrawer>)drawer + contextInfo:(void*)contextInfo { + self = [super initWithFrame:frame]; + if (self != nil) { + drawer_ = [drawer retain]; + contextInfo_ = contextInfo; + } + return self; +} + +- (void)dealloc { + [drawer_ release]; + [super dealloc]; +} + + +- (void)drawRect:(NSRect)rect { + [drawer_ gtm_unitTestViewDrawRect:rect contextInfo:contextInfo_]; +} + + +@end + +@implementation NSView (GTMUnitTestingAdditions) // Returns an image containing a representation of the object // suitable for use in comparing against a master image. @@ -461,10 +512,10 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); CGSize cgSize = GTMNSSizeToCGSize(bounds.size); CGContextRef contextRef = GTMCreateUnitTestBitmapContextOfSizeWithData(cgSize, NULL); - NSGraphicsContext *bitmapContext + NSGraphicsContext *bitmapContext = [NSGraphicsContext graphicsContextWithGraphicsPort:contextRef flipped:NO]; _GTMDevAssert(bitmapContext, @"Couldn't create ns bitmap context"); - + // Save our state and turn off font smoothing and antialias. CGContextSaveGState(contextRef); CGContextSetShouldSmoothFonts(contextRef, false); @@ -479,9 +530,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); // Returns whether gtm_unitTestEncodeState should recurse into subviews // of a particular view. // If you have "Full keyboard access" in the -// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes -// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the -// case of NSTextFields we don't want to recurse into their subviews. There may +// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes +// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the +// case of NSTextFields we don't want to recurse into their subviews. There may // be other cases like this, so instead of specializing gtm_unitTestEncodeState: to // look for NSTextFields, NSTextFields will just not allow us to recurse into // their subviews. @@ -504,12 +555,12 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:); [inCoder encodeObject:[self toolTip] forKey:@"ViewToolTip"]; NSArray *supportedAttrs = [self accessibilityAttributeNames]; if ([supportedAttrs containsObject:NSAccessibilityHelpAttribute]) { - NSString *help + NSString *help = [self accessibilityAttributeValue:NSAccessibilityHelpAttribute]; [inCoder encodeObject:help forKey:@"ViewAccessibilityHelp"]; } if ([supportedAttrs containsObject:NSAccessibilityDescriptionAttribute]) { - NSString *description + NSString *description = [self accessibilityAttributeValue:NSAccessibilityDescriptionAttribute]; [inCoder encodeObject:description forKey:@"ViewAccessibilityDescription"]; } diff --git a/UnitTesting/GTMAppKitUnitTestingUtilities.h b/UnitTesting/GTMAppKitUnitTestingUtilities.h index d29f63a..1edccd7 100644 --- a/UnitTesting/GTMAppKitUnitTestingUtilities.h +++ b/UnitTesting/GTMAppKitUnitTestingUtilities.h @@ -6,9 +6,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -29,7 +29,7 @@ // This should be called in main, before NSApplicationMain is called. + (void)setUpForUIUnitTests; -// Syntactic sugar combining that checks to see if we are running unittests +// Syntactic sugar combining that checks to see if we are running unittests // and then calls setUpForUIUnitTests wrapped up in a NSAutoreleasePool so that // your main can look like this: // int main(int argc, const char *argv[]) { @@ -42,11 +42,11 @@ // the screen saver is active. + (BOOL)isScreenSaverActive; -// Allows for posting either a keydown or a keyup with all the modifiers being -// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask +// Allows for posting either a keydown or a keyup with all the modifiers being +// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask // generates two events (a shift key key down and a 'g' key keydown). Make sure -// to balance this with a keyup, or things could get confused. Events get posted -// using the CGRemoteOperation events which means that it gets posted in the +// to balance this with a keyup, or things could get confused. Events get posted +// using the CGRemoteOperation events which means that it gets posted in the // system event queue. Thus you can affect other applications if your app isn't // the active app (or in some cases, such as hotkeys, even if it is). // Arguments: @@ -58,12 +58,12 @@ // cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask, // NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and // NSCommandKeyMask -+ (void)postKeyEvent:(NSEventType)type - character:(CGCharCode)keyChar ++ (void)postKeyEvent:(NSEventType)type + character:(CGCharCode)keyChar modifiers:(UInt32)cocoaModifiers; // Syntactic sugar for posting a keydown immediately followed by a key up event -// which is often what you really want. +// which is often what you really want. // Arguments: // keyChar - character on the keyboard to type. Make sure it is lower case. // If you need upper case, pass in the NSShiftKeyMask in the @@ -72,20 +72,20 @@ // cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask, // NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and // NSCommandKeyMask -+ (void)postTypeCharacterEvent:(CGCharCode)keyChar ++ (void)postTypeCharacterEvent:(CGCharCode)keyChar modifiers:(UInt32)cocoaModifiers; @end // Some category methods to simplify spinning the runloops in such a way as // to make tests less flaky, but have them complete as fast as possible. -@interface NSApplication (GTMUnitTestingAdditions) -// Has NSApplication call nextEventMatchingMask repeatedly until -// [context shouldStop] returns YES or it returns nil because the current date +@interface NSApplication (GTMUnitTestingRunAdditions) +// Has NSApplication call nextEventMatchingMask repeatedly until +// [context shouldStop] returns YES or it returns nil because the current date // is greater than |date|. // Return YES if the runloop was stopped because [context shouldStop] returned // YES. -- (BOOL)gtm_runUntilDate:(NSDate *)date +- (BOOL)gtm_runUntilDate:(NSDate *)date context:(id<GTMUnitTestingRunLoopContext>)context; // Calls -gtm_runUntilDate:context: with the timeout date set to 60 seconds. diff --git a/UnitTesting/GTMAppKitUnitTestingUtilities.m b/UnitTesting/GTMAppKitUnitTestingUtilities.m index 551738e..ff9442e 100644 --- a/UnitTesting/GTMAppKitUnitTestingUtilities.m +++ b/UnitTesting/GTMAppKitUnitTestingUtilities.m @@ -6,9 +6,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -44,7 +44,7 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode); // Give some names to undocumented defaults values const NSInteger MediumFontSmoothing = 2; const NSInteger BlueTintedAppearance = 1; - + // This sets up some basic values that we want as our defaults for doing pixel // based user interface tests. These defaults only apply to the unit test app, // except or the color profile which will be set system wide, and then @@ -59,17 +59,17 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode); // Blue aqua [defaults setInteger:BlueTintedAppearance forKey:@"AppleAquaColorVariant"]; // Standard highlight colors - [defaults setObject:@"0.709800 0.835300 1.000000" + [defaults setObject:@"0.709800 0.835300 1.000000" forKey:@"AppleHighlightColor"]; - [defaults setObject:@"0.500000 0.500000 0.500000" + [defaults setObject:@"0.500000 0.500000 0.500000" forKey:@"AppleOtherHighlightColor"]; // Use english plz [defaults setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"]; // How fast should we draw sheets. This speeds up the sheet tests considerably [defaults setFloat:.001f forKey:@"NSWindowResizeTime"]; - // Switch over the screen profile to "generic rgb". This installs an + // Switch over the screen profile to "generic rgb". This installs an // atexit handler to return our profile back when we are done. - GTMSetColorProfileToGenericRGB(); + GTMSetColorProfileToGenericRGB(); } + (void)setUpForUIUnitTestsIfBeingTested { @@ -84,27 +84,27 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode); BOOL answer = NO; ProcessSerialNumber psn; if (GetFrontProcess(&psn) == noErr) { - CFDictionaryRef cfProcessInfo - = ProcessInformationCopyDictionary(&psn, + CFDictionaryRef cfProcessInfo + = ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask); NSDictionary *processInfo = GTMCFAutorelease(cfProcessInfo); - + NSString *bundlePath = [processInfo objectForKey:@"BundlePath"]; // ScreenSaverEngine is the frontmost app if the screen saver is actually // running Security Agent is the frontmost app if the "enter password" // dialog is showing NSString *bundleName = [bundlePath lastPathComponent]; - answer = ([bundleName isEqualToString:@"ScreenSaverEngine.app"] + answer = ([bundleName isEqualToString:@"ScreenSaverEngine.app"] || [bundleName isEqualToString:@"SecurityAgent.app"]); } return answer; } -// Allows for posting either a keydown or a keyup with all the modifiers being -// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask +// Allows for posting either a keydown or a keyup with all the modifiers being +// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask // generates two events (a shift key key down and a 'g' key keydown). Make sure -// to balance this with a keyup, or things could get confused. Events get posted -// using the CGRemoteOperation events which means that it gets posted in the +// to balance this with a keyup, or things could get confused. Events get posted +// using the CGRemoteOperation events which means that it gets posted in the // system event queue. Thus you can affect other applications if your app isn't // the active app (or in some cases, such as hotkeys, even if it is). // Arguments: @@ -116,8 +116,8 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode); // cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask, // NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and // NSCommandKeyMask -+ (void)postKeyEvent:(NSEventType)type - character:(CGCharCode)keyChar ++ (void)postKeyEvent:(NSEventType)type + character:(CGCharCode)keyChar modifiers:(UInt32)cocoaModifiers { require(![self isScreenSaverActive], CantWorkWithScreenSaver); require(type == NSKeyDown || type == NSKeyUp, CantDoEvent); @@ -135,7 +135,7 @@ CantWorkWithScreenSaver: } // Syntactic sugar for posting a keydown immediately followed by a key up event -// which is often what you really want. +// which is often what you really want. // Arguments: // keyChar - character on the keyboard to type. Make sure it is lower case. // If you need upper case, pass in the NSShiftKeyMask in the @@ -158,8 +158,8 @@ BOOL GTMAreCMProfilesEqual(CMProfileRef a, CMProfileRef b) { CMProfileMD5 bMD5; CMError aMD5Err = CMGetProfileMD5(a, aMD5); CMError bMD5Err = CMGetProfileMD5(b, bMD5); - equal = (!aMD5Err && - !bMD5Err && + equal = (!aMD5Err && + !bMD5Err && !memcmp(aMD5, bMD5, sizeof(CMProfileMD5))) ? YES : NO; } return equal; @@ -168,7 +168,7 @@ BOOL GTMAreCMProfilesEqual(CMProfileRef a, CMProfileRef b) { void GTMRestoreColorProfile(void) { if (gGTMCurrentColorProfile) { CGDirectDisplayID displayID = CGMainDisplayID(); - CMError error = CMSetProfileByAVID((UInt32)displayID, + CMError error = CMSetProfileByAVID((UInt32)displayID, gGTMCurrentColorProfile); CMCloseProfile(gGTMCurrentColorProfile); if (error) { @@ -177,7 +177,7 @@ void GTMRestoreColorProfile(void) { _GTMDevLog(@"Failed to restore previous color profile! " "You may need to open System Preferences : Displays : Color " "and manually restore your color settings. (Error: %i)", error); - // COV_NF_END + // COV_NF_END } else { _GTMDevLog(@"Color profile restored"); } @@ -204,7 +204,7 @@ void GTMSetColorProfileToGenericRGB(void) { // No way to force this case in a unittest. _GTMDevLog(@"Failed to get current color profile. " "I will not be able to restore your current profile, thus I'm " - "not changing it. Many unit tests may fail as a result. (Error: %i)", + "not changing it. Many unit tests may fail as a result. (Error: %i)", error); return; // COV_NF_END @@ -217,14 +217,14 @@ void GTMSetColorProfileToGenericRGB(void) { CFStringRef genericProfileName; CMCopyProfileDescriptionString(previousProfile, &previousProfileName); CMCopyProfileDescriptionString(genericProfile, &genericProfileName); - - _GTMDevLog(@"Temporarily changing your system color profile from \"%@\" to \"%@\".", + + _GTMDevLog(@"Temporarily changing your system color profile from \"%@\" to \"%@\".", previousProfileName, genericProfileName); _GTMDevLog(@"This allows the pixel-based unit-tests to have consistent color " "values across all machines."); _GTMDevLog(@"The colors on your screen will change for the duration of the testing."); - - + + if ((error = CMSetProfileByAVID((UInt32)displayID, genericProfile))) { // COV_NF_START // No way to force this case in a unittest. @@ -256,30 +256,30 @@ void GTMSetColorProfileToGenericRGB(void) { // NS*FunctionKeys as well. static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode) { // character map taken from http://classicteck.com/rbarticles/mackeyboard.php - int characters[] = { - 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', 256, 'b', 'q', 'w', - 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-', - '8', '0', ']', 'o', 'u', '[', 'i', 'p', '\n', 'l', 'j', '\'', 'k', ';', - '\\', ',', '/', 'n', 'm', '.', '\t', ' ', '`', '\b', 256, '\e' + int characters[] = { + 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', 256, 'b', 'q', 'w', + 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-', + '8', '0', ']', 'o', 'u', '[', 'i', 'p', '\n', 'l', 'j', '\'', 'k', ';', + '\\', ',', '/', 'n', 'm', '.', '\t', ' ', '`', '\b', 256, '\e' }; - - // function key map taken from + + // function key map taken from // file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSEvent.html - int functionKeys[] = { + int functionKeys[] = { // NSUpArrowFunctionKey - NSF12FunctionKey - 126, 125, 123, 124, 122, 120, 99, 118, 96, 97, 98, 100, 101, 109, 103, 111, + 126, 125, 123, 124, 122, 120, 99, 118, 96, 97, 98, 100, 101, 109, 103, 111, // NSF13FunctionKey - NSF28FunctionKey - 105, 107, 113, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, - // NSF29FunctionKey - NSScrollLockFunctionKey - 256, 256, 256, 256, 256, 256, 256, 256, 117, 115, 256, 119, 116, 121, 256, 256, + 105, 107, 113, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, + // NSF29FunctionKey - NSScrollLockFunctionKey + 256, 256, 256, 256, 256, 256, 256, 256, 117, 115, 256, 119, 116, 121, 256, 256, // NSPauseFunctionKey - NSPrevFunctionKey 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, // NSNextFunctionKey - NSModeSwitchFunctionKey - 256, 256, 256, 256, 256, 256, 114, 1 - }; - + 256, 256, 256, 256, 256, 256, 114, 1 + }; + CGKeyCode outCode = 0; - + // Look in the function keys if (charCode >= NSUpArrowFunctionKey && charCode <= NSModeSwitchFunctionKey) { outCode = functionKeys[charCode - NSUpArrowFunctionKey]; @@ -295,18 +295,18 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode) { return outCode; } -@implementation NSApplication (GTMUnitTestingAdditions) +@implementation NSApplication (GTMUnitTestingRunAdditions) -- (BOOL)gtm_runUntilDate:(NSDate *)date +- (BOOL)gtm_runUntilDate:(NSDate *)date context:(id<GTMUnitTestingRunLoopContext>)context { BOOL contextShouldStop = NO; while (1) { contextShouldStop = [context shouldStop]; if (contextShouldStop) break; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:date - inMode:NSDefaultRunLoopMode + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:date + inMode:NSDefaultRunLoopMode dequeue:YES]; if (!event) { [pool drain]; |