Release all memory in tests and fix comment
This commit is contained in:
parent
3d0b652ec9
commit
c0ee55325c
|
@ -732,7 +732,8 @@ int main(int argc, char** argv)
|
||||||
exotic_add_test(&handle, &exotic_test_rbtree_size_4, "rbtree_size_4");
|
exotic_add_test(&handle, &exotic_test_rbtree_size_4, "rbtree_size_4");
|
||||||
exotic_add_test(&handle, &exotic_test_rbtree_check_10000, "rbtree_check_10000");
|
exotic_add_test(&handle, &exotic_test_rbtree_check_10000, "rbtree_check_10000");
|
||||||
exotic_add_test(&handle, &exotic_test_rbtree_iterate_10000, "rbtree_iterate_10000");
|
exotic_add_test(&handle, &exotic_test_rbtree_iterate_10000, "rbtree_iterate_10000");
|
||||||
exotic_add_test(&handle, &exotic_test_rbtree_remove_5000, "rbtree_remove_5000");
|
exotic_add_test(&handle, &exotic_test_rbtree_remove_10000, "rbtree_remove_10000");
|
||||||
|
exotic_add_test(&handle, &exotic_test_rbtree_destroy_1, "rbtree_destroy_1");
|
||||||
exotic_add_test(&handle, &exotic_test_sid_create_pool, "sid_create_pool");
|
exotic_add_test(&handle, &exotic_test_sid_create_pool, "sid_create_pool");
|
||||||
exotic_add_test(&handle, &exotic_test_sid_check_0a, "sid_check_0a");
|
exotic_add_test(&handle, &exotic_test_sid_check_0a, "sid_check_0a");
|
||||||
exotic_add_test(&handle, &exotic_test_sid_check_0b, "sid_check_0b");
|
exotic_add_test(&handle, &exotic_test_sid_check_0b, "sid_check_0b");
|
||||||
|
@ -770,6 +771,7 @@ int main(int argc, char** argv)
|
||||||
exotic_add_test(&handle, &exotic_test_timer_add_5_events_1, "timer_add_5_events_1");
|
exotic_add_test(&handle, &exotic_test_timer_add_5_events_1, "timer_add_5_events_1");
|
||||||
exotic_add_test(&handle, &exotic_test_timer_check_5_events_1, "timer_check_5_events_1");
|
exotic_add_test(&handle, &exotic_test_timer_check_5_events_1, "timer_check_5_events_1");
|
||||||
exotic_add_test(&handle, &exotic_test_timer_process_5_events_1, "timer_process_5_events_1");
|
exotic_add_test(&handle, &exotic_test_timer_process_5_events_1, "timer_process_5_events_1");
|
||||||
|
exotic_add_test(&handle, &exotic_test_timer_shutdown, "timer_shutdown");
|
||||||
exotic_add_test(&handle, &exotic_test_tokenizer_basic_0, "tokenizer_basic_0");
|
exotic_add_test(&handle, &exotic_test_tokenizer_basic_0, "tokenizer_basic_0");
|
||||||
exotic_add_test(&handle, &exotic_test_tokenizer_basic_1, "tokenizer_basic_1");
|
exotic_add_test(&handle, &exotic_test_tokenizer_basic_1, "tokenizer_basic_1");
|
||||||
exotic_add_test(&handle, &exotic_test_tokenizer_basic_1a, "tokenizer_basic_1a");
|
exotic_add_test(&handle, &exotic_test_tokenizer_basic_1a, "tokenizer_basic_1a");
|
||||||
|
|
|
@ -86,7 +86,7 @@ EXO_TEST(rbtree_size_3, { return rb_tree_size(tree) == 0; });
|
||||||
|
|
||||||
EXO_TEST(rbtree_insert_10000, {
|
EXO_TEST(rbtree_insert_10000, {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAX_NODES ; i++)
|
for (i = 0; i < MAX_NODES; i++)
|
||||||
{
|
{
|
||||||
const char* key = strdup(uhub_itoa(i));
|
const char* key = strdup(uhub_itoa(i));
|
||||||
const char* val = strdup(uhub_itoa(i + 16384));
|
const char* val = strdup(uhub_itoa(i + 16384));
|
||||||
|
@ -96,11 +96,11 @@ EXO_TEST(rbtree_insert_10000, {
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
EXO_TEST(rbtree_size_4, { return rb_tree_size(tree) == MAX_NODES ; });
|
EXO_TEST(rbtree_size_4, { return rb_tree_size(tree) == MAX_NODES; });
|
||||||
|
|
||||||
EXO_TEST(rbtree_check_10000, {
|
EXO_TEST(rbtree_check_10000, {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAX_NODES ; i++)
|
for (i = 0; i < MAX_NODES; i++)
|
||||||
{
|
{
|
||||||
char* key = strdup(uhub_itoa(i));
|
char* key = strdup(uhub_itoa(i));
|
||||||
const char* expect = uhub_itoa(i + 16384);
|
const char* expect = uhub_itoa(i + 16384);
|
||||||
|
@ -119,24 +119,32 @@ EXO_TEST(rbtree_iterate_10000, {
|
||||||
n = (struct rb_node*) rb_tree_next(tree);
|
n = (struct rb_node*) rb_tree_next(tree);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return i == MAX_NODES ;
|
return i == MAX_NODES;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static int freed_nodes = 0;
|
||||||
static void free_node(struct rb_node* n)
|
static void free_node(struct rb_node* n)
|
||||||
{
|
{
|
||||||
hub_free((void*) n->key);
|
hub_free((void*) n->key);
|
||||||
hub_free((void*) n->value);
|
hub_free((void*) n->value);
|
||||||
|
freed_nodes += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
EXO_TEST(rbtree_remove_5000, {
|
EXO_TEST(rbtree_remove_10000, {
|
||||||
int i = 0;
|
int i;
|
||||||
for (i = 0; i < MAX_NODES ; i += 2)
|
int j;
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
{
|
||||||
|
for (i = j; i < MAX_NODES; i += 2)
|
||||||
{
|
{
|
||||||
const char* key = uhub_itoa(i);
|
const char* key = uhub_itoa(i);
|
||||||
rb_tree_remove_node(tree, key, &free_node);
|
rb_tree_remove_node(tree, key, &free_node);
|
||||||
}
|
}
|
||||||
return 1;
|
}
|
||||||
|
return freed_nodes == MAX_NODES;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EXO_TEST(rbtree_destroy_1, {
|
||||||
|
rb_tree_destroy(tree);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
|
@ -117,3 +117,9 @@ EXO_TEST(timer_process_5_events_1,{
|
||||||
g_now = 4;
|
g_now = 4;
|
||||||
return timeout_queue_process(g_queue, g_now) == g_triggered;
|
return timeout_queue_process(g_queue, g_now) == g_triggered;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EXO_TEST(timer_shutdown,{
|
||||||
|
timeout_queue_shutdown(g_queue);
|
||||||
|
hub_free(g_queue);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
|
@ -62,8 +62,8 @@ struct rb_tree
|
||||||
extern struct rb_tree* rb_tree_create(rb_tree_compare compare, rb_tree_alloc alloc, rb_tree_free dealloc);
|
extern struct rb_tree* rb_tree_create(rb_tree_compare compare, rb_tree_alloc alloc, rb_tree_free dealloc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the tree and all the nodes.
|
* Delete the tree.
|
||||||
* But not the content inside the nodes.
|
* Assumes that the tree is empty.
|
||||||
*/
|
*/
|
||||||
extern void rb_tree_destroy(struct rb_tree*);
|
extern void rb_tree_destroy(struct rb_tree*);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue