mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Extended tests for concurrent NSOperations
- trigger isFinished KVO notification when not being finished - add test for completion handler
This commit is contained in:
parent
e797128a03
commit
1980f9bdf6
1 changed files with 26 additions and 4 deletions
|
@ -39,10 +39,9 @@
|
|||
- (void) main
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
[self willChangeValueForKey:@"isExecuting"];
|
||||
executing = YES;
|
||||
[self didChangeValueForKey:@"isExecuting"];
|
||||
|
||||
[self beginOperation];
|
||||
|
||||
// Do the main work of the operation here.
|
||||
calculation = 2 * calculation;
|
||||
|
||||
|
@ -71,6 +70,20 @@
|
|||
[pool release];
|
||||
}
|
||||
|
||||
- (void) beginOperation
|
||||
{
|
||||
// Also trigger KVO notification for isFinished to ensure its handled
|
||||
// correctly if operation is not yet finished
|
||||
[self willChangeValueForKey: @"isFinished"];
|
||||
[self willChangeValueForKey: @"isExecuting"];
|
||||
|
||||
executing = YES;
|
||||
finished = NO;
|
||||
|
||||
[self didChangeValueForKey: @"isExecuting"];
|
||||
[self didChangeValueForKey: @"isFinished"];
|
||||
}
|
||||
|
||||
- (void) completeOperation
|
||||
{
|
||||
[self willChangeValueForKey: @"isFinished"];
|
||||
|
@ -92,16 +105,25 @@ int main()
|
|||
NSOperationQueue *q;
|
||||
int i;
|
||||
NSMutableArray *a;
|
||||
# if __has_feature(blocks)
|
||||
__block BOOL blockDidRun = NO;
|
||||
#endif
|
||||
|
||||
START_SET("concurrent operations")
|
||||
|
||||
// single concurrent operation
|
||||
obj = [[MyOperation alloc] initWithValue: 1];
|
||||
# if __has_feature(blocks)
|
||||
[obj setCompletionBlock: ^(void){blockDidRun = YES;}];
|
||||
# endif
|
||||
q = [NSOperationQueue new];
|
||||
[q addOperation: obj];
|
||||
[q waitUntilAllOperationsAreFinished];
|
||||
PASS(([obj isFinished] == YES), "operation ran");
|
||||
PASS(([obj isExecuting] == NO), "operation is not executing");
|
||||
# if __has_feature(blocks)
|
||||
PASS(blockDidRun == YES, "completion block is executed");
|
||||
# endif
|
||||
PASS(([obj getCalculation] == 2), "operation was performed");
|
||||
[obj release];
|
||||
|
||||
|
|
Loading…
Reference in a new issue