]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Update unit tests
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 3 Jun 2019 22:44:58 +0000 (17:44 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 3 Jun 2019 22:49:06 +0000 (17:49 -0500)
src/rtr/db/roa_table.c
src/rtr/db/roa_table.h
test/impersonator.c
test/rsync_test.c
test/rtr/db/impersonator.c
test/rtr/db/roa_table_test.c

index 1f738a45427b849125b9710644b7e3e32bd35caf..47b83742a7e24b7bbbf34da516b3d4c5096971f0 100644 (file)
@@ -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;
index 73648756d3a72dd2c3b2aed09e21ce396c05dfb1..f9776396e3afeda68744117d0c318fd244d7d309 100644 (file)
@@ -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 *);
index b8e0149e2ea220457c9c4fa662470db4e92b5390..aaaecdfc1e3d1607b9b0787de85fb88a28291083 100644 (file)
@@ -82,3 +82,8 @@ incidence_get_action(enum incidence_id id)
 {
        return INAC_ERROR;
 }
+
+void print_stack_trace(void)
+{
+       /* Nothing needed here */
+}
index 21bbd5e7b854bb7e097c73e123f944d58049baa6..aaa8aa4aab4dcf44861e1d61fd2877a77cd5a345 100644 (file)
@@ -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
 
index 5ea4cbf4f11a890203dfd476205a0a1bfa6100f3..ba3527cf824d525eeaec8f6060214b75d75ae55b 100644 (file)
@@ -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;
index 42e6728f9c98fa488b7f65974b68f237f2bffecc..5b3901fa436c3295a793fc14e37af77faadf24ee 100644 (file)
@@ -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: