Artifact a4019c97d27e6ddaa9acc3120f71fce660d8d8fa4902bbcccf9cc932c4148a12:
- File
tests/OFBlockTests.m
— part of check-in
[86c967829f]
at
2010-12-27 01:15:36
on branch trunk
— Move global block to global scope.
Some old clang revisions do not create global blocks in local scopes.
Verified with clang r90573. (user: js, size: 1907) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. 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. */ #include "config.h" #import "OFBlock.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #if defined(OF_OBJFW_RUNTIME) # include <objfw-rt.h> #elif defined(OF_OLD_GNU_RUNTIME) # include <objc/objc-api.h> #endif #if defined(OF_OLD_GNU_RUNTIME) || defined(OF_OBJFW_RUNTIME) # define objc_getClass objc_get_class #endif #import "TestsAppDelegate.h" static OFString *module = @"OFBlock"; extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; static void (^g)() = ^ {}; @implementation TestsAppDelegate (OFBlockTests) - (void)blockTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; __block int x; void (^s)() = ^ { x = 0; }; void (^m)(); TEST(@"Class of stack block", (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") && [s isKindOfClass: [OFBlock class]]) TEST(@"Class of global block", (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") && [g isKindOfClass: [OFBlock class]]) TEST(@"Class of a malloc block", (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock")) TEST(@"Copying a stack block", (m = [s copy]) && [m class] == objc_getClass("OFMallocBlock") && [m isKindOfClass: [OFBlock class]]) TEST(@"Copying a global block", (id)g == [g copy]) TEST(@"Copying a malloc block", (id)m == [m copy] && [m retainCount] == 2) TEST(@"Autorelease a stack block", R([s autorelease])) TEST(@"Autorelease a global block", R([g autorelease])) TEST(@"Autorelease a malloc block", R([m autorelease])) [pool drain]; } @end