Example #1
0
END_TEST

START_TEST (stress)
{
    ret_t       ret;
    chula_avl_t avl;
    int         pi[] = {3, 14, 15, 92, 65, 35, 89, 79, 32, 38, 46, 26, 43, 38, 32, 79, 50};

    ret = chula_avl_init (&avl);
    ch_assert (ret == ret_ok);

    /* Add */
    for (int i=0; i<16; i++) {
        char tmp[10];
        snprintf (tmp, 10, "%d", pi[i]);
        chula_avl_add_ptr (&avl, tmp, NULL);
    }

    /* Remove */
    for (int i=15; i>=0; i--) {
        char tmp[10];
        snprintf (tmp, 10, "%d", pi[i]);
        chula_avl_del_ptr (&avl, tmp, NULL);
    }

    ret = chula_avl_mrproper (AVL_GENERIC(&avl), fake_free);
    ch_assert (ret == ret_ok);
}
Example #2
0
END_TEST

START_TEST (_buf)
{
    ret_t           ret;
    void           *p;
    chula_avl_t     avl;
    chula_buffer_t  uno  = CHULA_BUF_INIT;
    chula_buffer_t  dos  = CHULA_BUF_INIT;
    chula_buffer_t  tres = CHULA_BUF_INIT;

    chula_avl_init (&avl);
    chula_buffer_add_str (&uno,  "uno");
    chula_buffer_add_str (&dos,  "dos");
    chula_buffer_add_str (&tres, "tres");

    ret = chula_avl_add (&avl, &uno, INT_TO_POINTER(1));
    ch_assert (ret == ret_ok);
    ret = chula_avl_add (&avl, &dos, INT_TO_POINTER(2));
    ch_assert (ret == ret_ok);
    ret = chula_avl_add (&avl, &tres, INT_TO_POINTER(3));
    ch_assert (ret == ret_ok);

    chula_avl_get (&avl, &dos, &p);
    ch_assert (POINTER_TO_INT(p) == 2);
    chula_avl_get (&avl, &tres, &p);
    ch_assert (POINTER_TO_INT(p) == 3);
    chula_avl_get (&avl, &uno, &p);
    ch_assert (POINTER_TO_INT(p) == 1);

    chula_avl_del (&avl, &dos, NULL);
    chula_avl_get (&avl, &uno, &p);
    ch_assert (POINTER_TO_INT(p) == 1);

    p = NULL;
    ret = chula_avl_get (&avl, &dos, &p);
    ch_assert (ret != ret_ok);
    ch_assert (p == NULL);

    ret = chula_avl_check (AVL_GENERIC(&avl));
    ch_assert (ret == ret_ok);

    chula_buffer_mrproper (&uno);
    chula_buffer_mrproper (&dos);
    chula_buffer_mrproper (&tres);
    chula_avl_mrproper (AVL_GENERIC(&avl), NULL);
}
ret_t
cherokee_resolv_cache_mrproper (cherokee_resolv_cache_t *resolv)
{
	cherokee_avl_mrproper (AVL_GENERIC(&resolv->table), entry_free);
	CHEROKEE_RWLOCK_DESTROY (&resolv->lock);

	return ret_ok;
}
Example #4
0
static ret_t
_free (void *p)
{
	cherokee_rule_extensions_t *rule = RULE_EXTENSIONS(p);

	cherokee_avl_mrproper (AVL_GENERIC(&rule->extensions), NULL);
	return ret_ok;
}
Example #5
0
END_TEST

