Artifact aa69694177f57c56a76e3746d21124265ed981a94cf6149c9042ec1c90024b3e:
- File
tests/OFAutoreleasePool/OFAutoreleasePool.m
— part of check-in
[2a4aa05a84]
at
2009-05-05 12:05:06
on branch trunk
— Rename OFArray to OFDataArray and add a new OFArray which stores objects.
Additionally, change OFAutoreleasePool to use the new OFArray.And while at it, change #import <config.h> in some files to
#import "config.h". (user: js, size: 1889) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008 - 2009 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "config.h" #include <stdio.h> #import "OFAutoreleasePool.h" #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif int inits; int retains; int releases; IMP init; IMP retain; IMP release; @interface TestObject: OFObject - init; - retain; - release; @end @implementation TestObject - init { id ret; inits++; ret = init(self, _cmd); printf("New %s with retain cnt " ZD "\n", [self name], [ret retainCount]); return ret; } - retain { id ret; retains++; ret = retain(self, _cmd); printf("Retaining %s to " ZD "\n", [self name], [ret retainCount]); return ret; } - release { releases++; printf("Releasing %s to " ZD "\n", [self name], [self retainCount] - 1); return release(self, _cmd); } @end int main() { inits = retains = releases = 0; init = [OFObject replaceMethod: @selector(init) withMethodFromClass: [TestObject class]]; retain = [OFObject replaceMethod: @selector(retain) withMethodFromClass: [TestObject class]]; release = [OFObject replaceMethod: @selector(release) withMethodFromClass: [TestObject class]]; OFObject *o1, *o2, *o3; OFAutoreleasePool *pool1, *pool2; o1 = [[[OFObject alloc] init] autorelease]; pool1 = [[OFAutoreleasePool alloc] init]; o2 = [[[OFObject alloc] init] autorelease]; [pool1 releaseObjects]; o2 = [[[OFObject alloc] init] autorelease]; pool2 = [[OFAutoreleasePool alloc] init]; o3 = [[[OFObject alloc] init] autorelease]; [pool1 retain]; [pool1 release]; [pool1 release]; [o3 free]; return (inits == 20 && retains == 6 && releases == 13 ? 0 : 1); }