Skip to content

Commit

Permalink
Added context tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhard Schraml authored and Gerhard Schraml committed Dec 2, 2009
1 parent cb3bed9 commit 6bf87fa
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
76 changes: 70 additions & 6 deletions ContextDAOTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ @interface ContextDAOTest : GHTestCase {
NSManagedObjectContext* managedObjectContext;
}

- (void)testAddContextWithNameWithoutTitle;

@end

@implementation ContextDAOTest
Expand Down Expand Up @@ -46,12 +44,50 @@ - (void)tearDown {
appDelegate = nil;
}

/* Tests adding a context without a context parameter */
- (void)testAddContextWithNameWithoutTitle {
/* Tests receiving all contexts without adding contexts before */
- (void)testAllContextsEmpty {
NSError *error = nil;
NSArray *contexts = [ContextDAO allContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)0, @"Context count must be 0");
}

/* Tests adding a context with nil as name */
- (void)testAddContextWithNameWithNilTitle {
NSError *error = nil;
Context *returnValue = [ContextDAO addContextWithName:nil error:&error];
GHAssertTrue([error code] == DAOMissingParametersError, @"Context must not be added without name");
GHAssertTrue(returnValue == nil, @"Return value must be nil.");
GHAssertEquals([error code], DAOMissingParametersError, @"Context must not be added without name");
GHAssertNil(returnValue, @"Return value must be nil.");
}

/* Tests adding a context with empty string as name */
- (void)testAddContextWithNameWithEmptyTitle {
NSError *error = nil;
Context *returnValue = [ContextDAO addContextWithName:@"" error:&error];
GHAssertEquals([error code], DAOMissingParametersError, @"Context must not be added without name");
GHAssertNil(returnValue, @"Return value must be nil.");
}

/* adds 3 contexts - count must be 3 */
- (void)testAddContextWithName {
NSError *error = nil;

Context *newContext1 = [ContextDAO addContextWithName:@"Test generated 1" error:&error];
GHAssertNotNil(newContext1, @"Add context1 not successful");
Context *newContext2 = [ContextDAO addContextWithName:@"Test generated 2" error:&error];
GHAssertNotNil(newContext2, @"Add context2 not successful");
Context *newContext3 = [ContextDAO addContextWithName:@"Test generated 3" error:&error];
GHAssertNotNil(newContext3, @"Add context3 not successful");

NSArray *contexts = [ContextDAO allContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)3, @"Add context not successful");
}

/* Tests deleting a context with nil as parameter */
- (void)testDeleteContextWithNilParameter {
NSError *error = nil;
BOOL returnValue = [ContextDAO deleteContext:nil error:&error];
GHAssertEquals([error code], DAOMissingParametersError, @"Context must not be deleted without reference");
GHAssertFalse(returnValue, @"Return value must be NO.");
}

/* first adds a context and then deletes it - count then must be 0 */
Expand All @@ -70,4 +106,32 @@ - (void)testDeleteContext {
GHAssertEquals([contexts count], (NSUInteger)0, @"Delete context not successful");
}

/* Tests updating a context with nil as parameter */
- (void)testUpdateContextWithNilParameter {
NSError *error = nil;
BOOL returnValue = [ContextDAO updateContext:nil error:&error];
GHAssertEquals([error code], DAOMissingParametersError, @"Context must not be updated without reference");
GHAssertFalse(returnValue, @"Return value must be NO.");
}

/* first adds a context and then updates it */
- (void)testUpdateContext {
NSError *error = nil;
Context *newContext = [ContextDAO addContextWithName:@"Test generated" error:&error];
GHAssertNotNil(newContext, @"Add context not successful");

newContext.name = @"UPDATE";
BOOL updateSuccessful = [ContextDAO updateContext:newContext error:&error];
GHAssertTrue(updateSuccessful, @"Update context not successful");

GHAssertTrue([newContext isUpdated], @"Update context not successful");

/*//[NSThread sleepForTimeInterval:2];
NSArray *contexts = [ContextDAO allContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)1, @"Add context not successful");
Context *context = [contexts objectAtIndex:0];
GHAssertEqualStrings([context name], [newContext name], @"Update context not successful"); */
}

@end
28 changes: 16 additions & 12 deletions Less2Do.xcodeproj/gerhard.perspectivev3
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@
<key>Layout</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXBottomSmartGroupGIDs</key>
Expand Down Expand Up @@ -280,17 +278,20 @@
<string>29B97317FDCFA39411CA2CEA</string>
<string>29B97323FDCFA39411CA2CEA</string>
<string>1C37FBAC04509CD000000102</string>
<string>A3F5B54F10C67B0B0054A7FE</string>
<string>A3F5B55010C67B0B0054A7FE</string>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>48</integer>
<integer>4</integer>
<integer>0</integer>
<integer>80</integer>
<integer>75</integer>
<integer>72</integer>
<integer>70</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 613}, {344, 764}}</string>
<string>{{0, 697}, {344, 764}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
Expand Down Expand Up @@ -318,35 +319,38 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>A3E3383E10BC4160004F0F39</string>
<key>PBXProjectModuleLabel</key>
<string>Less2DoAppDelegate.m</string>
<string>ContextDAOTest.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>A3E3383F10BC4160004F0F39</string>
<key>PBXProjectModuleLabel</key>
<string>Less2DoAppDelegate.m</string>
<string>ContextDAOTest.m</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>A3F5B54310C678110054A7FE</string>
<string>A3F5B61310C683480054A7FE</string>
<key>history</key>
<array>
<string>A3CF9F0F10C414D80096B8CD</string>
<string>A3517ECB10C4403600DEEB5C</string>
<string>A3517ECC10C4403600DEEB5C</string>
<string>A3517ECE10C4403600DEEB5C</string>
<string>A3C723EE10C48F780025747C</string>
<string>A3C723EF10C48F780025747C</string>
<string>A3C723F910C48F8A0025747C</string>
<string>A3C7241A10C491430025747C</string>
<string>A3F5B54210C6780B0054A7FE</string>
<string>A3F5B54B10C67B0A0054A7FE</string>
<string>A3F5B56D10C67EA50054A7FE</string>
<string>A3F5B60010C683040054A7FE</string>
<string>A3F5B61210C683440054A7FE</string>
</array>
</dict>
<key>SplitCount</key>
Expand Down

0 comments on commit 6bf87fa

Please sign in to comment.