Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -98,6 +98,14 @@ * Removes an object from the list. * * \param listobj The list object returned by append / prepend */ - remove: (of_list_object_t*)listobj; + +/** + * 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; @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -166,6 +166,17 @@ [self freeMem: listobj]; return self; } + +- (size_t)items +{ + size_t i; + of_list_object_t *iter; + + for (i = 0, iter = first; iter != NULL; iter = iter->next) + i++; + + return i; +} @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 10 +#define NUM_TESTS 11 #define SUCCESS \ { \ printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m", \ (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ fflush(stdout); \ @@ -85,10 +85,12 @@ [list insert: [OFString stringWithCString: 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 ([list items] == 3) puts(""); return 0; }