diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/unit1309.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c index b75b1d74b..6cf886e9e 100644 --- a/tests/unit/unit1309.c +++ b/tests/unit/unit1309.c @@ -70,12 +70,14 @@ UNITTEST_START /* number of nodes to add to the splay tree */ #define NUM_NODES 50 - struct Curl_tree *root; - struct Curl_tree nodes[NUM_NODES]; + struct Curl_tree *root, *removed; + struct Curl_tree nodes[NUM_NODES*3]; int rc; - int i; + int i, j; + struct timeval tv_now = {0, 0}; root = NULL; /* the empty tree */ + /* add nodes */ for(i = 0; i < NUM_NODES; i++) { struct timeval key; @@ -103,6 +105,36 @@ UNITTEST_START } } + fail_unless(root == NULL, "tree not empty after removing all nodes"); + + /* rebuild tree */ + for(i = 0; i < NUM_NODES; i++) { + struct timeval key; + + key.tv_sec = 0; + key.tv_usec = (541*i)%1023; + + /* add some nodes with the same key */ + for(j = 0; j <= i % 3; j++) { + nodes[i*3+j].payload = (void *)(key.tv_usec*10 + j); /* for simplicity */ + root = Curl_splayinsert(key, root, &nodes[i*3+j]); + } + } + + removed = NULL; + for(i = 0; i <= 1100; i+= 100) { + printf("Removing nodes not larger than %d\n", i); + tv_now.tv_usec = i; + root = Curl_splaygetbest(tv_now, root, &removed); + while(removed != NULL) { + printf("removed payload %ld[%ld]\n", (long)(removed->payload) / 10, + (long)(removed->payload) % 10); + root = Curl_splaygetbest(tv_now, root, &removed); + } + } + + fail_unless(root == NULL, "tree not empty when it should be"); + UNITTEST_STOP |