skiplist/tests/api.c

197 lines
4.2 KiB
C
Raw Permalink Normal View History

2024-03-15 18:40:01 +00:00
static void *
test_api_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
struct test_info *info = (struct test_info *)user_data;
(void)info;
(void)params;
2024-03-15 18:40:01 +00:00
2024-03-19 01:19:26 +00:00
ex_sl_t *slist = calloc(sizeof(ex_sl_t), 1);
if (slist == NULL)
return NULL;
sl_init(slist, uint32_key_cmp);
return (void *)(uintptr_t)slist;
2024-03-15 18:40:01 +00:00
}
static void
test_api_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
ex_sl_t *slist = (ex_sl_t *)fixture;
assert_ptr_not_null(slist);
sl_node *cursor = sl_begin(slist);
while (cursor) {
assert_ptr_not_null(cursor);
ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode);
assert_ptr_not_null(entry);
assert_uint32(entry->key, ==, entry->value);
cursor = sl_next(slist, cursor);
sl_erase_node(slist, &entry->snode);
sl_release_node(&entry->snode);
sl_wait_for_free(&entry->snode);
sl_free_node(&entry->snode);
free(entry);
}
sl_free(slist);
free(fixture);
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_insert_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_insert_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_insert(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
assert_ptr_not_null(data);
int n = munit_rand_int_range(128, 4096);
int key = munit_rand_int_range(0, (((uint32_t)0) - 1) / 10);
while (n--) {
ex_node_t *node = (ex_node_t *)calloc(sizeof(ex_node_t), 1);
sl_init_node(&node->snode);
node->key = key;
node->value = key;
sl_insert(slist, &node->snode);
}
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_remove_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_remove_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_remove(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_find_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_find_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_find(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_update_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_update_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_update(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_delete_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_delete_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_delete(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_duplicates_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_duplicates_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_duplicates(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_size_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_size_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_size(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}
static void *
2024-03-15 20:24:08 +00:00
test_api_iterators_setup(const MunitParameter params[], void *user_data)
{
2024-03-19 01:19:26 +00:00
return test_api_setup(params, user_data);
2024-03-15 18:40:01 +00:00
}
static void
2024-03-15 20:24:08 +00:00
test_api_iterators_tear_down(void *fixture)
{
2024-03-19 01:19:26 +00:00
test_api_tear_down(fixture);
2024-03-15 18:40:01 +00:00
}
static MunitResult
test_api_iterators(const MunitParameter params[], void *data)
{
2024-03-19 01:19:26 +00:00
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
2024-03-15 18:40:01 +00:00
}