Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,26 +1,26 @@ include ../extra.mk SUBDIRS = ${TESTPLUGIN} PROG_NOINST = tests${PROG_SUFFIX} -SRCS = OFArray.m \ - OFDataArray.m \ - OFDictionary.m \ - OFHashes.m \ - OFList.m \ - OFNumber.m \ - OFObject.m \ - ${OFPLUGIN_M} \ - OFStream.m \ - OFString.m \ - OFTCPSocket.m \ - ${OFTHREAD_M} \ - OFXMLElement.m \ - OFXMLParser.m \ - main.m \ - ${PROPERTIES_M} +SRCS = OFArray.m \ + OFDataArray.m \ + OFDictionary.m \ + OFHashes.m \ + OFList.m \ + OFNumber.m \ + OFObject.m \ + ${OFPLUGIN_M} \ + OFStream.m \ + OFString.m \ + OFTCPSocket.m \ + ${OFTHREAD_M} \ + OFXMLElement.m \ + OFXMLParser.m \ + ${PROPERTIES_M} \ + TestsAppDelegate.m IPHONE_USER = mobile IPHONE_TMP = /tmp/objfw-test .PHONY: run run-tests run-on-iphone Index: tests/OFArray.m ================================================================== --- tests/OFArray.m +++ tests/OFArray.m @@ -14,22 +14,22 @@ #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFArray"; static OFString *c_ary[] = { @"Foo", @"Bar", @"Baz", nil }; -void -array_tests() +@implementation TestsAppDelegate (OFArrayTests) +- (void)arrayTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *a[3]; OFMutableArray *m[2]; OFEnumerator *enumerator; @@ -187,5 +187,6 @@ [m[0] removeNObjects: 1]; #endif [pool drain]; } +@end Index: tests/OFDataArray.m ================================================================== --- tests/OFDataArray.m +++ tests/OFDataArray.m @@ -16,17 +16,17 @@ #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module; const char *str = "Hello!"; -static void -do_tests(Class class) +@implementation TestsAppDelegate (OFDataArrayTests) +- (void)dataArrayTestsWithClass: (Class)class { OFDataArray *array[4]; void *data[2]; Class other; @@ -109,18 +109,18 @@ EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", OFOutOfRangeException, [array[0] removeNItems: [array[0] count] + 1]) } -void -dataarray_tests() +- (void)dataArrayTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; module = @"OFDataArray"; - do_tests([OFDataArray class]); + [self dataArrayTestsWithClass: [OFDataArray class]]; module = @"OFBigDataArray"; - do_tests([OFBigDataArray class]); + [self dataArrayTestsWithClass: [OFBigDataArray class]]; [pool drain]; } +@end Index: tests/OFDictionary.m ================================================================== --- tests/OFDictionary.m +++ tests/OFDictionary.m @@ -15,11 +15,11 @@ #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFDictionary"; static OFString *keys[] = { @"key1", @"key2" @@ -27,12 +27,12 @@ static OFString *values[] = { @"value1", @"value2" }; -void -dictionary_tests() +@implementation TestsAppDelegate (OFDictionaryTests) +- (void)dictionaryTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableDictionary *dict = [OFMutableDictionary dictionary], *dict2; OFEnumerator *key_enum, *obj_enum; OFArray *akeys, *avalues; @@ -148,5 +148,6 @@ forKey: keys[0]] && [dict isEqual: dict2]) [pool drain]; } +@end Index: tests/OFHashes.m ================================================================== --- tests/OFHashes.m +++ tests/OFHashes.m @@ -17,22 +17,22 @@ #import "OFFile.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFHashes"; const uint8_t testfile_md5[OF_MD5_DIGEST_SIZE] = "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; const uint8_t testfile_sha1[OF_SHA1_DIGEST_SIZE] = "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96\xF5" "\x94\xE7\x17"; -void -hashes_tests() +@implementation TestsAppDelegate (OFHashesTests) +- (void)hashesTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *md5; OFSHA1Hash *sha1; OFFile *f = [OFFile fileWithPath: @"testfile" @@ -64,5 +64,6 @@ OFHashAlreadyCalculatedException, [sha1 updateWithBuffer: "" ofSize: 1]) [pool drain]; } +@end Index: tests/OFList.m ================================================================== --- tests/OFList.m +++ tests/OFList.m @@ -14,21 +14,21 @@ #import "OFList.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFList"; static OFString *strings[] = { @"Foo", @"Bar", @"Baz" }; -void -list_tests() +@implementation TestsAppDelegate (OFListTests) +- (void)listTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFList *list; TEST(@"+[list]", (list = [OFList list])) @@ -68,5 +68,6 @@ TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]]) [pool drain]; } +@end Index: tests/OFNumber.m ================================================================== --- tests/OFNumber.m +++ tests/OFNumber.m @@ -9,19 +9,20 @@ * the packaging of this file. */ #include "config.h" +#import "OFString.h" #import "OFNumber.h" #import "OFAutoreleasePool.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFNumber"; -void -number_tests() +@implementation TestsAppDelegate (OFNumberTests) +- (void)numberTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *num; TEST(@"+[numberWithIntMax:]", @@ -46,5 +47,6 @@ TEST(@"-[shiftRight:]", [[num shiftRight: [OFNumber numberWithInt: 8]] asInt] == 482253) [pool drain]; } +@end Index: tests/OFObject.m ================================================================== --- tests/OFObject.m +++ tests/OFObject.m @@ -9,19 +9,20 @@ * the packaging of this file. */ #include "config.h" +#import "OFString.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFObject"; -void -object_tests() +@implementation TestsAppDelegate (OFObjectTests) +- (void)objectTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFObject *obj = [[[OFObject alloc] init] autorelease]; void *p, *q, *r; @@ -63,5 +64,6 @@ OFMemoryNotPartOfObjectException, [obj resizeMemory: (void*)1 toSize: 1024]) [pool drain]; } +@end Index: tests/OFPlugin.m ================================================================== --- tests/OFPlugin.m +++ tests/OFPlugin.m @@ -14,18 +14,18 @@ #import "OFPlugin.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" #import "plugin/TestPlugin.h" static OFString *module = @"OFPlugin"; -void -plugin_tests() +@implementation TestsAppDelegate (OFPluginTests) +- (void)pluginTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; TestPlugin *plugin; TEST(@"+[pluginFromFile:]", @@ -33,5 +33,6 @@ TEST(@"TestPlugin's -[test:]", [plugin test: 1234] == 2468) [pool drain]; } +@end Index: tests/OFStream.m ================================================================== --- tests/OFStream.m +++ tests/OFStream.m @@ -11,14 +11,15 @@ #include "config.h" #include +#import "OFString.h" #import "OFStream.h" #import "OFAutoreleasePool.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFStream"; @interface StreamTester: OFStream { @@ -57,12 +58,12 @@ return 0; } @end -void -stream_tests() +@implementation TestsAppDelegate (OFStreamTests) +- (void)streamTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; StreamTester *t = [[[StreamTester alloc] init] autorelease]; OFString *str; char *cstr; @@ -75,5 +76,6 @@ [(str = [t readLine]) length] == of_pagesize - 3 && !strcmp([str cString], cstr)) [pool drain]; } +@end Index: tests/OFString.m ================================================================== --- tests/OFString.m +++ tests/OFString.m @@ -14,11 +14,11 @@ #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFString"; static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" @@ -35,12 +35,12 @@ return nil; } @end -void -string_tests() +@implementation TestsAppDelegate (OFStringTests) +- (void)stringTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableString *s[3]; OFArray *a; int i; @@ -339,5 +339,6 @@ (s[0] = [@"x&foo;y" stringByXMLUnescapingWithHandler: h]) && [s[0] isEqual: @"xbary"]) [pool drain]; } +@end Index: tests/OFTCPSocket.m ================================================================== --- tests/OFTCPSocket.m +++ tests/OFTCPSocket.m @@ -19,16 +19,16 @@ #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" #import "macros.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFTCPSocket"; -void -tcpsocket_tests() +@implementation TestsAppDelegate (OFTCPSocketTests) +- (void)TCPSocketTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFTCPSocket *server, *client = nil, *accepted; OFString *service, *msg; uint16_t port; @@ -63,5 +63,6 @@ intoBuffer: buf] && !memcmp(buf, "Hello!", 6)) [pool drain]; } +@end Index: tests/OFThread.m ================================================================== --- tests/OFThread.m +++ tests/OFThread.m @@ -14,11 +14,11 @@ #import "OFThread.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFThread"; @interface TestThread: OFThread @end @@ -31,12 +31,12 @@ return nil; } @end -void -thread_tests() +@implementation TestsAppDelegate (OFThreadTests) +- (void)threadTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; TestThread *t; OFTLSKey *key; @@ -53,5 +53,6 @@ TEST(@"+[objectForTLSKey:]", [[OFThread objectForTLSKey: key] isEqual: @"foo"]) [pool drain]; } +@end Index: tests/OFXMLElement.m ================================================================== --- tests/OFXMLElement.m +++ tests/OFXMLElement.m @@ -16,16 +16,16 @@ #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFXMLElement"; -void -xmlelement_tests() +@implementation TestsAppDelegate (OFXMLElementTests) +- (void)XMLElementTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *elem[2]; TEST(@"+[elementWithName:]", @@ -49,5 +49,6 @@ [elem[0] addChild: [OFXMLElement elementWithName: @"bar"]] && [[elem[0] string] isEqual: @""]) [pool drain]; } +@end Index: tests/OFXMLParser.m ================================================================== --- tests/OFXMLParser.m +++ tests/OFXMLParser.m @@ -18,11 +18,11 @@ #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"OFXMLParser"; static int i = 0; enum event_type { @@ -30,13 +30,18 @@ TAG_END, STRING, COMMENT }; -static void -callback(enum event_type et, OFString *name, OFString *prefix, OFString *ns, - OFArray *attrs, OFString *string, OFString *comment) +@implementation TestsAppDelegate (OFXMLParser) +- (void)xmlParserCallbackWithEventType: (enum event_type)et + name: (OFString*)name + prefix: (OFString*)prefix + namespace: (OFString*)ns + attributes: (OFArray*)attrs + string: (OFString*)string + comment: (OFString*)comment { OFString *msg; id *carray; size_t count; @@ -114,41 +119,61 @@ TEST(msg, NO) break; } } -@interface ParserDelegate: OFObject -@end - -@implementation ParserDelegate - (void)xmlParser: (OFXMLParser*)parser didStartTagWithName: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns attributes: (OFArray*)attrs { - callback(TAG_START, name, prefix, ns, attrs, nil, nil); + [self xmlParserCallbackWithEventType: TAG_START + name: name + prefix: prefix + namespace: ns + attributes: attrs + string: nil + comment: nil]; } - (void)xmlParser: (OFXMLParser*)parser didEndTagWithName: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns { - callback(TAG_END, name, prefix, ns, nil, nil, nil); + [self xmlParserCallbackWithEventType: TAG_END + name: name + prefix: prefix + namespace: ns + attributes: nil + string: nil + comment: nil]; } - (void)xmlParser: (OFXMLParser*)parser foundString: (OFString*)string { - callback(STRING, nil, nil, nil, nil, string, nil); + [self xmlParserCallbackWithEventType: STRING + name: nil + prefix: nil + namespace: nil + attributes: nil + string: string + comment: nil]; } - (void)xmlParser: (OFXMLParser*)parser foundComment: (OFString*)comment { - callback(COMMENT, nil, nil, nil, nil, nil, comment); + [self xmlParserCallbackWithEventType: COMMENT + name: nil + prefix: nil + namespace: nil + attributes: nil + string: nil + comment: comment]; } - (OFString*)xmlParser: (OFXMLParser*)parser foundUnknownEntityNamed: (OFString*)entity { @@ -155,14 +180,12 @@ if ([entity isEqual: @"foo"]) return @"foobar"; return nil; } -@end -void -xmlparser_tests() +- (void)XMLParserTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLParser *parser; const char *str = "bar\r\n" "foo<barbar quxbar\r\n" @@ -169,12 +192,11 @@ ""; size_t j, len; TEST(@"+[xmlParser]", (parser = [OFXMLParser xmlParser])) - TEST(@"-[setDelegate:]", - [parser setDelegate: [[[ParserDelegate alloc] init] autorelease]]) + TEST(@"-[setDelegate:]", [parser setDelegate: self]) /* Simulate a stream where we only get chunks */ len = strlen(str); for (j = 0; j < len; j+= 2) { @@ -188,5 +210,6 @@ TEST(@"Checking if everything was parsed", i == 11) [pool drain]; } +@end ADDED tests/TestsAppDelegate.h Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2008 - 2010 + * 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 included in + * the packaging of this file. + */ + +#import "OFApplication.h" + +#define TEST(test, cond) \ + { \ + [self outputTesting: test \ + inModule: module]; \ + \ + if (cond) \ + [self outputSuccess: test \ + inModule: module]; \ + else { \ + [self outputFailure: test \ + inModule: module]; \ + fails++; \ + } \ + } +#define EXPECT_EXCEPTION(test, exception, code) \ + { \ + BOOL caught = NO; \ + \ + [self outputTesting: test \ + inModule: module]; \ + \ + @try { \ + code; \ + } @catch (exception *e) { \ + caught = YES; \ + [e dealloc]; \ + } \ + \ + if (caught) \ + [self outputSuccess: test \ + inModule: module]; \ + else { \ + [self outputFailure: test \ + inModule: module]; \ + fails++; \ + } \ + } + +@class OFString; + +@interface TestsAppDelegate: OFObject +{ + int fails; +} + +- (void)outputString: (OFString*)str + withColor: (int)color; +- (void)outputTesting: (OFString*)test + inModule: (OFString*)module; +- (void)outputSuccess: (OFString*)test + inModule: (OFString*)module; +- (void)outputFailure: (OFString*)test + inModule: (OFString*)module; +@end + +@interface TestsAppDelegate (OFArrayTests) +- (void)arrayTests; +@end + +@interface TestsAppDelegate (OFDataArrayTests) +- (void)dataArrayTests; +@end + +@interface TestsAppDelegate (OFDictionaryTests) +- (void)dictionaryTests; +@end + +@interface TestsAppDelegate (OFHashesTests) +- (void)hashesTests; +@end + +@interface TestsAppDelegate (OFListTests) +- (void)listTests; +@end + +@interface TestsAppDelegate (OFNumberTests) +- (void)numberTests; +@end + +@interface TestsAppDelegate (OFObjectTests) +- (void)objectTests; +@end + +@interface TestsAppDelegate (OFPluginTests) +- (void)pluginTests; +@end + +@interface TestsAppDelegate (PropertiesTests) +- (void)propertiesTests; +@end + +@interface TestsAppDelegate (OFStreamTests) +- (void)streamTests; +@end + +@interface TestsAppDelegate (OFStringTests) +- (void)stringTests; +@end + +@interface TestsAppDelegate (OFTCPSocketTests) +- (void)TCPSocketTests; +@end + +@interface TestsAppDelegate (OFThreadTests) +- (void)threadTests; +@end + +@interface TestsAppDelegate (OFXMLElementTests) +- (void)XMLElementTests; +@end + +@interface TestsAppDelegate (OFXMLParserTests) +- (void)XMLParserTests; +@end ADDED tests/TestsAppDelegate.m Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2008 - 2010 + * 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 included in + * the packaging of this file. + */ + +#import "OFString.h" +#import "OFFile.h" +#import "OFAutoreleasePool.h" + +#import "TestsAppDelegate.h" + +@implementation TestsAppDelegate +- (void)outputString: (OFString*)str + withColor: (int)color +{ +#ifdef STDOUT + switch (color) { + case 0: + [of_stdout writeString: @"\r\033[K\033[1;33m"]; + break; + case 1: + [of_stdout writeString: @"\r\033[K\033[1;32m"]; + break; + case 2: + [of_stdout writeString: @"\r\033[K\033[1;31m"]; + break; + } + + [of_stdout writeString: str]; + [of_stdout writeString: @"\033[m"]; +#else +#error No output method! +#endif +} + +- (void)outputTesting: (OFString*)test + inModule: (OFString*)module +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + [self outputString: [OFString stringWithFormat: @"[%s] %s: testing...", + [module cString], + [test cString]] + withColor: 0]; + [pool release]; +} + +- (void)outputSuccess: (OFString*)test + inModule: (OFString*)module +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + [self outputString: [OFString stringWithFormat: @"[%s] %s: ok\n", + [module cString], + [test cString]] + withColor: 1]; + [pool release]; +} + +- (void)outputFailure: (OFString*)test + inModule: (OFString*)module +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + [self outputString: [OFString stringWithFormat: @"[%s] %s: failed\n", + [module cString], + [test cString]] + withColor: 2]; + [pool release]; +} + +- (void)applicationDidFinishLaunching +{ + [self objectTests]; + [self hashesTests]; + [self stringTests]; + [self dataArrayTests]; + [self arrayTests]; + [self dictionaryTests]; + [self listTests]; + [self numberTests]; + [self streamTests]; + [self TCPSocketTests]; +#ifdef OF_THREADS + [self threadTests]; +#endif + [self XMLElementTests]; + [self XMLParserTests]; +#ifdef OF_PLUGINS + [self pluginTests]; +#endif +#ifdef OF_HAVE_PROPERTIES + [self propertiesTests]; +#endif +} +@end + +int +main(int argc, char *argv[]) +{ + return of_application_main(argc, argv, [TestsAppDelegate class]); +} DELETED tests/main.h Index: tests/main.h ================================================================== --- tests/main.h +++ tests/main.h @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008 - 2010 - * 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 included in - * the packaging of this file. - */ - -#import "OFString.h" - -extern void testing(OFString*, OFString*); -extern void success(OFString*, OFString*); -extern void failed(OFString*, OFString*); - -#define TEST(test, cond) \ - { \ - testing(module, test); \ - \ - if (cond) \ - success(module, test); \ - else \ - failed(module, test); \ - } -#define EXPECT_EXCEPTION(test, exception, code) \ - { \ - BOOL caught = NO; \ - \ - testing(module, test); \ - \ - @try { \ - code; \ - } @catch (exception *e) { \ - caught = YES; \ - [e dealloc]; \ - } \ - \ - if (caught) \ - success(module, test); \ - else \ - failed(module, test); \ - } DELETED tests/main.m Index: tests/main.m ================================================================== --- tests/main.m +++ tests/main.m @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2008 - 2010 - * 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 included in - * the packaging of this file. - */ - -#include "config.h" - -#ifdef STDOUT -#include -#endif -#include - -#import "OFString.h" -#import "OFAutoreleasePool.h" - -extern void array_tests(); -extern void dataarray_tests(); -extern void dictionary_tests(); -extern void hashes_tests(); -extern void list_tests(); -extern void number_tests(); -extern void object_tests(); -#ifdef OF_PLUGINS -extern void plugin_tests(); -#endif -#ifdef OF_HAVE_PROPERTIES -extern void properties_tests(); -#endif -extern void stream_tests(); -extern void string_tests(); -extern void tcpsocket_tests(); -#ifdef OF_THREADS -extern void thread_tests(); -#endif -extern void xmlelement_tests(); -extern void xmlparser_tests(); - -static int fails = 0; - -static void -output(OFString *str, int color) -{ -#ifdef STDOUT - switch (color) { - case 0: - fputs("\r\033[K\033[1;33m", stdout); - break; - case 1: - fputs("\r\033[K\033[1;32m", stdout); - break; - case 2: - fputs("\r\033[K\033[1;31m", stdout); - break; - } - - fputs([str cString], stdout); - fputs("\033[m", stdout); - fflush(stdout); -#else -#error No output method! -#endif -} - -void -testing(OFString *module, OFString *test) -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *str = [OFString stringWithFormat: @"[%s] %s: testing...", - [module cString], - [test cString]]; - output(str, 0); - [pool release]; -} - -void -success(OFString *module, OFString *test) -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *str = [OFString stringWithFormat: @"[%s] %s: ok\n", - [module cString], - [test cString]]; - output(str, 1); - [pool release]; -} - -void -failed(OFString *module, OFString *test) -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *str = [OFString stringWithFormat: @"[%s] %s: failed\n", - [module cString], - [test cString]]; - output(str, 2); - fails++; - [pool release]; -} - -int -main() -{ - object_tests(); - hashes_tests(); - string_tests(); - dataarray_tests(); - array_tests(); - dictionary_tests(); - list_tests(); - number_tests(); - stream_tests(); - tcpsocket_tests(); -#ifdef OF_THREADS - thread_tests(); -#endif - xmlelement_tests(); - xmlparser_tests(); -#ifdef OF_PLUGINS - plugin_tests(); -#endif -#ifdef OF_HAVE_PROPERTIES - properties_tests(); -#endif - - return fails; -} Index: tests/properties.m ================================================================== --- tests/properties.m +++ tests/properties.m @@ -12,11 +12,11 @@ #include "config.h" #import "OFString.h" #import "OFAutoreleasePool.h" -#import "main.h" +#import "TestsAppDelegate.h" static OFString *module = @"Properties"; @interface PropertiesTest: OFObject { @@ -39,12 +39,12 @@ [super dealloc]; } @end -void -properties_tests() +@implementation TestsAppDelegate (PropertiesTests) +- (void)propertiesTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; PropertiesTest *pt = [[[PropertiesTest alloc] init] autorelease]; OFString *t = [OFMutableString stringWithString: @"foo"]; @@ -55,5 +55,6 @@ [pt setBar: t]; TEST(@"retain, atomic", [pt bar] == t && [t retainCount] == 3) [pool drain]; } +@end