Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,9 +1,8 @@ include ../extra.mk SUBDIRS = OFDataArray \ - OFArray \ OFHashes \ ${OFPLUGIN} \ OFTCPSocket \ OFThread \ OFList \ DELETED tests/OFArray/Makefile Index: tests/OFArray/Makefile ================================================================== --- tests/OFArray/Makefile +++ tests/OFArray/Makefile @@ -1,29 +0,0 @@ -PROG_NOINST = ofarray${PROG_SUFFIX} -SRCS = OFArray.m - -include ../../buildsys.mk -include ../../extra.mk - -CPPFLAGS += -I../../src -I../.. -LIBS := -L../../src -lobjfw ${LIBS} - -.PHONY: run - -all: run -run: ${PROG_NOINST} - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib - if test -f ../../src/libobjfw.so; then \ - ln -s ../../src/libobjfw.so libobjfw.so.0; \ - ln -s ../../src/libobjfw.so libobjfw.so.0.1; \ - fi - if test -f ../../src/libobjfw.dll; then \ - ln ../../src/libobjfw.dll libobjfw.dll; \ - fi - if test -f ../../src/libobjfw.dylib; then \ - ln -s ../../src/libobjfw.dylib libobjfw.dylib; \ - fi - LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ - DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ - ${TEST_LAUNCHER} ./${PROG_NOINST}; EXIT=$$?; \ - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib; \ - exit $$EXIT DELETED tests/OFArray/OFArray.m Index: tests/OFArray/OFArray.m ================================================================== --- tests/OFArray/OFArray.m +++ tests/OFArray/OFArray.m @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * Jonathan Schleifer - * - * 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. - */ - -#include "config.h" - -#include -#include - -#import "OFArray.h" -#import "OFAutoreleasePool.h" -#import "OFString.h" -#import "OFExceptions.h" - -#define CATCH_EXCEPTION(code, exception) \ - @try { \ - code; \ - \ - puts("NOT CAUGHT!"); \ - return 1; \ - } @catch (exception *e) { \ - puts("CAUGHT! Error string was:"); \ - puts([[e string] cString]); \ - puts("Resuming..."); \ - } - -id c_array[] = { - @"Foo", - @"Bar", - @"Baz", - nil -}; - -int -main() -{ - OFArray *a = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; - OFArray *b = [OFMutableArray array]; - OFArray *c = [OFArray arrayWithCArray: c_array]; - - [b addObject: @"Foo"]; - [b addObject: @"Bar"]; - [b addObject: @"Baz"]; - - assert([a count] == 3); - assert([b count] == 3); - assert([c count] == 3); - assert([a isEqual: b]); - assert([a isEqual: c]); - - [b removeNObjects: 1]; - [b addObject: @"Baz"]; - assert([a isEqual: b]); - - [b removeNObjects: 1]; - [b addObject: @"Qux"]; - assert(![a isEqual: b]); - - CATCH_EXCEPTION([a objectAtIndex: 3], OFOutOfRangeException) - CATCH_EXCEPTION([a addObject: @"foo"], OFNotImplementedException) - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -1,7 +1,8 @@ PROG_NOINST = tests${PROG_SUFFIX} -SRCS = dictionary.m \ +SRCS = array.m \ + dictionary.m \ main.m \ object.m \ string.m include ../buildsys.mk ADDED tests_new/array.m Index: tests_new/array.m ================================================================== --- tests_new/array.m +++ tests_new/array.m @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008 - 2009 + * Jonathan Schleifer + * + * 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. + */ + +#include "config.h" + +#import "OFArray.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" + +#import "main.h" + +static OFString *module = @"OFArray"; +static OFString *c_ary[] = { + @"Foo", + @"Bar", + @"Baz", + nil +}; + +void +array_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFArray *a[3]; + + TEST(@"+[array]", (a[0] = [OFMutableArray array])) + + TEST(@"+[arrayWithObjects:]", + (a[1] = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) + + TEST(@"+[arrayWithCArray:]", (a[2] = [OFArray arrayWithCArray: c_ary])) + + TEST(@"-[addObject:]", [a[0] addObject: c_ary[0]] && + [a[0] addObject: c_ary[1]] && [a[0] addObject: c_ary[2]]) + + TEST(@"-[count]", [a[0] count] == 3 && [a[1] count] == 3 && + [a[2] count] == 3) + + TEST(@"-[isEqual:]", [a[0] isEqual: a[1]] && [a[1] isEqual: a[2]]) + + TEST(@"-[objectAtIndex:]", + [[a[0] objectAtIndex: 0] isEqual: c_ary[0]] && + [[a[0] objectAtIndex: 1] isEqual: c_ary[1]] && + [[a[0] objectAtIndex: 2] isEqual: c_ary[2]] && + [[a[1] objectAtIndex: 0] isEqual: c_ary[0]] && + [[a[1] objectAtIndex: 1] isEqual: c_ary[1]] && + [[a[1] objectAtIndex: 2] isEqual: c_ary[2]] && + [[a[2] objectAtIndex: 0] isEqual: c_ary[0]] && + [[a[2] objectAtIndex: 1] isEqual: c_ary[1]] && + [[a[2] objectAtIndex: 2] isEqual: c_ary[2]]) + + TEST(@"-[removeNObjects:]", [a[0] removeNObjects: 2] && + [a[0] count] == 1 && [[a[0] objectAtIndex: 0] isEqual: c_ary[0]]) + + EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", + OFOutOfRangeException, [a[0] objectAtIndex: 1]) + + [pool release]; +} Index: tests_new/main.m ================================================================== --- tests_new/main.m +++ tests_new/main.m @@ -17,10 +17,11 @@ #include #import "OFString.h" #import "OFAutoreleasePool.h" +extern void array_tests(); extern void dictionary_tests(); extern void object_tests(); extern void string_tests(); static int fails = 0; @@ -86,9 +87,10 @@ int main() { object_tests(); string_tests(); + array_tests(); dictionary_tests(); return fails; }