refactoring testcase group

This commit is contained in:
c9s 2015-11-17 15:36:29 +08:00
parent b70c239b2c
commit 2f3bcb7116

View file

@ -258,7 +258,7 @@ START_TEST (test_compile)
r3_tree_insert_path(n, "/{id}", NULL); r3_tree_insert_path(n, "/{id}", NULL);
r3_tree_compile(n, NULL); r3_tree_compile(n, NULL);
r3_tree_compile(n, NULL); // test double compile r3_tree_compile(n, NULL); // test double compile
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
match_entry * entry; match_entry * entry;
entry = match_entry_createl( "foo" , strlen("/foo") ); entry = match_entry_createl( "foo" , strlen("/foo") );
@ -328,7 +328,7 @@ START_TEST (test_incomplete_slug_path)
r3_tree_compile(n, &errstr); r3_tree_compile(n, &errstr);
ck_assert(errstr == NULL); // no error ck_assert(errstr == NULL); // no error
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
r3_tree_free(n); r3_tree_free(n);
} }
@ -401,7 +401,7 @@ START_TEST (test_root_match)
char *errstr = NULL; char *errstr = NULL;
r3_tree_compile(n, &errstr); r3_tree_compile(n, &errstr);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
node *matched; node *matched;
matched = r3_tree_match(n, "/", NULL); matched = r3_tree_match(n, "/", NULL);
ck_assert(matched); ck_assert(matched);
@ -437,7 +437,7 @@ START_TEST (test_pcre_patterns_insert_2)
char *errstr = NULL; char *errstr = NULL;
r3_tree_compile(n, &errstr); r3_tree_compile(n, &errstr);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
node *matched; node *matched;
matched = r3_tree_match(n, "/post/11/22", NULL); matched = r3_tree_match(n, "/post/11/22", NULL);
ck_assert((int)matched); ck_assert((int)matched);
@ -453,11 +453,11 @@ START_TEST (test_pcre_patterns_insert_3)
node * n = r3_tree_create(10); node * n = r3_tree_create(10);
printf("Inserting /post/{idx:\\d{2}}/{idy}\n"); printf("Inserting /post/{idx:\\d{2}}/{idy}\n");
r3_tree_insert_path(n, "/post/{idx:\\d{2}}/{idy}", NULL); r3_tree_insert_path(n, "/post/{idx:\\d{2}}/{idy}", NULL);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
printf("Inserting /zoo\n"); printf("Inserting /zoo\n");
r3_tree_insert_path(n, "/zoo", NULL); r3_tree_insert_path(n, "/zoo", NULL);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
r3_tree_insert_path(n, "/foo", NULL); r3_tree_insert_path(n, "/foo", NULL);
r3_tree_insert_path(n, "/bar", NULL); r3_tree_insert_path(n, "/bar", NULL);
@ -465,7 +465,7 @@ START_TEST (test_pcre_patterns_insert_3)
char *errstr = NULL; char *errstr = NULL;
r3_tree_compile(n, &errstr); r3_tree_compile(n, &errstr);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
node *matched; node *matched;
@ -551,8 +551,7 @@ START_TEST (test_insert_pathl)
char * errstr = NULL; char * errstr = NULL;
r3_tree_compile(n, &errstr); r3_tree_compile(n, &errstr);
ck_assert(errstr == NULL); ck_assert(errstr == NULL);
// r3_tree_dump(n, 0);
r3_tree_dump(n, 0);
r3_tree_free(n); r3_tree_free(n);
} }
END_TEST END_TEST
@ -577,7 +576,7 @@ START_TEST (test_compile_fail)
fprintf(stderr, "Compile failed: %s\n", errstr); fprintf(stderr, "Compile failed: %s\n", errstr);
free(errstr); free(errstr);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
r3_tree_free(n); r3_tree_free(n);
} }
END_TEST END_TEST
@ -669,7 +668,7 @@ START_TEST(test_pcre_pattern_more)
r3_tree_insert_path(n, "/user3/{id:\\d{3}}", &var3); r3_tree_insert_path(n, "/user3/{id:\\d{3}}", &var3);
r3_tree_insert_path(n, "/user", &var0); r3_tree_insert_path(n, "/user", &var0);
r3_tree_compile(n, NULL); r3_tree_compile(n, NULL);
r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
node *matched; node *matched;
matched = r3_tree_matchl(n, "/user/123", strlen("/user/123"), entry); matched = r3_tree_matchl(n, "/user/123", strlen("/user/123"), entry);
@ -736,25 +735,31 @@ START_TEST(test_insert_route)
} }
END_TEST END_TEST
Suite* r3_suite (void) { Suite* r3_suite (void) {
Suite *suite = suite_create("r3 core tests"); Suite *suite = suite_create("r3 core tests");
TCase *tcase = tcase_create("common_prefix_testcase");
TCase *tcase = tcase_create("testcase");
tcase_add_test(tcase, test_find_common_prefix); tcase_add_test(tcase, test_find_common_prefix);
tcase_add_test(tcase, test_find_common_prefix_after); tcase_add_test(tcase, test_find_common_prefix_after);
tcase_add_test(tcase, test_find_common_prefix_double_middle); tcase_add_test(tcase, test_find_common_prefix_double_middle);
tcase_add_test(tcase, test_find_common_prefix_middle); tcase_add_test(tcase, test_find_common_prefix_middle);
tcase_add_test(tcase, test_find_common_prefix_same_pattern); tcase_add_test(tcase, test_find_common_prefix_same_pattern);
tcase_add_test(tcase, test_find_common_prefix_same_pattern2); tcase_add_test(tcase, test_find_common_prefix_same_pattern2);
suite_add_tcase(suite, tcase);
tcase = tcase_create("insert_testcase");
tcase_add_test(tcase, test_insert_pathl); tcase_add_test(tcase, test_insert_pathl);
tcase_add_test(tcase, test_insert_pathl_fail); tcase_add_test(tcase, test_insert_pathl_fail);
tcase_add_test(tcase, test_node_construct_and_free); tcase_add_test(tcase, test_node_construct_and_free);
suite_add_tcase(suite, tcase);
tcase = tcase_create("compile_testcase");
tcase_add_test(tcase, test_compile); tcase_add_test(tcase, test_compile);
tcase_add_test(tcase, test_compile_fail); tcase_add_test(tcase, test_compile_fail);
tcase_add_test(tcase, test_route_cmp); tcase_add_test(tcase, test_route_cmp);
tcase_add_test(tcase, test_insert_route); tcase_add_test(tcase, test_insert_route);
suite_add_tcase(suite, tcase);
tcase = tcase_create("pcre_pattern_testcase");
tcase_add_test(tcase, test_pcre_pattern_simple); tcase_add_test(tcase, test_pcre_pattern_simple);
tcase_add_test(tcase, test_pcre_pattern_more); tcase_add_test(tcase, test_pcre_pattern_more);
tcase_add_test(tcase, test_pcre_patterns_insert); tcase_add_test(tcase, test_pcre_patterns_insert);