File: TRAutoreleasePoolTests.m

package info (click to toggle)
openvpn-auth-ldap 2.0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,440 kB
  • sloc: ansic: 8,366; objc: 3,799; sh: 2,718; cpp: 594; makefile: 189; xml: 36
file content (78 lines) | stat: -rw-r--r-- 2,030 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * TRAutoreleasePool.m vi:ts=4:sw=4:expandtab:
 *
 * Copyright (C) 2005 - 2007 Landon Fuller <landonf@opendarwin.org>
 * All rights reserved.
 *
 * This file is part of Objective-C Substrate.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.
 *
 * We disclaim all warranties with regard to this software, including all
 * implied warranties of merchantability and fitness, in no event shall
 * we be liable for any special, indirect or consequential damages or any
 * damages whatsoever resulting from loss of use, data or profits, whether in
 * an action of contract, negligence or other tortious action, arising out of
 * or in connection with the use or performance of this software.
 */

#import "TRAutoreleasePool.h"
#import "PXTestCase.h"

static unsigned int livecount;

@interface PoolTester : TRObject
@end

@implementation PoolTester

- (oneway void) release {
    livecount--;
    [super release];
}

- (void) dealloc {
    livecount--;
    [super dealloc];
}

@end

@interface TRAutoreleasePoolTests : PXTestCase @end

@implementation TRAutoreleasePoolTests

- (void) testAddObject {
    TRAutoreleasePool *pool;
    TRObject *obj;
    int i;

    /* Allocate a pool */
    pool = [[TRAutoreleasePool alloc] init];
    fail_if(pool == nil, "[[TRAutoreleasePool alloc] init] returned nil.\n");

    /* Allocate an object to auto-release */
    obj = [[PoolTester alloc] init];
    [obj autorelease];

    /* Implicit refcount + dealloc */
    livecount = 2;

    /* Exercise the pool */
    for (i = 0; i < 4096; i++) {
        livecount++;
        [obj retain];
        [obj autorelease];
    }

    /* Release it */
    [pool release];

    fail_unless(livecount == 0, "[TRAutoreleasePool release] failed to release %d objects.", livecount);
}

@end