File: tryLock.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 (78 lines) | stat: -rw-r--r-- 2,236 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
74
75
76
77
78
#import <Foundation/Foundation.h>
#import "Testing.h"

int main()
{
  NSAutoreleasePool   	*arp = [NSAutoreleasePool new];
  BOOL 			ret;
  id			lock = nil;
  
  lock = AUTORELEASE([NSLock new]);
  ret = [lock tryLock];
  if (ret)
    [lock unlock];
  PASS(ret, "NSLock with tryLock, then unlocking");
 
  lock =  AUTORELEASE([NSLock new]);
  [lock tryLock];
  ret = [lock tryLock];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive try lock with NSLock should return NO"); 
  
  lock =  AUTORELEASE([NSConditionLock new]);
  [lock lock];
  ret = [lock tryLock];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive try lock with NSConditionLock should return NO"); 
  
  ret = [lock tryLockWhenCondition: 42];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive tryLockWhenCondition: with NSConditionLock (1) should return NO"); 
  [lock unlockWithCondition: 42];
  [lock lock];
  ret = [lock tryLockWhenCondition: 42];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive tryLockWhenCondition: with NSConditionLock (2) should return NO"); 
  
  lock = AUTORELEASE([NSRecursiveLock new]);
  [lock tryLock];
  ret = [lock tryLock];
  if (ret)
    [lock unlock];
  PASS(ret == YES, "Recursive try lock with NSRecursiveLock should return YES"); 
  
  lock = AUTORELEASE([NSLock new]);
  ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
  if (ret)
    [lock unlock];
  PASS(ret, "NSLock lockBeforeDate: works");
  
  lock = AUTORELEASE([NSLock new]);
  [lock tryLock];
  ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive lockBeforeDate: with NSLock returns NO");
  
  lock = AUTORELEASE([NSConditionLock new]);
  [lock tryLock];
  ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
  if (ret)
    [lock unlock];
  PASS(ret == NO, "Recursive lockBeforeDate: with NSConditionLock returns NO");
  
  lock = AUTORELEASE([NSRecursiveLock new]);
  [lock tryLock];
  ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
  if (ret)
    [lock unlock];
  PASS(ret == YES, "Recursive lockBeforeDate: with NSRecursiveLock returns YES");
  
  [arp release]; arp = nil;
  return 0;
}