Skip to content

Commit 69d4fe4

Browse files
committed
NSProgress: Add cancellation unit test
1 parent 078b8d7 commit 69d4fe4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Tests/base/NSProgress/cancellation.m

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Test propragation of progress cancellation to children */
2+
3+
#include "Foundation/NSException.h"
4+
#include "GNUstepBase/GNUstep.h"
5+
#import <Foundation/NSProgress.h>
6+
#import <Foundation/NSAutoreleasePool.h>
7+
#import "ObjectTesting.h"
8+
9+
void checkPropagationExplicitChildren(void) {
10+
/*
11+
* ┌──────────┐
12+
* │ PARENT │
13+
* └──────────┘
14+
* │
15+
* ┌──────┴──────┐
16+
* ▼ ▼
17+
* ┌──────────┐ ┌──────────┐
18+
* │ CHILD0 │ │ CHILD1 │
19+
* └──────────┘ └──────────┘
20+
* │
21+
* └────┐
22+
* ▼
23+
* ┌──────────┐
24+
* │ CHILD2 │
25+
* └──────────┘
26+
*/
27+
NSProgress *parent = [NSProgress progressWithTotalUnitCount: 100];
28+
NSProgress *child0 = [NSProgress progressWithTotalUnitCount: 10];
29+
NSProgress *child1 = [NSProgress progressWithTotalUnitCount: 10];
30+
NSProgress *child2 = [NSProgress progressWithTotalUnitCount: 5];
31+
32+
/* child0 and child1 constitude 100% of the unit count of the parent */
33+
[parent addChild: child0 withPendingUnitCount: 50];
34+
[parent addChild: child1 withPendingUnitCount: 50];
35+
[child1 addChild: child2 withPendingUnitCount: 5];
36+
37+
[child2 setCompletedUnitCount: 2];
38+
[child1 setCompletedUnitCount: 5];
39+
[child0 setCompletedUnitCount: 10];
40+
41+
PASS([child0 isFinished], "child0 is finished");
42+
43+
/* Only unfinished progresses are cancelled */
44+
[parent cancel];
45+
PASS([parent isCancelled], "parent is cancelled");
46+
PASS([child0 isCancelled] == NO, "child0 is not cancelled");
47+
PASS([child1 isCancelled], "child1 is cancelled");
48+
PASS([child2 isCancelled], "child2 is cancelled");
49+
}
50+
51+
int main(void)
52+
{
53+
ENTER_POOL
54+
55+
checkPropagationExplicitChildren();
56+
57+
LEAVE_POOL
58+
return 0;
59+
}

0 commit comments

Comments
 (0)