aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorDániel Bakai <daniel.bakai@tresorit.com>2017-04-03 09:16:21 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-04-04 23:48:14 +0200
commit6193770ee1f6771758a653730e7a1ecaf2cf9dc8 (patch)
treee895a90a47ecb50d2e2836040d17af33f29c14da /tests/unit
parentde05bcb706243546d37047439dabc4e73054cfef (diff)
tests: added test for Curl_splaygetbest to unit1309
This checks the new behavior of Curl_splaygetbest, so that the smallest node not larger than the key is removed, and FIFO behavior is kept even when there are multiple nodes with the same key. Closes #1358
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unit1309.c38
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