From: Alberto Leiva Popper Date: Mon, 3 Jun 2019 22:44:58 +0000 (-0500) Subject: Update unit tests X-Git-Tag: v0.0.2~12^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47ac8bbe059ecfc2f410e867433de3880684b2c4;p=thirdparty%2FFORT-validator.git Update unit tests --- diff --git a/src/rtr/db/roa_table.c b/src/rtr/db/roa_table.c index 1f738a45..47b83742 100644 --- a/src/rtr/db/roa_table.c +++ b/src/rtr/db/roa_table.c @@ -110,7 +110,7 @@ duplicate_roa(struct roa_table *dst, struct hashable_roa *new) return pr_crit("Unknown address family: %d", vrp.addr_fam); } -static int +int roa_table_merge(struct roa_table *dst, struct roa_table *src) { struct hashable_roa *node, *tmp, *found; diff --git a/src/rtr/db/roa_table.h b/src/rtr/db/roa_table.h index 73648756..f9776396 100644 --- a/src/rtr/db/roa_table.h +++ b/src/rtr/db/roa_table.h @@ -8,6 +8,8 @@ struct roa_table; struct roa_table *roa_table_create(void); void roa_table_destroy(struct roa_table *); + +int roa_table_merge(struct roa_table *, struct roa_table *); int roa_table_clone(struct roa_table **, struct roa_table *); int roa_table_foreach_roa(struct roa_table *, vrp_foreach_cb, void *); diff --git a/test/impersonator.c b/test/impersonator.c index b8e0149e..aaaecdfc 100644 --- a/test/impersonator.c +++ b/test/impersonator.c @@ -82,3 +82,8 @@ incidence_get_action(enum incidence_id id) { return INAC_ERROR; } + +void print_stack_trace(void) +{ + /* Nothing needed here */ +} diff --git a/test/rsync_test.c b/test/rsync_test.c index 21bbd5e7..aaa8aa4a 100644 --- a/test/rsync_test.c +++ b/test/rsync_test.c @@ -15,58 +15,56 @@ END_TEST static void assert_descendant(bool expected, char *ancestor, char *descendant) { - struct uri ancestor_uri; - struct rpki_uri descendant_uri; + struct rpki_uri *ancestor_uri; + struct rpki_uri *descendant_uri; - ancestor_uri.string = ancestor; - ancestor_uri.len = strlen(ancestor); - descendant_uri.global = descendant; - descendant_uri.global_len = strlen(descendant); + ck_assert_int_eq(0, uri_create_str(&ancestor_uri, ancestor, + strlen(ancestor))); + ck_assert_int_eq(0, uri_create_str(&descendant_uri, descendant, + strlen(descendant))); - ck_assert_int_eq(is_descendant(&ancestor_uri, &descendant_uri), - expected); + ck_assert_int_eq(is_descendant(ancestor_uri, descendant_uri), expected); + + uri_refput(ancestor_uri); + uri_refput(descendant_uri); } START_TEST(rsync_test_prefix_equals) { char *ancestor; - ancestor = "proto://a/b/c"; - assert_descendant(true, ancestor, "proto://a/b/c"); - assert_descendant(false, ancestor, "proto://a/b/"); - assert_descendant(true, ancestor, "proto://a/b/c/c"); - assert_descendant(false, ancestor, "proto://a/b/cc"); - assert_descendant(false, ancestor, "proto://a/b/cc/"); - - ancestor = "proto://a/b/c/"; - assert_descendant(true, ancestor, "proto://a/b/c"); - assert_descendant(false, ancestor, "proto://a/b/"); - assert_descendant(true, ancestor, "proto://a/b/c/c"); - assert_descendant(false, ancestor, "proto://a/b/cc"); - assert_descendant(false, ancestor, "proto://a/b/cc/"); + ancestor = "rsync://a/b/c"; + assert_descendant(true, ancestor, "rsync://a/b/c"); + assert_descendant(false, ancestor, "rsync://a/b/"); + assert_descendant(true, ancestor, "rsync://a/b/c/c"); + assert_descendant(false, ancestor, "rsync://a/b/cc"); + assert_descendant(false, ancestor, "rsync://a/b/cc/"); + + ancestor = "rsync://a/b/c/"; + assert_descendant(true, ancestor, "rsync://a/b/c"); + assert_descendant(false, ancestor, "rsync://a/b/"); + assert_descendant(true, ancestor, "rsync://a/b/c/c"); + assert_descendant(false, ancestor, "rsync://a/b/cc"); + assert_descendant(false, ancestor, "rsync://a/b/cc/"); } END_TEST static void __mark_as_downloaded(char *uri_str) { - struct rpki_uri uri; - - uri.global = uri_str; - uri.global_len = strlen(uri_str); - - ck_assert_int_eq(mark_as_downloaded(&uri), 0); + struct rpki_uri *uri; + ck_assert_int_eq(0, uri_create_str(&uri, uri_str, strlen(uri_str))); + ck_assert_int_eq(mark_as_downloaded(uri), 0); + uri_refput(uri); } static void assert_downloaded(char *uri_str, bool expected) { - struct rpki_uri uri; - - uri.global = uri_str; - uri.global_len = strlen(uri_str); - - ck_assert_int_eq(is_already_downloaded(&uri), expected); + struct rpki_uri *uri; + ck_assert_int_eq(0, uri_create_str(&uri, uri_str, strlen(uri_str))); + ck_assert_int_eq(is_already_downloaded(uri), expected); + uri_refput(uri); } START_TEST(rsync_test_list) @@ -100,24 +98,15 @@ END_TEST static void test_root_strategy(char *test, char *expected) { - struct rpki_uri src; - struct rpki_uri dst; - - src.global = strdup(test); - if (src.global == NULL) - ck_abort_msg("Out of memory."); - src.global_len = strlen(test); - src.local = strdup("foo"); - if (src.local == NULL) - ck_abort_msg("Out of memory."); - - ck_assert_int_eq(handle_root_strategy(&src, &dst), 0); - ck_assert_str_eq(dst.global, expected); - - free(src.global); - free(src.local); - free(dst.global); - free(dst.local); + struct rpki_uri *src; + struct rpki_uri *dst; + + ck_assert_int_eq(0, uri_create_str(&src, test, strlen(test))); + ck_assert_int_eq(handle_root_strategy(src, &dst), 0); + ck_assert_str_eq(uri_get_global(dst), expected); + + uri_refput(src); + uri_refput(dst); } START_TEST(rsync_test_get_prefix) @@ -134,10 +123,6 @@ START_TEST(rsync_test_get_prefix) "rsync://www.example1.com"); test_root_strategy("rsync://w", "rsync://w"); test_root_strategy("rsync://", "rsync://"); - test_root_strategy("rsync:/", "rsync:/"); - test_root_strategy("rsync:", "rsync:"); - test_root_strategy("r", "r"); - test_root_strategy("", ""); } END_TEST diff --git a/test/rtr/db/impersonator.c b/test/rtr/db/impersonator.c index 5ea4cbf4..ba3527cf 100644 --- a/test/rtr/db/impersonator.c +++ b/test/rtr/db/impersonator.c @@ -27,8 +27,6 @@ add_v6(struct validation_handler *handler, uint32_t as) int perform_standalone_validation(struct validation_handler *handler) { - ck_assert_int_eq(0, handler->reset(handler->arg)); - switch (iteration) { case 0: add_v4(handler, 0); @@ -49,8 +47,6 @@ perform_standalone_validation(struct validation_handler *handler) ck_abort_msg("perform_standalone_validation() was called too many times (%d).", iteration); } - if (handler->merge != NULL) - handler->merge(handler->merge_arg, handler->arg); iteration++; return 0; diff --git a/test/rtr/db/roa_table_test.c b/test/rtr/db/roa_table_test.c index 42e6728f..5b3901fa 100644 --- a/test/rtr/db/roa_table_test.c +++ b/test/rtr/db/roa_table_test.c @@ -225,8 +225,8 @@ START_TEST(test_merge) right_count++; /** Do the merge */ - ck_assert_int_eq(0, rtrhandler_merge(merged, left)); - ck_assert_int_eq(0, rtrhandler_merge(merged, right)); + ck_assert_int_eq(0, roa_table_merge(merged, left)); + ck_assert_int_eq(0, roa_table_merge(merged, right)); /** * Must have: