Add uc_str_append_all function
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <check.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ucore/strvec.h>
|
||||
|
||||
|
||||
@@ -73,6 +74,54 @@ START_TEST (test_strv_null_terminate)
|
||||
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_strv_append_all_copy)
|
||||
struct UCStrv src;
|
||||
struct UCStrv dst;
|
||||
int rc;
|
||||
|
||||
uc_strv_init(&src);
|
||||
uc_strv_init(&dst);
|
||||
|
||||
uc_strv_append(&dst, "string1");
|
||||
uc_strv_append(&src, "string2");
|
||||
uc_strv_append(&src, "string3");
|
||||
|
||||
rc = uc_strv_append_all(&dst, &src, 1);
|
||||
fail_if(rc != 0);
|
||||
fail_if(dst.cnt != 3);
|
||||
ck_assert_str_eq("string1", dst.strings[0]);
|
||||
ck_assert_str_eq("string2", dst.strings[1]);
|
||||
ck_assert_str_eq("string3", dst.strings[2]);
|
||||
|
||||
uc_strv_destroy(&src);
|
||||
uc_strv_destroy(&dst);
|
||||
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_strv_append_all_nocopy)
|
||||
struct UCStrv src;
|
||||
struct UCStrv dst;
|
||||
int rc;
|
||||
|
||||
uc_strv_init(&src);
|
||||
uc_strv_init(&dst);
|
||||
|
||||
uc_strv_append(&dst, "string1");
|
||||
uc_strv_append(&src, "string2");
|
||||
uc_strv_append(&src, "string3");
|
||||
|
||||
rc = uc_strv_append_all(&dst, &src, 0);
|
||||
fail_if(rc != 0);
|
||||
fail_if(dst.cnt != 3);
|
||||
ck_assert_str_eq("string1", dst.strings[0]);
|
||||
ck_assert_str_eq("string2", dst.strings[1]);
|
||||
ck_assert_str_eq("string3", dst.strings[2]);
|
||||
|
||||
uc_strv_destroy(&dst);
|
||||
free(src.strings);
|
||||
|
||||
END_TEST
|
||||
|
||||
|
||||
Suite *strv_suite(void)
|
||||
{
|
||||
@@ -83,6 +132,8 @@ Suite *strv_suite(void)
|
||||
tcase_add_test(tc, test_strv_clear);
|
||||
tcase_add_test(tc, test_strv_nocopy);
|
||||
tcase_add_test(tc, test_strv_null_terminate);
|
||||
tcase_add_test(tc, test_strv_append_all_copy);
|
||||
tcase_add_test(tc, test_strv_append_all_nocopy);
|
||||
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user