Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -305,11 +305,11 @@ items = 0; buckets = 0; for (i = 0; i < size; i++) { if (data[i] != nil) { - items += [data[i] items] / 2; + items += [data[i] count] / 2; buckets++; } } return (float)items / buckets; Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -105,7 +105,7 @@ * Get the number of items in the list. Use with caution, as this means one * iteration through the whole list! * * \return The number of items in the list. */ -- (size_t)items; +- (size_t)count; @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -166,16 +166,35 @@ [self freeMem: listobj]; return self; } -- (size_t)items +- (size_t)count { size_t i; of_list_object_t *iter; for (i = 0, iter = first; iter != NULL; iter = iter->next) i++; return i; } + +- (BOOL)isEqual: (id)obj +{ + of_list_object_t *iter, *iter2; + + if (![obj isKindOf: [OFList class]]) + return NO; + + for (iter = first, iter2 = [obj first]; iter != NULL && iter2 != NULL; + iter = iter->next, iter2 = iter2->next) + if (![iter->object isEqual: iter2->object]) + return NO; + + /* One has still items */ + if (iter != NULL || iter2 != NULL) + return NO; + + return YES; +} @end Index: tests/OFList/OFList.m ================================================================== --- tests/OFList/OFList.m +++ tests/OFList/OFList.m @@ -21,11 +21,11 @@ #define ZD "%zd" #else #define ZD "%u" #endif -#define NUM_TESTS 11 +#define NUM_TESTS 14 #define SUCCESS \ { \ printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m", \ (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ fflush(stdout); \ @@ -43,54 +43,66 @@ else \ FAIL \ i++; \ } -const char *strings[] = { - "First String Object", - "Second String Object", - "Third String Object" +const OFString *strings[] = { + @"First String Object", + @"Second String Object", + @"Third String Object" }; int main() { size_t i, j; - OFList *list; + OFList *list, *list2; of_list_object_t *iter; list = [OFList list]; - [list append: [OFString stringWithCString: strings[0]]]; - [list append: [OFString stringWithCString: strings[1]]]; - [list append: [OFString stringWithCString: strings[2]]]; + [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 (!strcmp([iter->object cString], strings[i])) + if ([iter->object isEqual: strings[i]]) SUCCESS else FAIL - CHECK(!strcmp([[list first]->object cString], strings[0])) - CHECK(!strcmp([[list last]->object cString], strings[2])) + CHECK([[list first]->object isEqual: strings[0]]) + CHECK([[list last]->object isEqual: strings[2]]) [list remove: [list last]]; - CHECK(!strcmp([[list last]->object cString], strings[1])) + CHECK([[list last]->object isEqual: strings[1]]) [list remove: [list first]]; - CHECK(!strcmp([[list first]->object cString], - [[list last]->object cString])) + CHECK([[list first]->object isEqual: [list last]->object]) - [list insert: [OFString stringWithCString: strings[0]] + [list insert: strings[0] before: [list last]]; - [list insert: [OFString stringWithCString: strings[2]] + [list insert: strings[2] after: [list first]->next]; for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++) - CHECK(!strcmp([iter->object cString], strings[j])) + CHECK([iter->object isEqual: strings[j]]) + + CHECK([list count] == 3) + + 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]); - CHECK ([list items] == 3) + [list2 append: @"foo"]; + CHECK(![list2 isEqual: list]); puts(""); return 0; }