From 09e15e1d6661f3f79788a728adcc3f52ef839ded Mon Sep 17 00:00:00 2001 From: gcasa Date: Thu, 29 Jan 2009 21:31:58 +0000 Subject: [PATCH] Update test. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27723 72102866-910b-0410-8b05-ffd578937521 --- Testing/locktest/locktest.m | 190 +++++++++++++++++++++++++++--------- 1 file changed, 146 insertions(+), 44 deletions(-) diff --git a/Testing/locktest/locktest.m b/Testing/locktest/locktest.m index 5183d3e12..34ec8c28e 100644 --- a/Testing/locktest/locktest.m +++ b/Testing/locktest/locktest.m @@ -1,68 +1,170 @@ #import -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() { - // insert code here... - NSLock *lock = [[NSLock alloc] init]; - [lock tryLock]; - [lock tryLock]; - [lock unlock]; - [lock release]; + NS_DURING + { + // insert code here... + NSLock *lock = [[NSLock alloc] init]; + [lock tryLock]; + [lock tryLock]; + [lock unlock]; + [lock release]; + NSLog(@"[NSLock tryLock] test passed"); + } + NS_HANDLER + { + NSLog(@"[NSLock tryLock] test failed"); + } + NS_ENDHANDLER; } + void testNSConditionLockTryLock() { - // insert code here... - NSConditionLock *lock = [[NSConditionLock alloc] init]; - [lock tryLock]; - [lock tryLock]; - [lock unlock]; - [lock release]; + NS_DURING + { + // insert code here... + NSConditionLock *lock = [[NSConditionLock alloc] init]; + [lock tryLock]; + [lock tryLock]; + [lock unlock]; + [lock release]; + NSLog(@"[NSConditionLock tryLock] test passed"); + } + NS_HANDLER + { + NSLog(@"[NSConditionLock tryLock] test failed"); + } + NS_ENDHANDLER; } void testNSRecursiveLockTryLock() { - // insert code here... - NSRecursiveLock *lock = [[NSRecursiveLock alloc] init]; - [lock tryLock]; - [lock tryLock]; - [lock unlock]; - [lock unlock]; - [lock release]; + NS_DURING + { + // insert code here... + NSRecursiveLock *lock = [[NSRecursiveLock alloc] init]; + [lock tryLock]; + [lock tryLock]; + [lock unlock]; + [lock unlock]; + [lock release]; + NSLog(@"[NSRecursiveLock tryLock] test passed"); + } + NS_HANDLER + { + NSLog(@"[NSRecursiveLock tryLock] test failed"); + } + NS_ENDHANDLER; } void singleThreadedTests() { - NS_DURING - { - // single threaded tests... - testNSLockTryLock(); - testNSConditionLockTryLock(); - testNSRecursiveLockTryLock(); - } - NS_HANDLER - { - NSLog(@"Test failed"); - pass = NO; - } - NS_ENDHANDLER + // single threaded tests... + NSLog(@"======== SINGLE THREADED TESTS"); + + // lock + testNSLockLock(); + testNSConditionLockLock(); + testNSRecursiveLockLock(); + + // tryLock + testNSLockTryLock(); + testNSConditionLockTryLock(); + testNSRecursiveLockTryLock(); } + void multiThreadedTests() { + NSLog(@"======== MULTI THREADED TESTS"); } -int main (int argc, const char * argv[]) { - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - - pass = YES; - // single threaded tests... - singleThreadedTests(); - // multi threaded tests... - multiThreadedTests(); - assert(pass == YES); - [pool drain]; - return 0; +int main (int argc, const char * argv[]) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + // pass = YES; + // single threaded tests... + singleThreadedTests(); + // multi threaded tests... + multiThreadedTests(); + [pool drain]; + return 0; }