File: basic.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (73 lines) | stat: -rw-r--r-- 2,490 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#import <Foundation/NSInvocationOperation.h>
#import <Foundation/NSInvocation.h>
#import <Foundation/NSOperation.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"


int main()
{
  START_SET("NSInvocationOperation - basic")
  NSInvocationOperation *op;
  NSInvocation          *inv1;
  NSInvocation          *inv2;
  NSValue               *val;
  NSInteger             length;
  NSString              *hello = @"hello";
  NSString              *uppercaseHello;
  NSOperationQueue      *queue = AUTORELEASE([NSOperationQueue new]);

  op = [[NSInvocationOperation alloc] initWithTarget: hello
					    selector: @selector(length)
					      object: nil];
  [queue addOperations: [NSArray arrayWithObject: op]
     waitUntilFinished: YES];
  val = [op result];
  [val getValue: &length];
  PASS((length == 5), "Can invoke a selector on a target");
  RELEASE(op);

  inv1 = [NSInvocation invocationWithMethodSignature: 
    [hello methodSignatureForSelector: @selector(uppercaseString)]];
  [inv1 setTarget: hello];
  [inv1 setSelector: @selector(uppercaseString)];
  op = [[NSInvocationOperation alloc] initWithInvocation: inv1];
  inv2 = [op invocation];
  PASS(([inv2 isEqual: inv1]), "Can recover an operation's invocation");
  [queue addOperations: [NSArray arrayWithObject: op]
     waitUntilFinished: YES];
  uppercaseHello = [op result];
  PASS_EQUAL(uppercaseHello, @"HELLO", "Can schedule an NSInvocation");
  RELEASE(op);

  op = [[NSInvocationOperation alloc] initWithTarget: hello
					    selector: @selector(release)
					      object: nil];
  [queue addOperations: [NSArray arrayWithObject: op]
     waitUntilFinished: YES];
  PASS_EXCEPTION(([op result]), NSInvocationOperationVoidResultException, 
    "Can't get result of a void invocation");
  RELEASE(op);

  op = [[NSInvocationOperation alloc] initWithTarget: hello
					    selector: @selector(length)
					      object: nil];
  [op cancel];
  [queue addOperations: [NSArray arrayWithObject: op]
     waitUntilFinished: YES];
  PASS_EXCEPTION(([op result]), NSInvocationOperationCancelledException,
    "Can't get the result of a cancelled invocation");
  RELEASE(op);

  op = [[NSInvocationOperation alloc] initWithTarget: hello
					    selector: @selector(length)
					      object: nil];
  PASS(([op result] == nil),
    "Result is nil before the invocation has completed");
  RELEASE(op);

  RELEASE(queue);
  END_SET("NSInvocationOperation - basic")
  return 0;
}