mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-30 20:07:36 +00:00
Merge pull request #2287 from cacaodev/CPOperationQueue-cancelOperation
FIXED : a CPOperation marked as cancelled was never started
This commit is contained in:
commit
b1382e8e89
4 files changed
+73
-5
No files matched your search
@@ -117,10 +117,11 @@ CPOperationQueuePriorityVeryHigh = 8;
|
||||
[self willChangeValueForKey:@"isExecuting"];
|
||||
_executing = NO;
|
||||
[self didChangeValueForKey:@"isExecuting"];
|
||||
[self willChangeValueForKey:@"isFinished"];
|
||||
_finished = YES;
|
||||
[self didChangeValueForKey:@"isFinished"];
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"isFinished"];
|
||||
_finished = YES;
|
||||
[self didChangeValueForKey:@"isFinished"];
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -70,7 +70,7 @@ var cpOperationMainQueue = nil;
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var op = [_operations objectAtIndex:i];
|
||||
if ([op isReady] && ![op isCancelled] && ![op isFinished] && ![op isExecuting])
|
||||
if ([op isReady] && ![op isFinished] && ![op isExecuting])
|
||||
{
|
||||
[op start];
|
||||
}
|
||||
@@ -260,7 +260,7 @@ var cpOperationMainQueue = nil;
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var op = [ops objectAtIndex:i];
|
||||
if ([op isReady] && ![op isCancelled] && ![op isFinished] && ![op isExecuting])
|
||||
if ([op isReady] && ![op isFinished] && ![op isExecuting])
|
||||
{
|
||||
[op start];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,33 @@ globalResults = [];
|
||||
|
||||
@end
|
||||
|
||||
@implementation TestCancelOperation : CPOperation
|
||||
{
|
||||
BOOL _started @accessors(getter=didStart);
|
||||
BOOL _mained @accessors(getter=didMain);
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
_started = NO;
|
||||
_mained = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
_mained = YES;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[super start];
|
||||
_started = YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TestObserver : CPObject
|
||||
{
|
||||
CPArray changedKeyPaths @accessors;
|
||||
@@ -167,4 +194,27 @@ globalResults = [];
|
||||
[self assert:@"name" equals:[[obs changedKeyPaths] objectAtIndex:4]];
|
||||
}
|
||||
|
||||
- (void)testCancelledOperationDoesStart
|
||||
{
|
||||
var op = [[TestCancelOperation alloc] init],
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
|
||||
[self assertFalse:[op isCancelled]];
|
||||
[self assertFalse:[op isFinished]];
|
||||
[self assertFalse:[op didMain]];
|
||||
[self assertFalse:[op didStart]];
|
||||
|
||||
[op cancel];
|
||||
|
||||
[self assertTrue:[op isCancelled]];
|
||||
[self assertFalse:[op isFinished]];
|
||||
|
||||
[queue addOperations:[op] waitUntilFinished:YES];
|
||||
|
||||
[self assertFalse:[op didMain]];
|
||||
[self assertTrue:[op didStart]];
|
||||
[self assertTrue:[op isCancelled]];
|
||||
[self assertTrue:[op isFinished]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -180,4 +180,21 @@
|
||||
[self assert:@"isCancelled" equals:[[obs changedKeyPaths] objectAtIndex:9]];
|
||||
}
|
||||
|
||||
- (void)testCancelledOperationIsFinished
|
||||
{
|
||||
var results = @[],
|
||||
funcOp = [CPFunctionOperation functionOperationWithFunction:function() {[results addObject:"funcOp"];}];
|
||||
|
||||
[funcOp cancel];
|
||||
[self assertTrue:[funcOp isCancelled]];
|
||||
[self assertFalse:[funcOp isFinished]];
|
||||
|
||||
[funcOp start];
|
||||
|
||||
[self assertTrue:[funcOp isCancelled]];
|
||||
[self assertTrue:[funcOp isFinished]];
|
||||
|
||||
[self assertTrue:([results count] == 0)];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user