Permalink
Browse files

Code cleanup

  • Loading branch information...
1 parent a8732c9 commit ba04d724c6c3dbe461d7ad203641f198bfa62c1b @johnboiles johnboiles committed Oct 27, 2011
@@ -87,7 +87,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if ([node status] == GHTestStatusRunning) {
cell.textLabel.textColor = [UIColor blackColor];
} else if ([node status] == GHTestStatusErrored) {
- //NSLog(@"Got a node: %@", node);
if ([node.test.exception.name isEqualToString:@"GHViewUnavailableException"]) {
cell.textLabel.textColor = [UIColor colorWithRed:0.60 green:0.60 blue:0 alpha:1.0];
} else {
@@ -3,7 +3,28 @@
// GHUnitIOS
//
// Created by John Boiles on 8/8/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
+// Copyright 2011. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
@@ -3,7 +3,28 @@
// GHUnitIOS
//
// Created by John Boiles on 8/8/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
+// Copyright 2011. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
//
#import "GHUnitIOSTestView.h"
@@ -81,7 +81,6 @@ - (NSString *)updateTestView {
[testView_ setOriginalImage:originalImage newImage:newImage text:text];
} else if ([testNode_.test.exception.name isEqualToString:@"GHViewUnavailableException"]) {
NSDictionary *exceptionUserInfo = testNode_.test.exception.userInfo;
- //UIImage *originalImage = [exceptionUserInfo objectForKey:@"OriginalImage"];
UIImage *newImage = [exceptionUserInfo objectForKey:@"NewImage"];
[testView_ setOriginalImage:nil newImage:newImage text:text];
} else {
@@ -123,7 +122,6 @@ - (void)testViewDidSelectNewImage:(GHUnitIOSTestView *)testView {
}
- (void)testViewDidApproveChange:(GHUnitIOSTestView *)testView {
- // TODO(johnb): Change some UI to reflect that the change has been accepted
// Save new image as the approved version
NSString *imageFilename = [testNode_.test.exception.userInfo objectForKey:@"ImageFilename"];
UIImage *newImage = [testNode_.test.exception.userInfo objectForKey:@"NewImage"];
View
@@ -1006,8 +1006,6 @@ continue; \
} while (0)
-//! @cond DEV
-
@interface NSException(GHTestMacros_GTMSenTestAdditions)
+ (NSException *)ghu_failureInFile:(NSString *)filename
atLine:(int)lineNumber
View
@@ -207,7 +207,7 @@ - (BOOL)isCLIDisabled {
}
- (CGSize)sizeForView:(UIView *)view {
- // If the view is a UIScrollView, return the contet
+ // If the view is a UIScrollView, return the contentSize
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)view;
return scrollView.contentSize;
@@ -1006,8 +1006,6 @@ continue; \
} while (0)
-//! @cond DEV
-
@interface NSException(GHTestMacros_GTMSenTestAdditions)
+ (NSException *)ghu_failureInFile:(NSString *)filename
atLine:(int)lineNumber
@@ -1042,6 +1040,10 @@ continue; \
inFile:(NSString *)filename
atLine:(int)lineNumber
withDescription:(NSString *)formatString, ...;
++ (NSException *)ghu_failureWithName:(NSString *)name
+ inFile:(NSString *)filename
+ atLine:(int)lineNumber
+ reason:(NSString *)reason;
@end
// SENTE_END
@@ -29,7 +29,6 @@
#import "GHTestCase.h"
#import "GHAsyncTestCase.h"
-#import "GHViewTestCase.h"
#import "GHTestSuite.h"
#import "GHTestMacros.h"
#import "GHTestRunner.h"
@@ -45,6 +44,7 @@
#if TARGET_OS_IPHONE
#import "GHUnitIOSAppDelegate.h"
+#import "GHViewTestCase.h"
#endif
#ifdef DEBUG
@@ -3,7 +3,28 @@
// GHUnitIOS
//
// Created by John Boiles on 8/8/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
+// Copyright 2011. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
@@ -30,28 +30,87 @@
#import "GHTestCase.h"
#import <UIKit/UIKit.h>
-/*!
+/*!
Assert that a view has not changed. Raises exception if the view has changed or if
no image exists from previous test runs.
@param view The view to verify
*/
#define GHVerifyView(view) \
do { \
-[self verifyView:view inFilename:[NSString stringWithUTF8String:__FILE__] atLineNumber:__LINE__];\
+if (![self isKindOfClass:[GHViewTestCase class]]) \
+[[NSException ghu_failureWithName:@"GHInvalidTestException" \
+inFile:[NSString stringWithUTF8String:__FILE__] \
+atLine:__LINE__ \
+reason:@"GHVerifyView can only be called from within a GHViewTestCase class"] raise]; \
+[self verifyView:view filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__]; \
} while (0)
+/*!
+ View verification test case.
-@interface GHViewTestCase : GHTestCase {
+ Supports GHVerifyView, which renders a view and compares it against a saved
+ image from a previous test run.
+
+ @interface MyViewTest : GHViewTestCase { }
+ @end
+
+ @implementation MyViewTest
+
+ - (void)testMyView {
+ MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
+ GHVerifyView(myView);
+ }
+
+ @end
+
+ */
+@interface GHViewTestCase : GHTestCase {
NSInteger imageVerifyCount_;
}
+/*!
+ Clear all test images in the documents directory
+ */
++ (void)clearTestImages;
+
+/*!
+ Save an image to the documents directory as filename
+
+ @param image Image to save
+ @param filename Filename for the saved image
+ */
++ (void)saveToDocumentsWithImage:(UIImage *)image filename:(NSString *)filename;
+
+/*!
+ Whether the test class should be run as a part of command line tests.
+ By default this is YES since there are some small differences in rendering
+ from the command line vs rendering in the simulator
+
+ @result YES if this test class is disabled for command line tests
+ */
- (BOOL)isCLIDisabled;
-- (void)verifyView:(UIView *)view inFilename:(NSString *)filename atLineNumber:(int)lineNumber;
+/*!
+ Size for a given view. Subclasses can override this to provide custom sizes
+ for views before rendering. The default implementation returns contentSize
+ for scrollviews and returns self.frame.size for all other views.
-+ (void)clearTestImages;
+ @param view View for which to calculate the size
+ @result Size at which the view should be rendered
+ */
+- (CGSize)sizeForView:(UIView *)view;
-+ (void)saveToDocumentsWithImage:(UIImage *)image filename:(NSString *)filename;
+/*!
+ Called from the GHVerifyView macro. This method should not be called manually.
+ Verifies that a view hasn't changed since the last time it was approved. Raises
+ a GHViewChangeException if the view has changed. Raises a GHViewUnavailableException
+ if there is no image from a previous run.
+
+ @param view View to verify
+ @param filename Filename of the call to GHVerifyView
+ @param lineNumber Line number of the call to GHVerifyView
+ */
+- (void)verifyView:(UIView *)view filename:(NSString *)filename lineNumber:(int)lineNumber;
@end

0 comments on commit ba04d72

Please sign in to comment.