mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-01 04:21:07 +00:00
77 lines
2.4 KiB
Mathematica
77 lines
2.4 KiB
Mathematica
|
#import <Foundation/Foundation.h>
|
||
|
#import "Testing.h"
|
||
|
#import "ObjectTesting.h"
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||
|
NSFileManager *mgr;
|
||
|
NSString *helpers;
|
||
|
NSString *command;
|
||
|
NSTask *task;
|
||
|
NSPipe *ePipe;
|
||
|
NSFileHandle *hdl;
|
||
|
NSData *data;
|
||
|
NSString *string;
|
||
|
NSLock *lock = nil;
|
||
|
|
||
|
mgr = [NSFileManager defaultManager];
|
||
|
helpers = [mgr currentDirectoryPath];
|
||
|
helpers = [helpers stringByAppendingPathComponent: @"Helpers"];
|
||
|
helpers = [helpers stringByAppendingPathComponent: @"obj"];
|
||
|
|
||
|
command = [helpers stringByAppendingPathComponent: @"doubleNSLock"];
|
||
|
task = [[NSTask alloc] init];
|
||
|
ePipe = [[NSPipe pipe] retain];
|
||
|
[task setLaunchPath: command];
|
||
|
[task setStandardError: ePipe];
|
||
|
hdl = [ePipe fileHandleForReading];
|
||
|
[task launch];
|
||
|
[task waitUntilExit];
|
||
|
data = [hdl availableData];
|
||
|
NSLog(@"Data was %*.*s", [data length], [data length], [data bytes]);
|
||
|
string = [NSString alloc];
|
||
|
string = [string initWithData: data encoding: NSISOLatin1StringEncoding];
|
||
|
PASS([string rangeOfString: @"deadlock"].length > 0,
|
||
|
"NSLock deadlocked as expected");
|
||
|
|
||
|
command = [helpers stringByAppendingPathComponent: @"doubleNSConditionLock"];
|
||
|
task = [[NSTask alloc] init];
|
||
|
ePipe = [[NSPipe pipe] retain];
|
||
|
[task setLaunchPath: command];
|
||
|
[task setStandardError: ePipe];
|
||
|
hdl = [ePipe fileHandleForReading];
|
||
|
[task launch];
|
||
|
[task waitUntilExit];
|
||
|
data = [hdl availableData];
|
||
|
NSLog(@"Data was %*.*s", [data length], [data length], [data bytes]);
|
||
|
string = [NSString alloc];
|
||
|
string = [string initWithData: data encoding: NSISOLatin1StringEncoding];
|
||
|
PASS([string rangeOfString: @"deadlock"].length > 0,
|
||
|
"NSConditionLock deadlocked as expected");
|
||
|
|
||
|
ASSIGN(lock,[NSRecursiveLock new]);
|
||
|
[lock lock];
|
||
|
[lock lock];
|
||
|
[lock unlock];
|
||
|
[lock unlock];
|
||
|
|
||
|
ASSIGN(lock,[NSLock new]);
|
||
|
PASS([lock tryLock] == YES, "NSLock can tryLock");
|
||
|
PASS([lock tryLock] == NO, "NSLock says NO for recursive tryLock");
|
||
|
[lock unlock];
|
||
|
|
||
|
ASSIGN(lock,[NSConditionLock new]);
|
||
|
PASS([lock tryLock] == YES, "NSConditionLock can tryLock");
|
||
|
PASS([lock tryLock] == NO, "NSConditionLock says NO for recursive tryLock");
|
||
|
[lock unlock];
|
||
|
|
||
|
ASSIGN(lock,[NSRecursiveLock new]);
|
||
|
PASS([lock tryLock] == YES, "NSRecursiveLock can tryLock");
|
||
|
PASS([lock tryLock] == YES, "NSRecursiveLock says YES for recursive tryLock");
|
||
|
[lock unlock];
|
||
|
|
||
|
[arp release];
|
||
|
return 0;
|
||
|
}
|