]> git.saurik.com Git - apple/objc4.git/blob - test/nopool.m
objc4-756.2.tar.gz
[apple/objc4.git] / test / nopool.m
1 // TEST_CONFIG MEM=mrc
2
3 #include "test.h"
4 #include "testroot.i"
5
6 @implementation TestRoot (Loader)
7 +(void)load
8 {
9 [[TestRoot new] autorelease];
10 testassert(TestRootAutorelease == 1);
11 testassert(TestRootDealloc == 0);
12 }
13 @end
14
15 int main()
16 {
17 // +load's autoreleased object should have deallocated
18 testassert(TestRootDealloc == 1);
19
20 [[TestRoot new] autorelease];
21 testassert(TestRootAutorelease == 2);
22
23
24 objc_autoreleasePoolPop(objc_autoreleasePoolPush());
25 [[TestRoot new] autorelease];
26 testassert(TestRootAutorelease == 3);
27
28
29 testonthread(^{
30 [[TestRoot new] autorelease];
31 testassert(TestRootAutorelease == 4);
32 testassert(TestRootDealloc == 1);
33 });
34 // thread's autoreleased object should have deallocated
35 testassert(TestRootDealloc == 2);
36
37
38 // Test no-pool autorelease after a pool was pushed and popped.
39 // The simplest POOL_SENTINEL check during pop gets this wrong.
40 testonthread(^{
41 objc_autoreleasePoolPop(objc_autoreleasePoolPush());
42 [[TestRoot new] autorelease];
43 testassert(TestRootAutorelease == 5);
44 testassert(TestRootDealloc == 2);
45 });
46 testassert(TestRootDealloc == 3
47 );
48 succeed(__FILE__);
49 }