ADDED tests/ForwardingTests.m Index: tests/ForwardingTests.m ================================================================== --- tests/ForwardingTests.m +++ tests/ForwardingTests.m @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * Jonathan Schleifer + * + * 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.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFString.h" +#import "OFAutoreleasePool.h" + +#import "TestsAppDelegate.h" + +static OFString *module = @"Forwarding"; +static size_t forwardings = 0; +static BOOL success = NO; + +@interface ForwardingTest: OFObject +@end + +@interface ForwardingTest (Test) ++ (void)test; +- (void)test; +@end + +static void +test(id self, SEL _cmd) +{ + success = YES; +} + +@implementation ForwardingTest ++ (BOOL)resolveClassMethod: (SEL)selector +{ + forwardings++; + + if (sel_isEqual(selector, @selector(test))) { + [self replaceClassMethod: @selector(test) + withImplementation: (IMP)test + typeEncoding: "v@:"]; + return YES; + } + + return NO; +} + ++ (BOOL)resolveInstanceMethod: (SEL)selector +{ + forwardings++; + + if (sel_isEqual(selector, @selector(test))) { + [self replaceInstanceMethod: @selector(test) + withImplementation: (IMP)test + typeEncoding: "v@:"]; + return YES; + } + + return NO; +} +@end + +@implementation TestsAppDelegate (ForwardingTests) +- (void)forwardingTests +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + TEST(@"Forwarding a message and adding a class method", + R([ForwardingTest test]) && success && + R([ForwardingTest test]) && forwardings == 1); + + ForwardingTest *t = [[[ForwardingTest alloc] init] autorelease]; + + success = NO; + forwardings = 0; + + TEST(@"Forwarding a message and adding an instance method", + R([t test]) && success && R([t test]) && forwardings == 1); + + [pool drain]; +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,11 +1,12 @@ include ../extra.mk SUBDIRS = ${TESTPLUGIN} PROG_NOINST = tests${PROG_SUFFIX} -SRCS = OFArrayTests.m \ +SRCS = ForwardingTests.m \ + OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFDataArrayTests.m \ OFDateTests.m \ OFDictionaryTests.m \ ${OFHTTPREQUESTTESTS_M} \ Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -89,10 +89,14 @@ @end @interface TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTests; @end + +@interface TestsAppDelegate (ForwardingTests) +- (void)forwardingTests; +@end @interface TestsAppDelegate (OFHTTPRequestTests) - (void)HTTPRequestTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -142,13 +142,14 @@ [self serializationTests]; [self JSONTests]; #ifdef OF_PLUGINS [self pluginTests]; #endif + [self forwardingTests]; #ifdef OF_HAVE_PROPERTIES [self propertiesTests]; #endif if (fails > 0) [OFApplication terminateWithStatus: fails]; } @end