libs-base/Tests/base/NSLock/RecursiveLock.m
rfm 8f2ccfe42e Thread diagnositc changes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38768 72102866-910b-0410-8b05-ffd578937521
2015-07-08 12:54:15 +00:00

54 lines
1.3 KiB
Objective-C

#import <Foundation/Foundation.h>
#import "Testing.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
BOOL ret;
NSLock *lock = [NSRecursiveLock new];
ret = [lock tryLock];
if (ret)
[lock unlock];
PASS(ret, "NSRecursiveLock with tryLock, then unlocking");
ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
if (ret)
[lock unlock];
PASS(ret, "NSRecursiveLock lockBeforeDate: works");
ret = [lock tryLock];
if (ret)
{
ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
if (ret)
{
[lock unlock];
}
[lock unlock];
}
PASS(ret, "NSRecursiveLock lockBeforeDate: with NSRecursiveLock returns YES");
#if defined(GNUSTEP_BASE_LIBRARY)
NS_DURING
{
PASS([lock isLockedByCurrentThread] == NO,
"NSRecursiveLock isLockedByCurrentThread returns NO when not locked");
[lock lock];
PASS([lock isLockedByCurrentThread] == YES,
"NSRecursiveLock isLockedByCurrentThread returns YES when not locked");
[lock unlock];
PASS([lock isLockedByCurrentThread] == NO,
"NSRecursiveLock isLockedByCurrentThread returns NO when unlocked");
}
NS_HANDLER
{
NSLog(@"-isLockedByCurrentThread not supported");
}
NS_ENDHANDLER
#endif
[arp release]; arp = nil;
return 0;
}