Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -3,11 +3,10 @@ SUBDIRS = OFDataArray \ OFHashes \ ${OFPLUGIN} \ OFTCPSocket \ OFThread \ - OFList \ OFXMLElement \ OFXMLParser \ ${OBJC_SYNC} include ../buildsys.mk DELETED tests/OFList/Makefile Index: tests/OFList/Makefile ================================================================== --- tests/OFList/Makefile +++ tests/OFList/Makefile @@ -1,29 +0,0 @@ -PROG_NOINST = oflist${PROG_SUFFIX} -SRCS = OFList.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/OFList/OFList.m Index: tests/OFList/OFList.m ================================================================== --- tests/OFList/OFList.m +++ tests/OFList/OFList.m @@ -1,133 +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 "OFString.h" -#import "OFList.h" - -#ifndef _WIN32 -#define ZD "%zd" -#else -#define ZD "%u" -#endif - -#define NUM_TESTS 27 -#define SUCCESS \ -{ \ - printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m", \ - (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ - fflush(stdout); \ -} -#define FAIL \ -{ \ - printf("\r\033[K\033[1;31mTest " ZD "/%d failed!\033[m\n", \ - i + 1, NUM_TESTS); \ - return 1; \ -} -#define CHECK(cond) \ -{ \ - if (cond) \ - SUCCESS \ - else \ - FAIL \ - i++; \ -} - -const OFString *strings[] = { - @"First String Object", - @"Second String Object", - @"Third String Object" -}; - -int -main() -{ - size_t i, j; - OFList *list, *list2, *list3; - of_list_object_t *iter, *iter2; - - list = [OFList list]; - - [list append: strings[0]]; - [list append: strings[1]]; - [list append: strings[2]]; - - for (iter = [list first], i = 0; iter != NULL; iter = iter->next, i++) - if ([iter->object isEqual: strings[i]]) - SUCCESS - else - FAIL - - CHECK([[list first]->object isEqual: strings[0]]) - CHECK([[list last]->object isEqual: strings[2]]) - - [list remove: [list last]]; - CHECK([[list last]->object isEqual: strings[1]]) - - [list remove: [list first]]; - CHECK([[list first]->object isEqual: [list last]->object]) - - [list insert: strings[0] - before: [list last]]; - [list insert: strings[2] - after: [list first]->next]; - - for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++) - CHECK([iter->object isEqual: strings[j]]) - - CHECK([list count] == 3) - - list2 = [list copy]; - CHECK([list2 count] == 3) - [list2 remove: [list2 last]]; - CHECK([list2 count] == 2) - [list2 remove: [list2 first]->next]; - CHECK([list2 count] == 1) - [list2 remove: [list2 first]]; - CHECK([list2 count] == 0) - - list2 = [OFList list]; - - [list2 append: strings[0]]; - [list2 append: strings[1]]; - [list2 append: strings[2]]; - CHECK([list2 isEqual: list]); - - [list2 remove: [list2 last]]; - CHECK(![list2 isEqual: list]); - - /* - * Only mutableCopy is guaranteed to return a real copy instead of just - * increasing the reference counter. - */ - [list2 append: [@"foo" mutableCopy]]; - CHECK(![list2 isEqual: list]); - - list3 = [list2 copy]; - CHECK([list2 isEqual: list3]); - - for (iter = [list2 first], iter2 = [list3 first]; - iter != NULL && iter2 != NULL; - iter = iter->next, iter2 = iter2->next) { - CHECK(iter != iter2) - CHECK(iter->object == iter2->object) - } - CHECK(iter == NULL && iter2 == NULL) - CHECK([[list2 last]->object retainCount] == 3) - - puts(""); - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -1,8 +1,9 @@ PROG_NOINST = tests${PROG_SUFFIX} SRCS = array.m \ dictionary.m \ + list.m \ main.m \ object.m \ string.m include ../buildsys.mk ADDED tests_new/list.m Index: tests_new/list.m ================================================================== --- tests_new/list.m +++ tests_new/list.m @@ -0,0 +1,72 @@ +/* + * 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 "OFList.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" + +#import "main.h" + +static OFString *module = @"OFList"; +static OFString *strings[] = { + @"Foo", + @"Bar", + @"Baz" +}; + +void +list_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFList *list; + + TEST(@"+[list]", (list = [OFList list])) + + TEST(@"-[append:]", [list append: strings[0]] && + [list append: strings[1]] && [list append: strings[2]]) + + TEST(@"-[first]", [[list first]->object isEqual: strings[0]]) + + TEST(@"-[first]->next", + [[list first]->next->object isEqual: strings[1]]) + + TEST(@"-[last]", [[list last]->object isEqual: strings[2]]) + + TEST(@"-[last]->prev", [[list last]->prev->object isEqual: strings[1]]) + + TEST(@"-[remove:]", [list remove: [list last]] && + [[list last]->object isEqual: strings[1]] && + [list remove: [list first]] && + [[list first]->object isEqual: [list last]->object]) + + TEST(@"-[insert:before:]", [list insert: strings[0] + before: [list last]] && + [[list last]->prev->object isEqual: strings[0]]) + + + TEST(@"-[insert:after:]", [list insert: strings[2] + after: [list first]->next] && + [[list last]->object isEqual: strings[2]]) + + TEST(@"-[count]", [list count] == 3) + + TEST(@"-[copy]", (list = [[list copy] autorelease]) && + [[list first]->object isEqual: strings[0]] && + [[list first]->next->object isEqual: strings[1]] && + [[list last]->object isEqual: strings[2]]) + + TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]]) + + [pool release]; +} Index: tests_new/main.m ================================================================== --- tests_new/main.m +++ tests_new/main.m @@ -19,10 +19,11 @@ #import "OFString.h" #import "OFAutoreleasePool.h" extern void array_tests(); extern void dictionary_tests(); +extern void list_tests(); extern void object_tests(); extern void string_tests(); static int fails = 0; @@ -89,8 +90,9 @@ { object_tests(); string_tests(); array_tests(); dictionary_tests(); + list_tests(); return fails; }