separate check_str_array test cases

This commit is contained in:
c9s 2014-06-02 08:13:19 +08:00
parent f3bf32b922
commit b4ce60de59
3 changed files with 56 additions and 23 deletions

View file

@ -21,6 +21,9 @@ check_slug_SOURCES = check_slug.c
TESTS += check_tree TESTS += check_tree
check_tree_SOURCES = check_tree.c check_tree_SOURCES = check_tree.c
TESTS += check_str_array
check_str_array_SOURCES = check_str_array.c
if ENABLE_JSON if ENABLE_JSON
TESTS += check_json TESTS += check_json

53
tests/check_str_array.c Normal file
View file

@ -0,0 +1,53 @@
/*
* check_str_array.c
* Copyright (C) 2014 c9s <c9s@c9smba.local>
*
* Distributed under terms of the MIT license.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <check.h>
#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;
}

View file

@ -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) START_TEST(test_route_cmp)
{ {
@ -422,7 +400,6 @@ Suite* r3_suite (void) {
TCase *tcase = tcase_create("testcase"); TCase *tcase = tcase_create("testcase");
tcase_add_test(tcase, test_r3_node_construct_and_free); 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, test_ltrim_slash);
tcase_add_test(tcase, testr3_tree_insert_pathl); tcase_add_test(tcase, testr3_tree_insert_pathl);
tcase_add_test(tcase, test_compile); tcase_add_test(tcase, test_compile);