Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -229,6 +229,12 @@ - removeNObjects: (size_t)nobjects { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } + +/* FIXME: Implement! +- (uint32_t)hash +{ +} +*/ @end Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -279,6 +279,12 @@ - removeObjectForKey: (OFObject*)key { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } + +/* FIXME: Implement! +- (uint32_t)hash +{ +} +*/ @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -228,6 +228,12 @@ new->last = o; return new; } + +/* FIXME: Implement! +- (uint32_t)hash +{ +} +*/ @end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,10 +1,9 @@ include ../extra.mk -SUBDIRS = OFDataArray \ - OFHashes \ +SUBDIRS = OFHashes \ ${OFPLUGIN} \ OFThread \ OFXMLParser \ ${OBJC_SYNC} include ../buildsys.mk DELETED tests/OFDataArray/Makefile Index: tests/OFDataArray/Makefile ================================================================== --- tests/OFDataArray/Makefile +++ tests/OFDataArray/Makefile @@ -1,29 +0,0 @@ -PROG_NOINST = ofdataarray${PROG_SUFFIX} -SRCS = OFDataArray.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/OFDataArray/OFDataArray.m Index: tests/OFDataArray/OFDataArray.m ================================================================== --- tests/OFDataArray/OFDataArray.m +++ tests/OFDataArray/OFDataArray.m @@ -1,185 +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 -#include -#include - -#import "OFDataArray.h" -#import "OFAutoreleasePool.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..."); \ - } - -const char *str = "Hallo!"; - -#define TEST(type) \ - puts("Trying to add too much to an array..."); \ - a = [[type alloc] initWithItemSize: 4096]; \ - CATCH_EXCEPTION([a addNItems: SIZE_MAX \ - fromCArray: NULL], \ - OFOutOfRangeException) \ - \ - puts("Trying to add something after that error..."); \ - p = [a allocMemoryWithSize: 4096]; \ - memset(p, 255, 4096); \ - [a addItem: p]; \ - if (!memcmp([a lastItem], p, 4096)) \ - puts("[a lastItem] matches with p!"); \ - else { \ - puts("[a lastItem] does not match p!"); \ - abort(); \ - } \ - [a freeMemory: p]; \ - \ - puts("Adding more data..."); \ - q = [a allocMemoryWithSize: 4096]; \ - memset(q, 42, 4096); \ - [a addItem: q]; \ - if (!memcmp([a lastItem], q, 4096)) \ - puts("[a lastItem] matches with q!"); \ - else { \ - puts("[a lastItem] does not match q!"); \ - abort(); \ - } \ - [a freeMemory: q]; \ - \ - puts("Adding multiple items at once..."); \ - p = [a allocMemoryWithSize: 8192]; \ - memset(p, 64, 8192); \ - [a addNItems: 2 \ - fromCArray: p]; \ - if (!memcmp([a lastItem], [a itemAtIndex: [a count] - 2], 4096) && \ - !memcmp([a itemAtIndex: [a count] - 2], p, 4096)) \ - puts("[a lastItem], [a itemAtIndex: [a count] - 2] " \ - "and p match!"); \ - else { \ - puts("[a lastItem], [a itemAtIndex: [a count] - 2] " \ - "and p do not match!"); \ - abort(); \ - } \ - [a freeMemory: p]; \ - \ - i = [a count]; \ - puts("Removing 2 items..."); \ - [a removeNItems: 2]; \ - if ([a count] + 2 != i) { \ - puts("[a count] + 2 != i!"); \ - abort(); \ - } \ - \ - puts("Trying to remove more data than we added..."); \ - CATCH_EXCEPTION([a removeNItems: [a count] + 1], \ - OFOutOfRangeException); \ - \ - puts("Trying to access an index that does not exist..."); \ - CATCH_EXCEPTION([a itemAtIndex: [a count]], \ - OFOutOfRangeException); \ - \ - [a release]; \ - \ - puts("Creating new array and using it to build a string..."); \ - a = [[type alloc] initWithItemSize: 1]; \ - \ - for (i = 0; i < strlen(str); i++) \ - [a addItem: (void*)&str[i]]; \ - [a addItem: ""]; \ - \ - if (!strcmp([a data], str)) \ - puts("Built string matches!"); \ - else { \ - puts("Built string does not match!"); \ - abort(); \ - } \ - \ - [a release]; - -int -main() -{ - id a; - void *p, *q; - size_t i; - OFDataArray *x, *y; - OFAutoreleasePool *pool; - - puts("== TESTING OFDataArray =="); - TEST(OFDataArray) - - puts("== TESTING OFBigArray =="); - TEST(OFBigDataArray) - - pool = [[OFAutoreleasePool alloc] init]; - x = [OFDataArray dataArrayWithItemSize: 1]; - y = [OFBigDataArray dataArrayWithItemSize: 1]; - - if (![x isEqual: y]) { - puts("FAIL 1!"); - return 1; - } - - if ([x hash] != [y hash]) { - puts("FAIL 2!"); - return 1; - } - - [x addItem: "x"]; - if ([x isEqual: y]) { - puts("FAIL 3!"); - return 1; - } - [pool releaseObjects]; - - x = [OFDataArray dataArrayWithItemSize: 2]; - y = [OFBigDataArray dataArrayWithItemSize: 4]; - - if ([x isEqual: y]) { - puts("FAIL 4!"); - return 1; - } - [pool releaseObjects]; - - x = [OFDataArray dataArrayWithItemSize: 1]; - [x addNItems: 3 - fromCArray: "abc"]; - y = [x copy]; - if ([x compare: y]) { - puts("FAIL 5!"); - return 1; - } - - [y addItem: "de"]; - if ([x compare: y] != -100) { - puts("FAIL 6!"); - return 1; - } - - if ([y hash] != 0xCD8B6206) { - puts("FAIL 7!"); - return 1; - } - [pool release]; - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -1,7 +1,8 @@ PROG_NOINST = tests${PROG_SUFFIX} SRCS = array.m \ + dataarray.m \ dictionary.m \ list.m \ main.m \ object.m \ string.m \ Index: tests_new/array.m ================================================================== --- tests_new/array.m +++ tests_new/array.m @@ -60,9 +60,12 @@ 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]) + OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) + + EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", + OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1]) [pool release]; } ADDED tests_new/dataarray.m Index: tests_new/dataarray.m ================================================================== --- tests_new/dataarray.m +++ tests_new/dataarray.m @@ -0,0 +1,103 @@ +/* + * 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 + +#import "OFArray.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" + +#import "main.h" + +static OFString *module; +const char *str = "Hello!"; + +static void +do_tests(Class class) +{ + OFDataArray *array[2]; + void *data[2]; + Class other; + + TEST(@"+[dataArrayWithItemSize:]", + (array[0] = [class dataArrayWithItemSize: 4096])) + + data[0] = [array[0] allocMemoryWithSize: 4096]; + data[1] = [array[0] allocMemoryWithSize: 4096]; + memset(data[0], 0xFF, 4096); + memset(data[1], 0x42, 4096); + + TEST(@"-[addItem:]", [array[0] addItem: data[0]] && + [array[0] addItem: data[1]]) + + TEST(@"-[itemAtIndex:]", + !memcmp([array[0] itemAtIndex: 0], data[0], 4096) && + !memcmp([array[0] itemAtIndex: 1], data[1], 4096)) + + TEST(@"-[lastItem]", !memcmp([array[0] lastItem], data[1], 4096)) + + TEST(@"-[count]", [array[0] count] == 2) + + other = (class == [OFDataArray class] + ? [OFBigDataArray class] + : [OFDataArray class]); + TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) && + [array[1] addNItems: [array[0] count] + fromCArray: [array[0] data]] && + [array[1] isEqual: array[0]] && + [array[1] removeNItems: 1] && ![array[0] isEqual: array[1]]) + + TEST(@"-[copy]", (array[1] = [[array[0] copy] autorelease]) && + [array[0] isEqual: array[1]]) + + TEST(@"-[compare]", [array[0] compare: array[1]] == 0 && + [array[1] removeNItems: 1] && + [array[0] compare: array[1]] == 0x42 && + [array[1] compare: array[0]] == -0x42) + + TEST(@"-[hash]", [array[0] hash] == 0xC54621B6) + + TEST(@"-[removeNItems:]", [array[0] removeNItems: 1]) + + TEST(@"Building strings", + (array[0] = [class dataArrayWithItemSize: 1]) && + [array[0] addNItems: 6 + fromCArray: (void*)str] && [array[0] addItem: ""] && + !strcmp([array[0] data], str)) + + EXPECT_EXCEPTION(@"Detect out of range in -[itemAtIndex:]", + OFOutOfRangeException, [array[0] itemAtIndex: [array[0] count]]) + + EXPECT_EXCEPTION(@"Detect out of range in -[addNItems:fromCArray:]", + OFOutOfRangeException, [array[0] addNItems: SIZE_MAX + fromCArray: NULL]) + + EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", + OFOutOfRangeException, + [array[0] removeNItems: [array[0] count] + 1]) +} + +void +dataarray_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + module = @"OFDataArray"; + do_tests([OFDataArray class]); + + module = @"OFBigDataArray"; + do_tests([OFBigDataArray class]); + + [pool release]; +} Index: tests_new/main.m ================================================================== --- tests_new/main.m +++ tests_new/main.m @@ -18,10 +18,11 @@ #import "OFString.h" #import "OFAutoreleasePool.h" extern void array_tests(); +extern void dataarray_tests(); extern void dictionary_tests(); extern void list_tests(); extern void object_tests(); extern void string_tests(); extern void tcpsocket_tests(); @@ -90,13 +91,14 @@ int main() { object_tests(); string_tests(); + dataarray_tests(); array_tests(); dictionary_tests(); list_tests(); tcpsocket_tests(); xmlelement_tests(); return fails; }