Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,10 +1,9 @@ include ../extra.mk SUBDIRS = OFDataArray \ OFArray \ - OFDictionary \ OFHashes \ ${OFPLUGIN} \ OFTCPSocket \ OFThread \ OFList \ DELETED tests/OFDictionary/Makefile Index: tests/OFDictionary/Makefile ================================================================== --- tests/OFDictionary/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -PROG_NOINST = ofdictionary${PROG_SUFFIX} -SRCS = OFDictionary.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/OFDictionary/OFDictionary.m Index: tests/OFDictionary/OFDictionary.m ================================================================== --- tests/OFDictionary/OFDictionary.m +++ /dev/null @@ -1,163 +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 "OFAutoreleasePool.h" -#import "OFDictionary.h" -#import "OFString.h" -#import "OFExceptions.h" - -#define TESTS 14 - -int -main() -{ - int i = 0; - - OFDictionary *dict = [OFMutableDictionary dictionary]; - OFDictionary *dict2; - OFArray *keys, *objs; - OFIterator *iter; - of_iterator_pair_t pair[2]; - - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *key1 = [OFString stringWithString: @"key1"]; - OFString *key2 = [OFString stringWithString: @"key2"]; - OFString *value1 = [OFString stringWithString: @"value1"]; - OFString *value2 = [OFString stringWithString: @"value2"]; - - [dict setObject: value1 - forKey: key1]; - [dict setObject: value2 - forKey: key2]; - [pool release]; - - i++; - if (strcmp([[dict objectForKey: @"key1"] cString], "value1")) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if (strcmp([[dict objectForKey: key2] cString], "value2")) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - iter = [dict iterator]; - pair[0] = [iter nextKeyObjectPair]; - pair[1] = [iter nextKeyObjectPair]; - if (![pair[0].key isEqual: @"key1"] || - ![pair[0].object isEqual: @"value1"] || - ![pair[1].key isEqual: @"key2"] || - ![pair[1].object isEqual: @"value2"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if ([dict count] != 2) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if ([iter nextKeyObjectPair].object != nil) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if ([dict objectForKey: @"key3"] != nil) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - [dict release]; - dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", - @"baz", @"qux", - nil]; - - if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if (![[dict objectForKey: @"baz"] isEqual: @"qux"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - [dict release]; - dict = [OFDictionary dictionaryWithObject: @"bar" - forKey: @"foo"]; - if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - [dict release]; - keys = [OFArray arrayWithObjects: @"k1", @"k2", nil]; - objs = [OFArray arrayWithObjects: @"o1", @"o2", nil]; - dict = [OFDictionary dictionaryWithObjects: objs - forKeys: keys]; - if (![[dict objectForKey: @"k1"] isEqual: @"o1"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - if (![[dict objectForKey: @"k2"] isEqual: @"o2"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - dict2 = [dict copy]; - [dict release]; - if (![[dict2 objectForKey: @"k1"] isEqual: @"o1"] || - ![[dict2 objectForKey: @"k2"] isEqual: @"o2"]) { - printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - dict = [dict2 mutableCopy]; - [dict2 release]; - if (![[dict objectForKey: @"k1"] isEqual: @"o1"] || - ![[dict objectForKey: @"k2"] isEqual: @"o2"]) { - printf("\033[k\033[1;31mtest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - i++; - [dict setObject: @"o0" forKey: @"k1"]; - [dict setObject: @"o3" forKey: @"k3"]; - if (![[dict objectForKey: @"k1"] isEqual: @"o0"] || - ![[dict objectForKey: @"k2"] isEqual: @"o2"] || - ![[dict objectForKey: @"k3"] isEqual: @"o3"]) { - printf("\033[k\033[1;31mtest %d/%d failed!\033[m\n", i, TESTS); - return 1; - } - - printf("\033[1;32mTests successful: %d/%d\033[0m\n", i, TESTS); - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -1,8 +1,9 @@ PROG_NOINST = tests${PROG_SUFFIX} -SRCS = main.m \ - object.m \ +SRCS = dictionary.m \ + main.m \ + object.m \ string.m include ../buildsys.mk include ../extra.mk ADDED tests_new/dictionary.m Index: tests_new/dictionary.m ================================================================== --- /dev/null +++ tests_new/dictionary.m @@ -0,0 +1,105 @@ +/* + * 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 "OFDictionary.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" + +#import "main.h" + +static OFString *module = @"OFDictionary"; +static OFString *keys[] = { + @"key1", + @"key2" +}; +static OFString *values[] = { + @"value1", + @"value2" +}; + +void +dictionary_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFDictionary *dict = [OFMutableDictionary dictionary]; + OFIterator *iter; + of_iterator_pair_t pair[3]; + OFArray *akeys, *avalues; + + [dict setObject: values[0] + forKey: keys[0]]; + [dict setObject: values[1] + forKey: keys[1]]; + + TEST(@"-[objectForKey:]", + [[dict objectForKey: keys[0]] isEqual: values[0]] && + [[dict objectForKey: keys[1]] isEqual: values[1]] && + [dict objectForKey: @"key3"] == nil) + + TEST(@"-[iterator]", (iter = [dict iterator])) + + pair[0] = [iter nextKeyObjectPair]; + pair[1] = [iter nextKeyObjectPair]; + pair[2] = [iter nextKeyObjectPair]; + TEST(@"OFIterator's -[nextKeyObjectPair]", + [pair[0].key isEqual: keys[0]] && + [pair[0].object isEqual: values[0]] && + [pair[1].key isEqual: keys[1]] && + [pair[1].object isEqual: values[1]] && + pair[2].key == nil && pair[2].object == nil) + + TEST(@"-[count]", [dict count] == 2) + + TEST(@"+[dictionaryWithKeysAndObjects:]", + (dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", + @"baz", @"qux", + nil]) && + [[dict objectForKey: @"foo"] isEqual: @"bar"] && + [[dict objectForKey: @"baz"] isEqual: @"qux"]) + + TEST(@"+[dictionaryWithObject:forKey:]", + (dict = [OFDictionary dictionaryWithObject: @"bar" + forKey: @"foo"]) && + [[dict objectForKey: @"foo"] isEqual: @"bar"]) + + akeys = [OFArray arrayWithObjects: keys[0], keys[1], nil]; + avalues = [OFArray arrayWithObjects: values[0], values[1], nil]; + TEST(@"+[dictionaryWithObjects:forKeys:]", + (dict = [OFDictionary dictionaryWithObjects: avalues + forKeys: akeys]) && + [[dict objectForKey: keys[0]] isEqual: values[0]] && + [[dict objectForKey: keys[1]] isEqual: values[1]]) + + TEST(@"-[copy]", + (dict = [[dict copy] autorelease]) && + [[dict objectForKey: keys[0]] isEqual: values[0]] && + [[dict objectForKey: keys[1]] isEqual: values[1]]) + + TEST(@"-[mutableCopy]", + (dict = [[dict mutableCopy] autorelease]) && + [[dict objectForKey: keys[0]] isEqual: values[0]] && + [[dict objectForKey: keys[1]] isEqual: values[1]] && + [dict setObject: @"value3" + forKey: @"key3"] && + [[dict objectForKey: @"key3"] isEqual: @"value3"] && + [dict setObject: @"foo" + forKey: keys[0]] && + [[dict objectForKey: keys[0]] isEqual: @"foo"]) + + TEST(@"-[removeObjectForKey:]", + [dict removeObjectForKey: keys[0]] && + [dict objectForKey: keys[0]] == nil) + + [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 dictionary_tests(); extern void object_tests(); extern void string_tests(); static int fails = 0; @@ -85,8 +86,9 @@ int main() { object_tests(); string_tests(); + dictionary_tests(); return fails; }