diff options
Diffstat (limited to 'iPhone')
40 files changed, 92 insertions, 490 deletions
diff --git a/iPhone/GTMFadeTruncatingLabelTest.m b/iPhone/GTMFadeTruncatingLabelTest.m index 052a32f..478ce9a 100644 --- a/iPhone/GTMFadeTruncatingLabelTest.m +++ b/iPhone/GTMFadeTruncatingLabelTest.m @@ -15,7 +15,6 @@ // License for the specific language governing permissions and limitations under // the License. // -#import "GTMNSObject+UnitTesting.h" #import "GTMSenTestCase.h" #import "GTMFadeTruncatingLabel.h" @@ -30,26 +29,14 @@ initWithFrame:CGRectMake(0, 0, 200, 25)] autorelease]; label.text = @"A very long string that won't fit"; - GTMAssertObjectImageEqualToImageNamed(label, - @"GTMFadeTruncatingLabelTest1", - @"Mismatched image."); label.text = @"A short string"; - GTMAssertObjectImageEqualToImageNamed(label, - @"GTMFadeTruncatingLabelTest2", - @"Mismatched image."); // Dark background, light text. label.backgroundColor = [UIColor blackColor]; [label setTextColor:[UIColor whiteColor]]; label.text = @"A very long string that won't fit"; - GTMAssertObjectImageEqualToImageNamed(label, - @"GTMFadeTruncatingLabelTest3", - @"Mismatched image."); label.text = @"A short string"; - GTMAssertObjectImageEqualToImageNamed(label, - @"GTMFadeTruncatingLabelTest4", - @"Mismatched image."); } - (void)testFadeTruncatingLabelLeftAndRight { @@ -59,9 +46,6 @@ label.truncateMode = GTMFadeTruncatingHeadAndTail; label.text = @"Fade on both left and right"; - GTMAssertObjectImageEqualToImageNamed(label, - @"GTMFadeTruncatingLabelTest5", - @"Mismatched image."); } @end diff --git a/iPhone/GTMUIFont+LineHeight.m b/iPhone/GTMUIFont+LineHeight.m index 6d5ef11..21f1fda 100644 --- a/iPhone/GTMUIFont+LineHeight.m +++ b/iPhone/GTMUIFont+LineHeight.m @@ -20,6 +20,11 @@ #import <Availability.h> +// Export a nonsense symbol to suppress a libtool warning when this is linked +// alone in a static lib. +__attribute__((visibility("default"))) + char GTMUIFont_LineHeightExportToSuppressLibToolWarning = 0; + @implementation UIFont (GTMLineHeight) - (CGFloat)gtm_lineHeight { #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 diff --git a/iPhone/GTMUIFont+LineHeightTest.m b/iPhone/GTMUIFont+LineHeightTest.m index 8da28eb..29e5021 100644 --- a/iPhone/GTMUIFont+LineHeightTest.m +++ b/iPhone/GTMUIFont+LineHeightTest.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 @@ -27,14 +27,14 @@ - (void)testLineHeight { UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; - STAssertNotNil(font, nil); - STAssertGreaterThanOrEqual([font gtm_lineHeight], (CGFloat)5.0, nil); + XCTAssertNotNil(font); + XCTAssertGreaterThanOrEqual([font gtm_lineHeight], (CGFloat)5.0); UIFont *fontSmall = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]]; - STAssertNotNil(fontSmall, nil); - STAssertGreaterThanOrEqual([fontSmall gtm_lineHeight], (CGFloat)5.0, nil); - - STAssertGreaterThan([font gtm_lineHeight], [fontSmall gtm_lineHeight], nil); + XCTAssertNotNil(fontSmall); + XCTAssertGreaterThanOrEqual([fontSmall gtm_lineHeight], (CGFloat)5.0); + + XCTAssertGreaterThan([font gtm_lineHeight], [fontSmall gtm_lineHeight]); } @end diff --git a/iPhone/GTMUIImage+ResizeTest.m b/iPhone/GTMUIImage+ResizeTest.m index 458daa7..1bbe04e 100644 --- a/iPhone/GTMUIImage+ResizeTest.m +++ b/iPhone/GTMUIImage+ResizeTest.m @@ -17,14 +17,8 @@ // #import "GTMSenTestCase.h" -#import "GTMNSObject+UnitTesting.h" #import "GTMUIImage+Resize.h" -#define GTMUIImageResizeAssertImageEqual(imageObject, imageSuffix) \ - GTMAssertObjectImageEqualToImageNamed(imageObject, \ - @"GTMUIImage+Resize_" imageSuffix,\ - @"Resized image mismatched.") - @interface GTMUIImage_ResizeTest : GTMTestCase - (UIImage *)testImageNamed:(NSString *)imageName; @end @@ -43,7 +37,7 @@ UIImage *actual = [image gtm_imageByResizingToSize:CGSizeMake(100, 100) preserveAspectRatio:YES trimToFit:NO]; - STAssertNil(actual, @"Invalid inputs should return nil"); + XCTAssertNil(actual, @"Invalid inputs should return nil"); } - (void)testInvalidInput { @@ -53,62 +47,59 @@ actual = [image gtm_imageByResizingToSize:CGSizeZero preserveAspectRatio:YES trimToFit:NO]; - STAssertNil(actual, @"CGSizeZero resize should be ignored."); + XCTAssertNil(actual, @"CGSizeZero resize should be ignored."); actual = [image gtm_imageByResizingToSize:CGSizeMake(0.1, 0.1) preserveAspectRatio:YES trimToFit:NO]; - STAssertNil(actual, @"Invalid size should be ignored."); + XCTAssertNil(actual, @"Invalid size should be ignored."); actual = [image gtm_imageByResizingToSize:CGSizeMake(-100, -100) preserveAspectRatio:YES trimToFit:NO]; - STAssertNil(actual, @"Invalid size should be ignored."); + XCTAssertNil(actual, @"Invalid size should be ignored."); } - (void)testImageByResizingWithoutPreservingAspectRatio { UIImage *actual = nil; // Square image. UIImage *originalImage = [self testImageNamed:@"GTMUIImage+Resize_100x100"]; - STAssertNotNil(originalImage, @"Unable to read image."); + XCTAssertNotNil(originalImage, @"Unable to read image."); // Resize with same aspect ratio. CGSize size50x50 = CGSizeMake(50, 50); actual = [originalImage gtm_imageByResizingToSize:size50x50 preserveAspectRatio:NO trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], size50x50), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size50x50), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x100_to_50x50"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size50x50), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size50x50), + NSStringFromCGSize([actual size])); // Resize with different aspect ratio CGSize size60x40 = CGSizeMake(60, 40); actual = [originalImage gtm_imageByResizingToSize:size60x40 preserveAspectRatio:NO trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], size60x40), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size60x40), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x100_to_60x40"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size60x40), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size60x40), + NSStringFromCGSize([actual size])); CGSize size40x60 = CGSizeMake(40, 60); actual = [originalImage gtm_imageByResizingToSize:size40x60 preserveAspectRatio:NO trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], size40x60), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size40x60), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x100_to_40x60"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size40x60), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size40x60), + NSStringFromCGSize([actual size])); } - (void)testImageByResizingPreservingAspectRatioWithoutClip { UIImage *actual = nil; UIImage *landscapeImage = [self testImageNamed:@"GTMUIImage+Resize_100x50"]; - STAssertNotNil(landscapeImage, @"Unable to read image."); + XCTAssertNotNil(landscapeImage, @"Unable to read image."); // Landscape resize to 50x50, but clipped to 50x25. CGSize size50x50 = CGSizeMake(50, 50); @@ -116,11 +107,10 @@ actual = [landscapeImage gtm_imageByResizingToSize:size50x50 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected50x25), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected50x25), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_50x50_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected50x25), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected50x25), + NSStringFromCGSize([actual size])); // Landscape resize to 60x40, but clipped to 60x30. CGSize size60x40 = CGSizeMake(60, 40); @@ -129,11 +119,10 @@ actual = [landscapeImage gtm_imageByResizingToSize:size60x40 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected60x30), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected60x30), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_60x40_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected60x30), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected60x30), + NSStringFromCGSize([actual size])); // Landscape resize to 40x60, but clipped to 40x20. CGSize expected40x20 = CGSizeMake(40, 20); @@ -141,11 +130,10 @@ actual = [landscapeImage gtm_imageByResizingToSize:size40x60 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected40x20), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected40x20), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_40x60_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected40x20), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected40x20), + NSStringFromCGSize([actual size])); // Portrait Image UIImage *portraitImage = [self testImageNamed:@"GTMUIImage+Resize_50x100"]; @@ -155,72 +143,66 @@ actual = [portraitImage gtm_imageByResizingToSize:size50x50 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected25x50), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected25x50), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_50x50_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected25x50), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected25x50), + NSStringFromCGSize([actual size])); // Portrait resize to 60x40, but clipped to 20x40. CGSize expected20x40 = CGSizeMake(20, 40); actual = [portraitImage gtm_imageByResizingToSize:size60x40 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected20x40), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected20x40), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_60x40_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected20x40), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected20x40), + NSStringFromCGSize([actual size])); // Portrait resize to 40x60, but clipped to 30x60. CGSize expected30x60 = CGSizeMake(30, 60); actual = [portraitImage gtm_imageByResizingToSize:size40x60 preserveAspectRatio:YES trimToFit:NO]; - STAssertTrue(CGSizeEqualToSize([actual size], expected30x60), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(expected30x60), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_40x60_noclip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], expected30x60), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(expected30x60), + NSStringFromCGSize([actual size])); } - (void)testImageByResizingPreservingAspectRatioWithClip { UIImage *actual = nil; UIImage *landscapeImage = [self testImageNamed:@"GTMUIImage+Resize_100x50"]; - STAssertNotNil(landscapeImage, @"Unable to read image."); + XCTAssertNotNil(landscapeImage, @"Unable to read image."); // Landscape resize to 50x50 CGSize size50x50 = CGSizeMake(50, 50); actual = [landscapeImage gtm_imageByResizingToSize:size50x50 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size50x50), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size50x50), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_50x50_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size50x50), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size50x50), + NSStringFromCGSize([actual size])); // Landscape resize to 60x40 CGSize size60x40 = CGSizeMake(60, 40); actual = [landscapeImage gtm_imageByResizingToSize:size60x40 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size60x40), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size60x40), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_60x40_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size60x40), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size60x40), + NSStringFromCGSize([actual size])); // Landscape resize to 40x60 CGSize size40x60 = CGSizeMake(40, 60); actual = [landscapeImage gtm_imageByResizingToSize:size40x60 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size40x60), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size40x60), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"100x50_to_40x60_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size40x60), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size40x60), + NSStringFromCGSize([actual size])); // Portrait Image. UIImage *portraitImage = [self testImageNamed:@"GTMUIImage+Resize_50x100"]; @@ -229,56 +211,46 @@ actual = [portraitImage gtm_imageByResizingToSize:size50x50 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size50x50), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size50x50), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_50x50_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size50x50), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size50x50), + NSStringFromCGSize([actual size])); // Portrait resize to 60x40 actual = [portraitImage gtm_imageByResizingToSize:size60x40 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size60x40), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size60x40), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_60x40_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size60x40), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size60x40), + NSStringFromCGSize([actual size])); // Portrait resize to 40x60. actual = [portraitImage gtm_imageByResizingToSize:size40x60 preserveAspectRatio:YES trimToFit:YES]; - STAssertTrue(CGSizeEqualToSize([actual size], size40x60), - @"Resized image should equal size: %@ actual: %@", - NSStringFromCGSize(size40x60), - NSStringFromCGSize([actual size])); - GTMUIImageResizeAssertImageEqual(actual, @"50x100_to_40x60_clip"); + XCTAssertTrue(CGSizeEqualToSize([actual size], size40x60), + @"Resized image should equal size: %@ actual: %@", + NSStringFromCGSize(size40x60), + NSStringFromCGSize([actual size])); } - (void)testImageByRotating { UIImage *actual = nil; UIImage *landscapeImage = [self testImageNamed:@"GTMUIImage+Resize_100x50"]; - STAssertNotNil(landscapeImage, @"Unable to read image."); + XCTAssertNotNil(landscapeImage, @"Unable to read image."); // Rotate 90 degrees. actual = [landscapeImage gtm_imageByRotating:UIImageOrientationRight]; - GTMUIImageResizeAssertImageEqual(actual, @"50x100"); // Rotate 180 degrees. actual = [landscapeImage gtm_imageByRotating:UIImageOrientationDown]; - GTMUIImageResizeAssertImageEqual(actual, - @"100x50_flipped"); - // Rotate 270 degrees. actual = [landscapeImage gtm_imageByRotating:UIImageOrientationLeft]; - GTMUIImageResizeAssertImageEqual(actual, - @"50x100_flipped"); // Rotate 360 degrees. actual = [landscapeImage gtm_imageByRotating:UIImageOrientationUp]; - GTMUIImageResizeAssertImageEqual(actual, @"100x50"); } @end diff --git a/iPhone/GTMUILocalizerTest.m b/iPhone/GTMUILocalizerTest.m index a53c249..434e890 100644 --- a/iPhone/GTMUILocalizerTest.m +++ b/iPhone/GTMUILocalizerTest.m @@ -58,7 +58,7 @@ - (void)checkValues:(NSString *)value onController:(GTMUILocalizerTestViewController *)controller { // Label - STAssertEqualStrings(value, [[controller label] text], nil); + XCTAssertEqualStrings(value, [[controller label] text]); // Button UIControlState allStates[] = { UIControlStateNormal, UIControlStateHighlighted, @@ -66,33 +66,29 @@ UIControlStateSelected }; for (size_t idx = 0; idx < (sizeof(allStates)/sizeof(allStates[0])); ++idx) { UIControlState state = allStates[idx]; - STAssertEqualStrings(value, [[controller button] titleForState:state], nil); + XCTAssertEqualStrings(value, [[controller button] titleForState:state]); } // SegementedControl for (NSUInteger i = 0; i < [[controller segmentedControl] numberOfSegments]; ++i) { - STAssertEqualStrings(value, - [[controller segmentedControl] titleForSegmentAtIndex:i], nil); + XCTAssertEqualStrings(value, + [[controller segmentedControl] titleForSegmentAtIndex:i]); } // SearchBar - STAssertEqualStrings(value, [[controller searchBar] text], nil); - STAssertEqualStrings(value, [[controller searchBar] placeholder], nil); - STAssertEqualStrings(value, [[controller searchBar] prompt], nil); + XCTAssertEqualStrings(value, [[controller searchBar] text]); + XCTAssertEqualStrings(value, [[controller searchBar] placeholder]); + XCTAssertEqualStrings(value, [[controller searchBar] prompt]); // Accessibility label seems to not be working at all. They always are nil. // Even when setting those explicitly there, the getter always returns nil. // This might be because the gobal accessibility switch is not on during the // tests. #if 0 - STAssertEqualStrings(value, [[controller view] accessibilityLabel], - nil); - STAssertEqualStrings(value, [[controller view] accessibilityHint], - nil); - STAssertEqualStrings(value, [[controller label] accessibilityLabel], - nil); - STAssertEqualStrings(value, [[controller label] accessibilityHint], - nil); + XCTAssertEqualStrings(value, [[controller view] accessibilityLabel]); + XCTAssertEqualStrings(value, [[controller view] accessibilityHint]); + XCTAssertEqualStrings(value, [[controller label] accessibilityLabel]); + XCTAssertEqualStrings(value, [[controller label] accessibilityHint]); #endif } diff --git a/iPhone/GTMUIView+SubtreeDescription.h b/iPhone/GTMUIView+SubtreeDescription.h deleted file mode 100644 index e713d3d..0000000 --- a/iPhone/GTMUIView+SubtreeDescription.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// GTMUIView+SubtreeDescription.h -// -// Copyright 2009 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 -// License for the specific language governing permissions and limitations -// under the License. -// -#import <UIKit/UIKit.h> - -// This entire file, and the corresponding .m is similar to, and predates -// Apple's recursiveDescription, used like so: -// -// (lldb) po [[self view] recursiveDescription] -// -// As documented in Technical Note TN2239 iOS Debugging Magic. - -// This entire file, and the corresponding .m is DEBUG only. -// But you can define INCLUDE_UIVIEW_SUBTREE_DESCRIPTION to no-zero to override. -#if DEBUG || INCLUDE_UIVIEW_SUBTREE_DESCRIPTION - -// Example, in debugger, pause the program, then type: -// po [[[UIApplication sharedApplication] keyWindow] subtreeDescription] - -@interface UIView (SubtreeDescription) - -// Returns one line, without leading indent, but with a trailing newline, -// describing the view. -// If you define a |myViewDescriptionLine| method in your own UIView classes, -// this will append that result to its description. -- (NSString *)gtm_subtreeDescriptionLine; - -// For debugging. Returns a nicely indented representation of this view's -// subview hierarchy, each with frame and isHidden. -- (NSString *)subtreeDescription; - -// For debugging. Returns a nicely indented representation of this view's -// layer hierarchy, with frames and isHidden. -// Requires QuartzCore to be useful, but your app will still link without it. -// TODO: should there be an analog of myViewDescriptionLine for layers? -- (NSString *)sublayersDescription; - -@end - -@protocol GTMUIViewSubtreeDescription -// A UIView can implement this and it can add it's own custom description -// in gtm_subtreeDescriptionLine. -- (NSString *)myViewDescriptionLine; -@end - -#endif // DEBUG diff --git a/iPhone/GTMUIView+SubtreeDescription.m b/iPhone/GTMUIView+SubtreeDescription.m deleted file mode 100644 index 519aed0..0000000 --- a/iPhone/GTMUIView+SubtreeDescription.m +++ /dev/null @@ -1,145 +0,0 @@ -// -// GTMUIView+SubtreeDescription.m -// -// Copyright 2009 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 -// License for the specific language governing permissions and limitations -// under the License. -// -#import "GTMUIView+SubtreeDescription.h" - -#if DEBUG || INCLUDE_UIVIEW_SUBTREE_DESCRIPTION - -static void AppendLabelFloat(NSMutableString *s, NSString *label, float f) { - [s appendString:label]; - // Respects gcc warning about using == with floats. - if (fabs(f - floor(f)) < 1.0e-8) { // Essentially integer. - int d = f; - // Respects gcc warning about casting floats to ints. - [s appendFormat:@"%d", d]; - } else { - [s appendFormat:@"%3.1f", f]; - } -} - -static NSMutableString *SublayerDescriptionLine(CALayer *layer) { - NSMutableString *result = [NSMutableString string]; - [result appendFormat:@"%@ %p {", [layer class], layer]; - CGRect frame = [layer frame]; - if (!CGRectIsEmpty(frame)) { - AppendLabelFloat(result, @"x:", frame.origin.x); - AppendLabelFloat(result, @" y:", frame.origin.y); - AppendLabelFloat(result, @" w:", frame.size.width); - AppendLabelFloat(result, @" h:", frame.size.height); - } - [result appendFormat:@"}"]; - if ([layer isHidden]) { - [result appendString:@" hid"]; - } - [result appendString:@"\n"]; - return result; -} - -// |sublayersDescription| has a guard so we'll only call this if it is safe -// to call. -static NSMutableString *SublayerDescriptionAtLevel(CALayer *layer, int level) { - NSMutableString *result = [NSMutableString string]; - for (int i = 0; i < level; ++i) { - [result appendString:@" "]; - } - [result appendString:SublayerDescriptionLine(layer)]; - // |sublayers| is defined in the QuartzCore framework, which isn't guaranteed - // to be linked to this program. (So we don't include the header.) - NSArray *layers = [layer performSelector:NSSelectorFromString(@"sublayers")]; - for (CALayer *l in layers) { - [result appendString:SublayerDescriptionAtLevel(l, level+1)]; - } - return result; -} - -@implementation UIView (SubtreeDescription) - -// TODO: Consider flagging things which might help in debugging: -// - alpha < 10% -// - origin not zero -// - non-opaque -// - transform if not identity -// - view not entirely within ancestor views -// - (possibly) tag==0 -- (NSString *)gtm_subtreeDescriptionLine { - NSMutableString *result = [NSMutableString string]; - [result appendFormat:@"%@ %p {", [self class], self]; - CGRect frame = [self frame]; - if (!CGRectIsEmpty(frame)) { - AppendLabelFloat(result, @"x:", frame.origin.x); - AppendLabelFloat(result, @" y:", frame.origin.y); - AppendLabelFloat(result, @" w:", frame.size.width); - AppendLabelFloat(result, @" h:", frame.size.height); - } - [result appendString:@"}"]; - if ([self isHidden]) { - [result appendString:@" hid"]; - } - - if ([self respondsToSelector:@selector(myViewDescriptionLine)]) { - NSString *customDescription = - [self performSelector:@selector(myViewDescriptionLine)]; - if (customDescription != nil) { - [result appendFormat:@" %@", customDescription]; - } - } - - [result appendString:@"\n"]; - return result; -} - -- (NSString *)gtm_subtreeDescriptionAtLevel:(int)level { - NSMutableString *result = [NSMutableString string]; - for (int i = 0; i < level; ++i) { - [result appendString:@" "]; - } - [result appendString:[self gtm_subtreeDescriptionLine]]; - for (UIView *v in [self subviews]) { - [result appendString:[v gtm_subtreeDescriptionAtLevel:level+1]]; - } - return result; -} - -- (NSString *)subtreeDescription { - NSMutableString *result = - [[[self gtm_subtreeDescriptionLine] mutableCopy] autorelease]; - for (UIView *v in [self subviews]) { - [result appendString:[v gtm_subtreeDescriptionAtLevel:1]]; - } - return result; -} - -// for debugging dump the layer hierarchy, frames and isHidden. -- (NSString *)sublayersDescription { - CALayer *layer = [self layer]; - SEL sublayers = NSSelectorFromString(@"sublayers"); - if (![layer respondsToSelector:sublayers]) { - return @"*** Sorry: This app is not linked with the QuartzCore framework."; - } - NSMutableString *result = SublayerDescriptionLine(layer); - NSArray *layers = [layer performSelector:sublayers]; - for (CALayer *l in layers) { - [result appendString:SublayerDescriptionAtLevel(l, 1)]; - } - return result; -} - -@end - -#endif // DEBUG - - diff --git a/iPhone/GTMUIView+SubtreeDescriptionTest.m b/iPhone/GTMUIView+SubtreeDescriptionTest.m deleted file mode 100644 index b691cd5..0000000 --- a/iPhone/GTMUIView+SubtreeDescriptionTest.m +++ /dev/null @@ -1,150 +0,0 @@ -// -// GTMUIView+SubtreeDescriptionTest.m -// -// Copyright 2009 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 -// License for the specific language governing permissions and limitations -// under the License. -// - -#import "GTMNSObject+UnitTesting.h" -#import "GTMSenTestCase.h" -#import "GTMUIView+SubtreeDescription.h" - -#if !NDEBUG - -@interface GTMUIView_SubtreeDescriptionTest : GTMTestCase -@end - -@implementation GTMUIView_SubtreeDescriptionTest - -- (void)testSubtreeDescription { - // Test a single, simple view. - CGRect frame1 = CGRectMake(0, 0, 100, 200); - UIView *view1 = [[[UIView alloc] initWithFrame:frame1] autorelease]; - NSString *actual = [view1 subtreeDescription]; - NSString *expected = [NSString stringWithFormat: - @"UIView %p {x:0 y:0 w:100 h:200}\n", view1]; - STAssertEqualObjects(actual, expected, @"a single, simple view failed"); - - // Test a view with one child. - CGRect frame2 = CGRectMake(2, 2, 102, 202); - UIView *view2 = [[[UIView alloc] initWithFrame:frame2] autorelease]; - [view1 addSubview:view2]; - NSString *actual2 = [view1 subtreeDescription]; - NSString *expected2 = [NSString stringWithFormat: - @"UIView %p {x:0 y:0 w:100 h:200}\n" - @" UIView %p {x:2 y:2 w:102 h:202}\n", view1, view2]; - STAssertEqualObjects(actual2, expected2, @"a view with one child"); - - // Test a view with two children. - CGRect frame3 = CGRectMake(3, 3, 103, 203); - UIView *view3 = [[[UIView alloc] initWithFrame:frame3] autorelease]; - [view1 addSubview:view3]; - NSString *actual3 = [view1 subtreeDescription]; - NSString *expected3 = [NSString stringWithFormat: - @"UIView %p {x:0 y:0 w:100 h:200}\n" - @" UIView %p {x:2 y:2 w:102 h:202}\n" - @" UIView %p {x:3 y:3 w:103 h:203}\n", - view1, view2, view3]; - STAssertEqualObjects(actual3, expected3, @"a view with two children"); - - // Test a view with two children, one hidden. - [view3 setHidden:YES]; - NSString *actual4 = [view1 subtreeDescription]; - NSString *expected4 = [NSString stringWithFormat: - @"UIView %p {x:0 y:0 w:100 h:200}\n" - @" UIView %p {x:2 y:2 w:102 h:202}\n" - @" UIView %p {x:3 y:3 w:103 h:203} hid\n", - view1, view2, view3]; - STAssertEqualObjects(actual4, expected4, @"with two children, one hidden"); -} - -- (void)testSublayersDescription { - // Test a single, simple layer. - CGRect frame1 = CGRectMake(0, 0, 100, 200); - UIView *view1 = [[[UIView alloc] initWithFrame:frame1] autorelease]; - NSString *actual = [view1 sublayersDescription]; - NSString *expected = [NSString stringWithFormat: - @"CALayer %p {x:0 y:0 w:100 h:200}\n", [view1 layer]]; - STAssertEqualObjects(actual, expected, @"a single, simple layer failed"); - - // Test a layer with one child. - CGRect frame2 = CGRectMake(2, 2, 102, 202); - UIView *view2 = [[[UIView alloc] initWithFrame:frame2] autorelease]; - [view1 addSubview:view2]; - NSString *actual2 = [view1 sublayersDescription]; - NSString *expected2 = [NSString stringWithFormat: - @"CALayer %p {x:0 y:0 w:100 h:200}\n" - @" CALayer %p {x:2 y:2 w:102 h:202}\n", - [view1 layer], [view2 layer]]; - STAssertEqualObjects(actual2, expected2, @"a layer with one child"); - - // Test a layer with two children. - CGRect frame3 = CGRectMake(3, 3, 103, 203); - UIView *view3 = [[[UIView alloc] initWithFrame:frame3] autorelease]; - [view1 addSubview:view3]; - NSString *actual3 = [view1 sublayersDescription]; - NSString *expected3 = [NSString stringWithFormat: - @"CALayer %p {x:0 y:0 w:100 h:200}\n" - @" CALayer %p {x:2 y:2 w:102 h:202}\n" - @" CALayer %p {x:3 y:3 w:103 h:203}\n", - [view1 layer], [view2 layer], [view3 layer]]; - STAssertEqualObjects(actual3, expected3, @"a layer with two children"); - - // Test a layer with two children, one hidden. - [view3 setHidden:YES]; - NSString *actual4 = [view1 sublayersDescription]; - NSString *expected4 = [NSString stringWithFormat: - @"CALayer %p {x:0 y:0 w:100 h:200}\n" - @" CALayer %p {x:2 y:2 w:102 h:202}\n" - @" CALayer %p {x:3 y:3 w:103 h:203} hid\n", - [view1 layer], [view2 layer], [view3 layer]]; - STAssertEqualObjects(actual4, expected4, @"with two children, one hidden"); -} - -@end - -@interface UIMyTestView : UIView -- (NSString *)myViewDescriptionLine; -@end - -@implementation UIMyTestView -- (NSString *)myViewDescriptionLine { - NSString *result = [NSString stringWithFormat:@"alpha: %3.1f", [self alpha]]; - return result; -} -@end - -@interface GTMUIView_SubtreeSubClassDescriptionTest : GTMTestCase -@end - -@implementation GTMUIView_SubtreeSubClassDescriptionTest -- (void)testSubtreeDescription { - CGRect frame1 = CGRectMake(0, 0, 100, 200); - UIView *view1 = [[[UIView alloc] initWithFrame:frame1] autorelease]; - - // Test a view with one child. - CGRect frame2 = CGRectMake(2, 2, 102, 202); - UIView *view2 = [[[UIMyTestView alloc] initWithFrame:frame2] autorelease]; - [view1 addSubview:view2]; - NSString *actual2 = [view1 subtreeDescription]; - NSString *expected2 = [NSString stringWithFormat: - @"UIView %p {x:0 y:0 w:100 h:200}\n" - @" UIMyTestView %p {x:2 y:2 w:102 h:202} alpha: 1.0\n", - view1, view2]; - STAssertEqualObjects(actual2, expected2, @"a view with one subclassed child"); -} -@end - - -#endif diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest1.5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest1.5.png Binary files differdeleted file mode 100644 index 27a1d90..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest1.5.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest1.6.png b/iPhone/TestData/GTMFadeTruncatingLabelTest1.6.png Binary files differdeleted file mode 100644 index e2a2777..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest1.6.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest1.png b/iPhone/TestData/GTMFadeTruncatingLabelTest1.png Binary files differdeleted file mode 100644 index d5d7910..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest1.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest2.5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest2.5.png Binary files differdeleted file mode 100644 index 49377c4..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest2.5.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest2.6.png b/iPhone/TestData/GTMFadeTruncatingLabelTest2.6.png Binary files differdeleted file mode 100644 index cb840ba..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest2.6.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest2.png b/iPhone/TestData/GTMFadeTruncatingLabelTest2.png Binary files differdeleted file mode 100644 index 80d95fd..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest2.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest3.5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest3.5.png Binary files differdeleted file mode 100644 index dd68fe9..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest3.5.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest3.6.png b/iPhone/TestData/GTMFadeTruncatingLabelTest3.6.png Binary files differdeleted file mode 100644 index b9a07fa..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest3.6.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest3.png b/iPhone/TestData/GTMFadeTruncatingLabelTest3.png Binary files differdeleted file mode 100644 index eba21b2..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest3.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest4.5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest4.5.png Binary files differdeleted file mode 100644 index f3bbfb0..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest4.5.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest4.6.png b/iPhone/TestData/GTMFadeTruncatingLabelTest4.6.png Binary files differdeleted file mode 100644 index 1fecc29..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest4.6.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest4.png b/iPhone/TestData/GTMFadeTruncatingLabelTest4.png Binary files differdeleted file mode 100644 index e9f59c8..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest4.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest5.5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest5.5.png Binary files differdeleted file mode 100644 index 60d4242..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest5.5.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest5.6.png b/iPhone/TestData/GTMFadeTruncatingLabelTest5.6.png Binary files differdeleted file mode 100644 index 8c2db75..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest5.6.png +++ /dev/null diff --git a/iPhone/TestData/GTMFadeTruncatingLabelTest5.png b/iPhone/TestData/GTMFadeTruncatingLabelTest5.png Binary files differdeleted file mode 100644 index ba378d2..0000000 --- a/iPhone/TestData/GTMFadeTruncatingLabelTest5.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x100_to_40x60.png b/iPhone/TestData/GTMUIImage+Resize_100x100_to_40x60.png Binary files differdeleted file mode 100644 index 10223fd..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x100_to_40x60.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x100_to_50x50.png b/iPhone/TestData/GTMUIImage+Resize_100x100_to_50x50.png Binary files differdeleted file mode 100644 index ab71afb..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x100_to_50x50.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x100_to_60x40.png b/iPhone/TestData/GTMUIImage+Resize_100x100_to_60x40.png Binary files differdeleted file mode 100644 index 5683f17..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x100_to_60x40.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_flipped.png b/iPhone/TestData/GTMUIImage+Resize_100x50_flipped.png Binary files differdeleted file mode 100644 index c6b1d8f..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_flipped.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_clip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_clip.png Binary files differdeleted file mode 100644 index b7721ad..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_noclip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_noclip.png Binary files differdeleted file mode 100644 index 0e2c9de..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_40x60_noclip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_clip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_clip.png Binary files differdeleted file mode 100644 index e913bfb..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_noclip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_noclip.png Binary files differdeleted file mode 100644 index 365dfb6..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_50x50_noclip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_clip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_clip.png Binary files differdeleted file mode 100644 index b8e6c06..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_noclip.png b/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_noclip.png Binary files differdeleted file mode 100644 index 14d96b0..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_100x50_to_60x40_noclip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_flipped.png b/iPhone/TestData/GTMUIImage+Resize_50x100_flipped.png Binary files differdeleted file mode 100644 index bdce5a2..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_flipped.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_clip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_clip.png Binary files differdeleted file mode 100644 index 3c68940..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_noclip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_noclip.png Binary files differdeleted file mode 100644 index 8a9b227..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_40x60_noclip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_clip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_clip.png Binary files differdeleted file mode 100644 index 6d6a5df..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_noclip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_noclip.png Binary files differdeleted file mode 100644 index c79873a..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_50x50_noclip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_clip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_clip.png Binary files differdeleted file mode 100644 index 87feb9b..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_clip.png +++ /dev/null diff --git a/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_noclip.png b/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_noclip.png Binary files differdeleted file mode 100644 index be94dc6..0000000 --- a/iPhone/TestData/GTMUIImage+Resize_50x100_to_60x40_noclip.png +++ /dev/null |