From 4c1a09d0cf7b87c47b1edb0cdce9afd59f7484d8 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 11 Jan 2009 04:43:53 +0000 Subject: [PATCH] Added a test that exposes a problem in BObjectList/PointerList. If a list contains 17 items or greater, and you attempt to sort it with a sort function that always returns 1 regardless of the items being compared, it will crash 100% of the time. Looking into why next. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28873 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../pointerlist/PointerListSortTest.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/tests/kits/support/pointerlist/PointerListSortTest.cpp diff --git a/src/tests/kits/support/pointerlist/PointerListSortTest.cpp b/src/tests/kits/support/pointerlist/PointerListSortTest.cpp new file mode 100644 index 0000000000..754fe9a1fe --- /dev/null +++ b/src/tests/kits/support/pointerlist/PointerListSortTest.cpp @@ -0,0 +1,35 @@ +#include +#include + +static int SortItemTestPositive(const BString *item1, const BString *item2) +{ + return 1; +} + +static int SortItemTestNegative(const BString *item1, const BString *item2) +{ + return -1; +} + +static int SortItemTestEqual(const BString *item1, const BString *item2) +{ + return 0; +} + +int main(int, char **) +{ + BObjectList list; + for (int i = 0; i < 20; i++) { + list.AddItem(new BString("test")); + printf("List contains %d items, attempting sorts\n", i); + printf("Attempting positive test\n"); + list.SortItems(SortItemTestPositive); + printf("Positive test completed, attempting negative test\n"); + list.SortItems(SortItemTestNegative); + printf("Positive test completed, attempting equal test\n"); + list.SortItems(SortItemTestEqual); + } + printf("All tests passed!\n"); + + return 0; +}