diff options
Diffstat (limited to 'tests/nghttp2_map_test.c')
-rw-r--r-- | tests/nghttp2_map_test.c | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/tests/nghttp2_map_test.c b/tests/nghttp2_map_test.c index 7ba9bd6..3b79b8a 100644 --- a/tests/nghttp2_map_test.c +++ b/tests/nghttp2_map_test.c @@ -27,10 +27,22 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_map.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_map), + munit_void_test(test_nghttp2_map_functional), + munit_void_test(test_nghttp2_map_each_free), + munit_void_test(test_nghttp2_map_clear), + munit_test_end(), +}; + +const MunitSuite map_suite = { + "/map", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct strentry { nghttp2_map_key_type key; const char *str; @@ -53,43 +65,43 @@ void test_nghttp2_map(void) { strentry_init(&baz, 3, "baz"); strentry_init(&shrubbery, 4, "shrubbery"); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); - CU_ASSERT(1 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); + assert_size(1, ==, nghttp2_map_size(&map)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_map_insert(&map, FOO.key, &FOO)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_map_insert(&map, FOO.key, &FOO)); - CU_ASSERT(1 == nghttp2_map_size(&map)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); + assert_size(1, ==, nghttp2_map_size(&map)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); - CU_ASSERT(0 == nghttp2_map_insert(&map, bar.key, &bar)); - CU_ASSERT(2 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, bar.key, &bar)); + assert_size(2, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, baz.key, &baz)); - CU_ASSERT(3 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, baz.key, &baz)); + assert_size(3, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); - CU_ASSERT(4 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); + assert_size(4, ==, nghttp2_map_size(&map)); - CU_ASSERT(strcmp("baz", ((strentry *)nghttp2_map_find(&map, 3))->str) == 0); + assert_string_equal("baz", ((strentry *)nghttp2_map_find(&map, 3))->str); nghttp2_map_remove(&map, 3); - CU_ASSERT(3 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 3)); + assert_size(3, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 3)); nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); /* Erasing non-existent entry */ nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); - CU_ASSERT(strcmp("bar", ((strentry *)nghttp2_map_find(&map, 2))->str) == 0); - CU_ASSERT(strcmp("shrubbery", ((strentry *)nghttp2_map_find(&map, 4))->str) == - 0); + assert_string_equal("bar", ((strentry *)nghttp2_map_find(&map, 2))->str); + assert_string_equal("shrubbery", + ((strentry *)nghttp2_map_find(&map, 4))->str); nghttp2_map_free(&map); } @@ -129,21 +141,21 @@ void test_nghttp2_map_functional(void) { shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { ent = &arr[order[i] - 1]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } - CU_ASSERT(NUM_ENT == nghttp2_map_size(&map)); + assert_size(NUM_ENT, ==, nghttp2_map_size(&map)); /* traverse */ nghttp2_map_each(&map, eachfun, NULL); /* find */ shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(NULL != nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); + assert_not_null(nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); } /* remove */ for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); + assert_int(0, ==, nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); } /* each_free (but no op function for testing purpose) */ @@ -153,7 +165,7 @@ void test_nghttp2_map_functional(void) { /* insert once again */ for (i = 0; i < NUM_ENT; ++i) { ent = &arr[i]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } nghttp2_map_each_free(&map, eachfun, NULL); nghttp2_map_free(&map); @@ -198,11 +210,11 @@ void test_nghttp2_map_clear(void) { nghttp2_map_init(&map, mem); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); nghttp2_map_clear(&map); - CU_ASSERT(0 == nghttp2_map_size(&map)); + assert_size(0, ==, nghttp2_map_size(&map)); nghttp2_map_free(&map); } |