~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty-proposed

« back to all changes in this revision

Viewing changes to Tests/base/NSOperation/basic.m

  • Committer: Package Import Robot
  • Author(s): Yavor Doganov
  • Date: 2011-09-15 12:31:15 UTC
  • mfrom: (1.2.11 upstream) (8.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20110915123115-rmvsia9z0211izvq
Tags: 1.22.1-1
* New upstream release:
  + Fixes implicit declaration of function (Closes: #629216).
* debian/rules (v_make): Set to 2.6.1.
  (install-common): Do not delete non-existent .swp file.
* debian/control.m4 (Build-Depends): Remove gobjc; gnustep-make now
  depends on it.
  (libgnustep-base-dev) <Depends>: Likewise.
  (Suggests): Remove; completely pointless.
* debian/control: Regenerate.
* debian/patches/avoid-nsl-linkage.patch: Refresh.
* debian/patches/autoreconf.patch: Regenerate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#import <Foundation/NSOperation.h>
 
2
#import <Foundation/NSThread.h>
 
3
#import <Foundation/NSAutoreleasePool.h>
 
4
#import "ObjectTesting.h"
 
5
 
 
6
 
 
7
int main()
 
8
{
 
9
  id                    obj1;
 
10
  id                    obj2;
 
11
  NSMutableArray        *testObjs = [[NSMutableArray alloc] init];
 
12
  NSAutoreleasePool     *arp = [NSAutoreleasePool new];
 
13
 
 
14
  test_alloc(@"NSOperation"); 
 
15
  obj1 = [NSOperation new];
 
16
  PASS((obj1 != nil), "can create an operation");
 
17
  [testObjs addObject: obj1];
 
18
  test_NSObject(@"NSOperation", testObjs);
 
19
  
 
20
  PASS(([obj1 isReady] == YES), "operation is ready");
 
21
  PASS(([obj1 isConcurrent] == NO), "operation is not concurrent");
 
22
  PASS(([obj1 isCancelled] == NO), "operation is not cancelled");
 
23
  PASS(([obj1 isExecuting] == NO), "operation is not executing");
 
24
  PASS(([obj1 isFinished] == NO), "operation is not finished");
 
25
  PASS(([[obj1 dependencies] isEqual: [NSArray array]]),
 
26
    "operation has no dependencies");
 
27
  PASS(([obj1 queuePriority] == NSOperationQueuePriorityNormal),
 
28
    "operation has normal priority");
 
29
  [obj1 setQueuePriority: 10000];
 
30
  PASS(([obj1 queuePriority] == NSOperationQueuePriorityVeryHigh),
 
31
    "operation has very high priority");
 
32
 
 
33
  obj2 = [NSOperation new];
 
34
  [obj2 addDependency: obj1];
 
35
  PASS(([[obj2 dependencies] isEqual: testObjs]),
 
36
    "operation has added dependency");
 
37
  PASS(([obj2 isReady] == NO), "operation with dependency is not ready");
 
38
  [obj1 cancel];
 
39
  PASS(([[obj2 dependencies] isEqual: testObjs]),
 
40
    "cancelled dependency continues");
 
41
  PASS(([obj1 isCancelled] == YES), "operation is cancelled");
 
42
  PASS(([[obj2 dependencies] isEqual: testObjs]),
 
43
    "cancelled dependency continues");
 
44
  PASS(([obj2 isReady] == NO), "operation with cancelled dependency not ready");
 
45
  [obj2 removeDependency: obj1];
 
46
  PASS(([[obj2 dependencies] isEqual: [NSArray array]]),
 
47
    "dependency removal works");
 
48
  PASS(([obj2 isReady] == YES), "operation without dependency is ready");
 
49
 
 
50
  [obj1 release];
 
51
  obj1 = [NSOperation new];
 
52
  [testObjs replaceObjectAtIndex: 0 withObject: obj1];
 
53
  [obj2 addDependency: obj1];
 
54
  [obj1 start];
 
55
 
 
56
  [NSThread sleepForTimeInterval: 1.0];
 
57
  PASS(([obj1 isFinished] == YES), "operation is finished");
 
58
  PASS(([obj1 isReady] == YES), "a finished operation is ready");
 
59
  PASS(([[obj2 dependencies] isEqual: testObjs]),
 
60
    "finished dependency continues");
 
61
  PASS(([obj2 isReady] == YES), "operation with finished dependency is ready");
 
62
 
 
63
  [obj2 removeDependency: obj1];
 
64
  [obj1 release];
 
65
  obj1 = [NSOperation new];
 
66
  [testObjs replaceObjectAtIndex: 0 withObject: obj1];
 
67
  [obj2 addDependency: obj1];
 
68
  [obj2 cancel];
 
69
  PASS(([obj2 isReady] == YES),
 
70
    "a cancelled object is ready even with a dependency");
 
71
 
 
72
  [obj2 start];
 
73
  PASS(([obj2 isFinished] == YES),
 
74
    "a cancelled object can finish");
 
75
 
 
76
  PASS_EXCEPTION([obj2 start];,
 
77
                 NSInvalidArgumentException,
 
78
                 "NSOperation cannot be started twice");
 
79
 
 
80
  PASS(([obj2 waitUntilFinished], YES), "wait returns at once");
 
81
 
 
82
 
 
83
  test_alloc(@"NSOperationQueue"); 
 
84
  obj1 = [NSOperationQueue new];
 
85
  PASS((obj1 != nil), "can create an operation queue");
 
86
  [testObjs removeAllObjects];
 
87
  [testObjs addObject: obj1];
 
88
  test_NSObject(@"NSOperationQueue", testObjs);
 
89
  
 
90
  PASS(([obj1 isSuspended] == NO), "not suspended by default");
 
91
  [obj1 setSuspended: YES];
 
92
  PASS(([obj1 isSuspended] == YES), "set suspended yes");
 
93
  [obj1 setSuspended: NO];
 
94
  PASS(([obj1 isSuspended] == NO), "set suspended no");
 
95
 
 
96
  PASS(([[obj1 name] length] > 0), "name has a default");
 
97
  [obj1 setName: @"mine"];
 
98
  PASS(([[obj1 name] isEqual: @"mine"] == YES), "set name OK");
 
99
  [obj1 setName: nil];
 
100
  PASS(([[obj1 name] isEqual: @""]), "setting null name gives empty string");
 
101
 
 
102
  PASS(([obj1 maxConcurrentOperationCount] == NSOperationQueueDefaultMaxConcurrentOperationCount), "max concurrent set by default");
 
103
  [obj1 setMaxConcurrentOperationCount: 1];
 
104
  PASS(([obj1 maxConcurrentOperationCount] == 1), "max concurrent set to one");
 
105
  [obj1 setMaxConcurrentOperationCount: 0];
 
106
  PASS(([obj1 maxConcurrentOperationCount] == 0), "max concurrent set to zero");
 
107
  [obj1 setMaxConcurrentOperationCount: 1000000];
 
108
  PASS(([obj1 maxConcurrentOperationCount] == 1000000), "max concurrent set to a million");
 
109
  [obj1 setMaxConcurrentOperationCount: NSOperationQueueDefaultMaxConcurrentOperationCount];
 
110
  PASS(([obj1 maxConcurrentOperationCount] == NSOperationQueueDefaultMaxConcurrentOperationCount), "max concurrent set to default");
 
111
  PASS_EXCEPTION([obj1 setMaxConcurrentOperationCount: -1000000];,
 
112
                 NSInvalidArgumentException,
 
113
                 "NSOperationQueue cannot be given negative count");
 
114
 
 
115
  obj2 = [NSOperation new];
 
116
  [obj1 addOperation: obj2];
 
117
  [NSThread sleepForTimeInterval: 1.0];
 
118
  PASS(([obj2 isFinished] == YES), "queue ran operation");
 
119
 
 
120
  [arp release]; arp = nil;
 
121
  return 0;
 
122
}