2011-02-16 08:21:17 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "Testing.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
BOOL ret;
|
|
|
|
NSLock *lock = [NSRecursiveLock new];
|
2015-07-08 12:54:15 +00:00
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
ret = [lock tryLock];
|
|
|
|
if (ret)
|
|
|
|
[lock unlock];
|
|
|
|
PASS(ret, "NSRecursiveLock with tryLock, then unlocking");
|
|
|
|
|
2015-07-08 12:54:15 +00:00
|
|
|
ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
|
2011-02-16 08:21:17 +00:00
|
|
|
if (ret)
|
|
|
|
[lock unlock];
|
|
|
|
PASS(ret, "NSRecursiveLock lockBeforeDate: works");
|
|
|
|
|
2015-07-08 12:54:15 +00:00
|
|
|
ret = [lock tryLock];
|
2011-02-16 08:21:17 +00:00
|
|
|
if (ret)
|
2015-07-08 12:54:15 +00:00
|
|
|
{
|
|
|
|
ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
[lock unlock];
|
|
|
|
}
|
|
|
|
[lock unlock];
|
|
|
|
}
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS(ret, "NSRecursiveLock lockBeforeDate: with NSRecursiveLock returns YES");
|
|
|
|
|
2015-07-08 12:54:15 +00:00
|
|
|
#if defined(GNUSTEP_BASE_LIBRARY)
|
2016-03-05 17:08:26 +00:00
|
|
|
START_SET("mutex ownership extension")
|
|
|
|
#if defined(_WIN32)
|
2016-03-05 17:10:28 +00:00
|
|
|
SKIP("mutex ownership feature not available on windows")
|
2016-03-05 17:08:26 +00:00
|
|
|
#endif
|
2015-07-08 12:54:15 +00:00
|
|
|
NS_DURING
|
|
|
|
{
|
2016-06-06 20:49:08 +00:00
|
|
|
testHopeful = YES;
|
2015-07-08 12:54:15 +00:00
|
|
|
PASS([lock isLockedByCurrentThread] == NO,
|
|
|
|
"NSRecursiveLock isLockedByCurrentThread returns NO when not locked");
|
|
|
|
[lock lock];
|
|
|
|
PASS([lock isLockedByCurrentThread] == YES,
|
2016-03-05 14:42:11 +00:00
|
|
|
"NSRecursiveLock isLockedByCurrentThread returns YES when locked");
|
2015-07-08 12:54:15 +00:00
|
|
|
[lock unlock];
|
|
|
|
PASS([lock isLockedByCurrentThread] == NO,
|
|
|
|
"NSRecursiveLock isLockedByCurrentThread returns NO when unlocked");
|
2016-06-06 20:49:08 +00:00
|
|
|
testHopeful = NO;
|
2015-07-08 12:54:15 +00:00
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
NSLog(@"-isLockedByCurrentThread not supported");
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
2016-03-05 17:08:26 +00:00
|
|
|
END_SET("mutex ownership extension")
|
2015-07-08 12:54:15 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|