START_TEST (len)
{
    ret_t       ret;
    size_t      len;
    chula_avl_t avl;

    /* None */
    chula_avl_init (&avl);
    ch_assert (chula_avl_is_empty (AVL_GENERIC(&avl)));

    ret = chula_avl_len (AVL_GENERIC(&avl), &len);
    ch_assert (ret == ret_ok);
    ch_assert (len == 0);

    /* Single */
    chula_avl_add_ptr (&avl, "uno", INT_TO_POINTER(1));
    ch_assert (ret == ret_ok);
    ch_assert (! chula_avl_is_empty (AVL_GENERIC(&avl)));

    chula_avl_len (AVL_GENERIC(&avl), &len);
    ch_assert (len == 1);

    /* Multiple */
    chula_avl_add_ptr (&avl, "dos", INT_TO_POINTER(2));
    ch_assert (ret == ret_ok);
    ch_assert (! chula_avl_is_empty (AVL_GENERIC(&avl)));

    chula_avl_len (AVL_GENERIC(&avl), &len);
    ch_assert (len == 2);

    chula_avl_mrproper (AVL_GENERIC(&avl), NULL);
}
ret_t
cherokee_resolv_cache_clean (cherokee_resolv_cache_t *resolv)
{
	CHEROKEE_RWLOCK_WRITER (&resolv->lock);
	cherokee_avl_mrproper (AVL_GENERIC(&resolv->table), entry_free);
	CHEROKEE_RWLOCK_UNLOCK (&resolv->lock);

	return ret_ok;
}
Example #7
0
ret_t
http2d_plugin_loader_mrproper (http2d_plugin_loader_t *loader)
{
	http2d_buffer_mrproper (&loader->module_dir);
	http2d_buffer_mrproper (&loader->deps_dir);

	http2d_avl_mrproper (AVL_GENERIC(&loader->table), free_entry);
	return ret_ok;
}
Example #8
0
ret_t
cherokee_regex_table_free (cherokee_regex_table_t *table)
{
	CHEROKEE_RWLOCK_DESTROY (&table->rwlock);

	cherokee_avl_mrproper (AVL_GENERIC(&table->cache), free);

	free(table);
	return ret_ok;
}
Example #9
0
END_TEST

START_TEST (_ptr)
{
    ret_t        ret;
    void        *p;
    chula_avl_t  avl;

    chula_avl_init (&avl);

    ret = chula_avl_add_ptr (&avl, "uno", INT_TO_POINTER(1));
    ch_assert (ret == ret_ok);
    ret = chula_avl_add_ptr (&avl, "dos", INT_TO_POINTER(2));
    ch_assert (ret == ret_ok);
    ret = chula_avl_add_ptr (&avl, "tres", INT_TO_POINTER(3));
    ch_assert (ret == ret_ok);

    chula_avl_get_ptr (&avl, "dos", &p);
    ch_assert (POINTER_TO_INT(p) == 2);
    chula_avl_get_ptr (&avl, "tres", &p);
    ch_assert (POINTER_TO_INT(p) == 3);
    chula_avl_get_ptr (&avl, "uno", &p);
    ch_assert (POINTER_TO_INT(p) == 1);

    chula_avl_set_case (&avl, true);
    chula_avl_get_ptr (&avl, "TrEs", &p);
    ch_assert (POINTER_TO_INT(p) == 3);
    chula_avl_set_case (&avl, false);

    chula_avl_del_ptr (&avl, "dos", NULL);
    chula_avl_get_ptr (&avl, "uno", &p);
    ch_assert (POINTER_TO_INT(p) == 1);

    p = NULL;
    ret = chula_avl_get_ptr (&avl, "dos", &p);
    ch_assert (ret != ret_ok);
    ch_assert (p == NULL);

    ret = chula_avl_check (AVL_GENERIC(&avl));
    ch_assert (ret == ret_ok);

    chula_avl_mrproper (AVL_GENERIC(&avl), NULL);
}
Example #10
0
END_TEST

START_TEST (empty)
{
    ret_t       ret;
    chula_avl_t avl;

    ret = chula_avl_init (&avl);
    ch_assert (ret == ret_ok);

    chula_avl_mrproper (AVL_GENERIC(&avl), NULL);
}
Example #11
0
END_TEST

START_TEST (mrproper)
{
    ret_t       ret;
    chula_avl_t avl;

    chula_avl_init (&avl);

    for (int i=0; i<16; i++) {
        char tmp[3];
        snprintf (tmp, 3, "%d", i);
        chula_avl_add_ptr (&avl, tmp, NULL);
    }

    ret = chula_avl_mrproper (AVL_GENERIC(&avl), fake_free);
    ch_assert (ret == ret_ok);
}