From b4ce60de590241ef8f5fcdb30b3ae82e0ac148ac Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 08:13:19 +0800 Subject: [PATCH] separate check_str_array test cases --- tests/Makefile.am | 3 +++ tests/check_str_array.c | 53 +++++++++++++++++++++++++++++++++++++++++ tests/check_tree.c | 23 ------------------ 3 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 tests/check_str_array.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 8b3a270..555b867 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,9 @@ check_slug_SOURCES = check_slug.c TESTS += check_tree check_tree_SOURCES = check_tree.c +TESTS += check_str_array +check_str_array_SOURCES = check_str_array.c + if ENABLE_JSON TESTS += check_json diff --git a/tests/check_str_array.c b/tests/check_str_array.c new file mode 100644 index 0000000..911591e --- /dev/null +++ b/tests/check_str_array.c @@ -0,0 +1,53 @@ +/* + * check_str_array.c + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ +#include "config.h" +#include +#include +#include +#include "r3.h" +#include "r3_str.h" +#include "zmalloc.h" + +START_TEST (test_str_array) +{ + str_array * l = str_array_create(3); + ck_assert(l); + + ck_assert(str_array_append(l, zstrdup("abc"))); + ck_assert( l->len == 1 ); + + ck_assert(str_array_append(l, zstrdup("foo") )); + ck_assert( l->len == 2 ); + + ck_assert( str_array_append(l, zstrdup("bar") ) ); + ck_assert( l->len == 3 ); + + ck_assert( str_array_append(l, zstrdup("zoo") ) ); + ck_assert( l->len == 4 ); + + ck_assert( str_array_resize(l, l->cap * 2) ); + str_array_free(l); +} +END_TEST + +Suite* r3_suite (void) { + Suite *suite = suite_create("str_array test"); + TCase *tcase = tcase_create("testcase"); + tcase_add_test(tcase, test_str_array); + suite_add_tcase(suite, tcase); + return suite; +} + +int main (int argc, char *argv[]) { + int number_failed; + Suite *suite = r3_suite(); + SRunner *runner = srunner_create(suite); + srunner_run_all(runner, CK_NORMAL); + number_failed = srunner_ntests_failed(runner); + srunner_free(runner); + return number_failed; +} diff --git a/tests/check_tree.c b/tests/check_tree.c index 5bb381a..47fe795 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -277,28 +277,6 @@ END_TEST -START_TEST (test_str_array) -{ - str_array * l = str_array_create(3); - ck_assert(l); - - ck_assert(str_array_append(l, zstrdup("abc"))); - ck_assert( l->len == 1 ); - - ck_assert(str_array_append(l, zstrdup("foo") )); - ck_assert( l->len == 2 ); - - fail_if( FALSE == str_array_append(l, zstrdup("bar") ) ); - fail_if( l->len != 3 ); - - fail_if( FALSE == str_array_append(l, zstrdup("zoo") ) ); - fail_if( l->len != 4 ); - - fail_if( FALSE == str_array_resize(l, l->cap * 2) ); - - str_array_free(l); -} -END_TEST START_TEST(test_route_cmp) { @@ -422,7 +400,6 @@ Suite* r3_suite (void) { TCase *tcase = tcase_create("testcase"); tcase_add_test(tcase, test_r3_node_construct_and_free); - tcase_add_test(tcase, test_str_array); tcase_add_test(tcase, test_ltrim_slash); tcase_add_test(tcase, testr3_tree_insert_pathl); tcase_add_test(tcase, test_compile);