Skip to content

Commit

Permalink
Merge branch 'master' of github.com:myellow/Less-2-Do
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed Jan 19, 2010
2 parents 827c336 + d52a283 commit 6791597
Show file tree
Hide file tree
Showing 8 changed files with 595 additions and 249 deletions.
5 changes: 5 additions & 0 deletions Classes/BaseManagedObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ + (BaseManagedObject *)objectOfType:(NSString *)type

+ (BOOL)deleteObject:(BaseManagedObject *)theObject error:(NSError **)error
{
/* show if parameter is set */
if(theObject == nil) {
*error = [NSError errorWithDomain:DAOErrorDomain code:DAOMissingParametersError userInfo:nil];
return NO;
}
theObject.deleted = [NSNumber numberWithInteger:1];
ALog(@"deleted the object: %d", [theObject.deleted integerValue]);
return YES;
Expand Down
15 changes: 14 additions & 1 deletion Classes/Entities/Task.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,20 @@ + (NSArray *)getAllTasksInStore:(NSError **)error

+ (NSArray *) getAllTasks:(NSError **)error {
NSArray* objects = [Task getTasksWithFilterPredicate:[NSPredicate predicateWithFormat:@"isCompleted == NO and deleted == NO"] error:error];
return objects;
NSMutableArray *notDeleted = [NSMutableArray array];

for(Task *t in objects)
{
if([t.deleted boolValue] == NO)
{
[notDeleted addObject:t];
}
}

return [NSArray arrayWithArray:notDeleted];

//return objects;

}

+ (NSArray *) getStarredTasks:(NSError **)error {
Expand Down
142 changes: 120 additions & 22 deletions ContextTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ - (void)testAllContextsEmpty {
}

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

Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.name = @"c1";
newContext2.name = @"c2";
newContext3.name = @"c3";

NSArray *contexts = [Context getAllContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)3, @"Add context not successful");
Expand Down Expand Up @@ -83,40 +86,135 @@ - (void)testDeleteContext {
GHAssertEquals([contexts count], (NSUInteger)0, @"Delete context not successful");
}

/* first adds a context and then updates it */
- (void)testUpdateContext {
Context *newContext = (Context*)[Context objectOfType:@"Context"];
- (void)testAllContextsOrdered {
NSError *error = nil;

newContext.name = @"UPDATE";
Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.name = @"C";
newContext2.name = @"A";
newContext3.name = @"B";

NSArray *contexts = [Context getAllContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)3, @"Add contextnot successful");
NSString *output = [NSString stringWithFormat:@"0: %@, 1: %@, 2: %@", [contexts objectAtIndex:0], [contexts objectAtIndex:1], [contexts objectAtIndex:2]];
GHAssertEqualStrings(output, @"0: A, 1: B, 2: C", @"Ordered Contexts not successful");
}

-(void) testGetRemoteStoredContexts
{
NSError *error = nil;

GHAssertTrue([newContext isUpdated], @"Update context not successful");
Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.remoteId = [NSNumber numberWithInt:-1];
newContext2.remoteId = [NSNumber numberWithInt:20000];
newContext3.remoteId = [NSNumber numberWithInt:23000];

/*//[NSThread sleepForTimeInterval:2];
NSArray *contexts = [Context getRemoteStoredContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)2, @"");
}

-(void) testGetRemoteStoredContextsLocallyDeleted
{
NSError *error = nil;

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"); */
Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.remoteId = [NSNumber numberWithInt:-1];
newContext2.remoteId = [NSNumber numberWithInt:20000];
newContext3.remoteId = [NSNumber numberWithInt:23000];
[Context deleteObject:newContext3 error:&error];

NSArray *contexts = [Context getRemoteStoredContextsLocallyDeleted:&error];
GHAssertEquals([contexts count], (NSUInteger)1, @"");
}

- (void)testAllContextsOrdered {
-(void) testGetLocalStoredContextsLocallyDeleted
{
NSError *error = nil;

Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.name = @"Eontext";
newContext2.name = @"Dontext";
newContext3.name = @"Context";
NSArray *contexts = [Context getAllContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)3, @"Add contextnot successful");
NSString *output = [NSString stringWithFormat:@"0: %@, 1: %@, 2: %@", [contexts objectAtIndex:0], [contexts objectAtIndex:1], [contexts objectAtIndex:2]];
GHAssertEqualStrings(output, @"0: Context, 1: Dontext, 2: Eontext", @"Ordered Contexts not successful");
newContext1.remoteId = [NSNumber numberWithInt:-1];
newContext2.remoteId = [NSNumber numberWithInt:-1];
newContext3.remoteId = [NSNumber numberWithInt:23000];
[Context deleteObject:newContext2 error:&error];
[Context commit];

NSArray *contexts = [Context getLocalStoredContextsLocallyDeleted:&error];
GHAssertEquals([contexts count], (NSUInteger)1, @"");
}

-(void) testGetAllContextsLocallyDeleted
{
NSError *error = nil;

Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.remoteId = [NSNumber numberWithInt:-1];
newContext2.remoteId = [NSNumber numberWithInt:20000];
newContext3.remoteId = [NSNumber numberWithInt:23000];
[Context deleteObject:newContext2 error:&error];
[Context deleteObject:newContext1 error:&error];

NSArray *contexts = [Context getAllContextsLocallyDeleted:&error];
GHAssertEquals([contexts count], (NSUInteger)2, @"");
}

-(void) testGetUnsyncedContexts
{
NSError *error = nil;

Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.remoteId = [NSNumber numberWithInt:-1];
newContext2.remoteId = [NSNumber numberWithInt:20000];
newContext3.remoteId = [NSNumber numberWithInt:23000];

NSArray *contexts = [Context getUnsyncedContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)1, @"");
}

-(void) testGetModifiedContexts
{
NSError *error = nil;

Context *newContext1 = (Context*)[Context objectOfType:@"Context"];
Context *newContext2 = (Context*)[Context objectOfType:@"Context"];
Context *newContext3 = (Context*)[Context objectOfType:@"Context"];
newContext1.lastLocalModification = [NSDate dateWithTimeIntervalSince1970:0];
newContext1.lastSyncDate = [NSDate dateWithTimeIntervalSince1970:5];
newContext2.lastLocalModification = [NSDate dateWithTimeIntervalSince1970:15];
newContext2.lastSyncDate = [NSDate dateWithTimeIntervalSince1970:5];
newContext3.lastLocalModification = [NSDate dateWithTimeIntervalSince1970:20];
newContext3.lastSyncDate = [NSDate dateWithTimeIntervalSince1970:5];


NSArray *contexts = [Context getModifiedContexts:&error];
GHAssertEquals([contexts count], (NSUInteger)2, @"");
}

-(void) testGetContextWithRemoteId
{
NSError *error = nil;

Context *newContext = (Context*)[Context objectOfType:@"Context"];
newContext.remoteId = [NSNumber numberWithInt:20000];

Context *theResult = [Context getContextWithRemoteId:[NSNumber numberWithInt:20000] error:&error];
GHAssertNotNil(theResult, @"");
}


/* adds 3 contexts - count must be 3 */
- (void)testOldestModificationDate {
/*- (void)testOldestModificationDate {
NSError *error = nil;
NSDateFormatter *format = [[NSDateFormatter alloc] init];
Expand All @@ -137,6 +235,6 @@ - (void)testOldestModificationDate {
if (![oldestDate isEqualToDate:newContext1.lastLocalModification]) {
GHFail(@"Oldest Mod Date not successful");
}
}
}*/

@end
Loading

0 comments on commit 6791597

Please sign in to comment.