Update test.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27723 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2009-01-29 21:31:58 +00:00
parent 14bd757dba
commit 09e15e1d66

View file

@ -1,68 +1,170 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
BOOL pass; // BOOL pass;
void testNSLockLock()
{
NS_DURING
{
// insert code here...
NSLock *lock = [[NSLock alloc] init];
[lock lock];
#ifdef GNUSTEP
[lock lock]; // On Mac OS X, this deadlocks. Should we do the same?
// our behavior in this case is arguably better since we raise an exception
#endif
[lock unlock];
[lock release];
#ifndef GNUSTEP
NSLog(@"[NSLock lock] test passed -- Mac OS X behavior is to deadlock in this case, we throw an exception.");
#else
NSLog(@"[NSLock lock] test failed");
#endif
}
NS_HANDLER
{
NSLog(@"[NSLock lock] test passed");
}
NS_ENDHANDLER;
}
void testNSConditionLockLock()
{
NS_DURING
{
// insert code here...
NSConditionLock *lock = [[NSConditionLock alloc] init];
[lock lock];
#ifdef GNUSTEP
[lock lock]; // On Mac OS X, this deadlocks. Should we do the same?
// our behavior in this case is arguably better since we raise an exception
#endif
[lock unlock];
[lock release];
#ifndef GNUSTEP
NSLog(@"[NSConditionLock lock] test passed -- Mac OS X behavior is to deadlock in this case, we throw an exception.");
#else
NSLog(@"[NSConditionLock lock] test failed");
#endif
}
NS_HANDLER
{
NSLog(@"[NSConditionLock lock] test failed");
}
NS_ENDHANDLER;
}
void testNSRecursiveLockLock()
{
NS_DURING
{
// insert code here...
NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
[lock lock];
[lock lock];
[lock unlock];
[lock unlock];
[lock release];
NSLog(@"[NSRecursiveLock lock] test passed");
}
NS_HANDLER
{
NSLog(@"[NSRecursiveLock lock] test failed");
}
NS_ENDHANDLER;
}
void testNSLockTryLock() void testNSLockTryLock()
{ {
// insert code here... NS_DURING
NSLock *lock = [[NSLock alloc] init]; {
[lock tryLock]; // insert code here...
[lock tryLock]; NSLock *lock = [[NSLock alloc] init];
[lock unlock]; [lock tryLock];
[lock release]; [lock tryLock];
[lock unlock];
[lock release];
NSLog(@"[NSLock tryLock] test passed");
}
NS_HANDLER
{
NSLog(@"[NSLock tryLock] test failed");
}
NS_ENDHANDLER;
} }
void testNSConditionLockTryLock() void testNSConditionLockTryLock()
{ {
// insert code here... NS_DURING
NSConditionLock *lock = [[NSConditionLock alloc] init]; {
[lock tryLock]; // insert code here...
[lock tryLock]; NSConditionLock *lock = [[NSConditionLock alloc] init];
[lock unlock]; [lock tryLock];
[lock release]; [lock tryLock];
[lock unlock];
[lock release];
NSLog(@"[NSConditionLock tryLock] test passed");
}
NS_HANDLER
{
NSLog(@"[NSConditionLock tryLock] test failed");
}
NS_ENDHANDLER;
} }
void testNSRecursiveLockTryLock() void testNSRecursiveLockTryLock()
{ {
// insert code here... NS_DURING
NSRecursiveLock *lock = [[NSRecursiveLock alloc] init]; {
[lock tryLock]; // insert code here...
[lock tryLock]; NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
[lock unlock]; [lock tryLock];
[lock unlock]; [lock tryLock];
[lock release]; [lock unlock];
[lock unlock];
[lock release];
NSLog(@"[NSRecursiveLock tryLock] test passed");
}
NS_HANDLER
{
NSLog(@"[NSRecursiveLock tryLock] test failed");
}
NS_ENDHANDLER;
} }
void singleThreadedTests() void singleThreadedTests()
{ {
NS_DURING // single threaded tests...
{ NSLog(@"======== SINGLE THREADED TESTS");
// single threaded tests...
testNSLockTryLock(); // lock
testNSConditionLockTryLock(); testNSLockLock();
testNSRecursiveLockTryLock(); testNSConditionLockLock();
} testNSRecursiveLockLock();
NS_HANDLER
{ // tryLock
NSLog(@"Test failed"); testNSLockTryLock();
pass = NO; testNSConditionLockTryLock();
} testNSRecursiveLockTryLock();
NS_ENDHANDLER
} }
void multiThreadedTests() void multiThreadedTests()
{ {
NSLog(@"======== MULTI THREADED TESTS");
} }
int main (int argc, const char * argv[]) { int main (int argc, const char * argv[])
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
pass = YES;
// single threaded tests... // pass = YES;
singleThreadedTests(); // single threaded tests...
// multi threaded tests... singleThreadedTests();
multiThreadedTests(); // multi threaded tests...
assert(pass == YES); multiThreadedTests();
[pool drain]; [pool drain];
return 0; return 0;
} }