diff options
Diffstat (limited to 'UnitTesting/GTMUnitTestingTest.m')
-rw-r--r-- | UnitTesting/GTMUnitTestingTest.m | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/UnitTesting/GTMUnitTestingTest.m b/UnitTesting/GTMUnitTestingTest.m index 8ee2244..d14795f 100644 --- a/UnitTesting/GTMUnitTestingTest.m +++ b/UnitTesting/GTMUnitTestingTest.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 @@ -16,17 +16,14 @@ // the License. // -#import <SenTestingKit/SenTestingKit.h> +#import "GTMSenTestCase.h" #import "GTMUnitTestingTest.h" #import "GTMAppKit+UnitTesting.h" NSString *const kGTMWindowNibName = @"GTMUnitTestingTest"; NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; -@interface GTMUnitTestingAbstractTest : GTMTestCase -@end - -@interface GTMUnitTestingTest : GTMUnitTestingAbstractTest { +@interface GTMUnitTestingTest : GTMTestCase { int expectedFailureCount_; } @end @@ -47,17 +44,9 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; @interface GTMUnitTestingProxyTest : NSProxy @end -@implementation GTMUnitTestingAbstractTest -- (void)testAbstractUnitTest { - static int testCount = 0; - testCount += 1; - STAssertEquals(testCount, 1, @"testAbstractUnitTest should only fire once"); -} -@end - @implementation GTMUnitTestingTest - -// Brings up the window defined in the nib and takes a snapshot of it. + +// Brings up the window defined in the nib and takes a snapshot of it. // We use the "empty" GTMUnitTestingTestController controller so that // initWithWindowNibName can find the appropriate bundle to load our nib from. // For some reason when running unit tests, with all the injecting going on @@ -69,24 +58,24 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; // set up our delegates so we can test delegate handling GTMUnitTestingDelegate *appDelegate = [[GTMUnitTestingDelegate alloc] init]; [NSApp setDelegate:appDelegate]; - + // Get our window - GTMUnitTestingTestController *testWindowController + GTMUnitTestingTestController *testWindowController = [[GTMUnitTestingTestController alloc] initWithWindowNibName:kGTMWindowNibName]; NSWindow *window = [testWindowController window]; // Test the app state. This will cover windows and menus - GTMAssertObjectStateEqualToStateNamed(NSApp, - @"GTMUnitTestingTestApp", + GTMAssertObjectStateEqualToStateNamed(NSApp, + @"GTMUnitTestingTestApp", @"Testing the app state"); - - // Test the window image and state - GTMAssertObjectEqualToStateAndImageNamed(window, - kGTMWindowSaveFileName, + + // Test the window image and state + GTMAssertObjectEqualToStateAndImageNamed(window, + kGTMWindowSaveFileName, @"Testing the window image and state"); - + // Verify that all of our delegate encoders got called STAssertTrue([appDelegate didEncode], @"app delegate didn't get called?"); - + // Clean up [NSApp setDelegate:nil]; [appDelegate release]; @@ -95,10 +84,10 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; - (void)testViewUnitTesting { GTMUnitTestingView *unitTestingView = [[GTMUnitTestingView alloc] init]; - GTMAssertDrawingEqualToImageNamed(unitTestingView, - NSMakeSize(200,200), - @"GTMUnitTestingView", - NSApp, + GTMAssertDrawingEqualToImageNamed(unitTestingView, + NSMakeSize(200,200), + @"GTMUnitTestingView", + NSApp, @"Testing view drawing"); STAssertTrue([unitTestingView hadGoodContext], @"bad context?"); [unitTestingView release]; @@ -123,33 +112,33 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; NSString *originalPath = [NSObject gtm_getUnitTestSaveToDirectory]; STAssertNotNil(originalPath, @"No save dir?"); [NSObject gtm_setUnitTestSaveToDirectory:tempDir]; - STAssertEqualObjects(tempDir, [NSObject gtm_getUnitTestSaveToDirectory], + STAssertEqualObjects(tempDir, [NSObject gtm_getUnitTestSaveToDirectory], @"Save to dir not set?"); NSString *statePath = [self gtm_saveToPathForStateNamed:bogusTestName]; STAssertNotNil(statePath, @"no state path?"); NSString *imagePath = [self gtm_saveToPathForImageNamed:bogusTestName]; STAssertNotNil(imagePath, @"no image path?"); - GTMUnitTestingTestController *testWindowController + GTMUnitTestingTestController *testWindowController = [[GTMUnitTestingTestController alloc] initWithWindowNibName:kGTMWindowNibName]; NSWindow *window = [testWindowController window]; - + // Test against a golden master filename that doesn't exist expectedFailureCount_ = 2; GTMAssertObjectEqualToStateAndImageNamed(window, bogusTestName, @"Creating image and state files"); - STAssertEquals(expectedFailureCount_, 0, + STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures creating files"); - + // Change our image and state and verify failures [[testWindowController textField] setStringValue:@"Foo"]; expectedFailureCount_ = 2; - GTMAssertObjectEqualToStateAndImageNamed(window, - kGTMWindowSaveFileName, + GTMAssertObjectEqualToStateAndImageNamed(window, + kGTMWindowSaveFileName, @"Testing the window image and state"); - STAssertEquals(expectedFailureCount_, 0, + STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures testing files"); - + // Now change the size of our image and verify failures NSRect oldFrame = [window frame]; NSRect newFrame = oldFrame; @@ -157,45 +146,45 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; [window setFrame:newFrame display:YES]; expectedFailureCount_ = 1; GTMAssertObjectImageEqualToImageNamed(window, - kGTMWindowSaveFileName, + kGTMWindowSaveFileName, @"Testing the changed window size"); - [window setFrame:oldFrame display:YES]; - + [window setFrame:oldFrame display:YES]; + // Set our unit test save dir to a bogus directory and // run the tests again. [NSObject gtm_setUnitTestSaveToDirectory:@"/zim/blatz/foo/bob/bar"]; expectedFailureCount_ = 2; - GTMAssertObjectEqualToStateAndImageNamed(window, - kGTMWindowSaveFileName, + GTMAssertObjectEqualToStateAndImageNamed(window, + kGTMWindowSaveFileName, @"Testing the window image and state"); - STAssertEquals(expectedFailureCount_, 0, - @"Didn't get expected failures testing files"); + STAssertEquals(expectedFailureCount_, 0, + @"Didn't get expected failures testing files"); expectedFailureCount_ = 2; - GTMAssertObjectEqualToStateAndImageNamed(window, - @"GTMUnitTestingWindowDoesntExist", + GTMAssertObjectEqualToStateAndImageNamed(window, + @"GTMUnitTestingWindowDoesntExist", @"Testing the window image and state"); - STAssertEquals(expectedFailureCount_, 0, - @"Didn't get expected failures testing files"); - + STAssertEquals(expectedFailureCount_, 0, + @"Didn't get expected failures testing files"); + // Reset our unit test save dir [NSObject gtm_setUnitTestSaveToDirectory:nil]; - + // Test against something that doesn't have an image expectedFailureCount_ = 1; - GTMAssertObjectImageEqualToImageNamed(@"a string", - @"GTMStringsDontHaveImages", + GTMAssertObjectImageEqualToImageNamed(@"a string", + @"GTMStringsDontHaveImages", @"Testing that strings should fail"); - STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures testing files"); - + STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures testing files"); + // Test against something that doesn't implement our support expectedFailureCount_ = 1; GTMUnitTestingProxyTest *proxy = [[GTMUnitTestingProxyTest alloc] init]; - GTMAssertObjectStateEqualToStateNamed(proxy, - @"NSProxiesDontDoState", + GTMAssertObjectStateEqualToStateNamed(proxy, + @"NSProxiesDontDoState", @"Testing that NSProxy should fail"); - STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures testing proxy"); + STAssertEquals(expectedFailureCount_, 0, @"Didn't get expected failures testing proxy"); [proxy release]; - + [window close]; } @@ -235,7 +224,7 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow"; return didEncode_; } @end - + @implementation GTMUnitTestingView - (void)gtm_unitTestViewDrawRect:(NSRect)rect contextInfo:(void*)contextInfo { |