summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-03-14 11:59:04 +0000
committerVincent Sanders <vince@kyllikki.org>2017-03-14 11:59:04 +0000
commit3d33157a863f979c57043d9aec1fb477d36e2dd4 (patch)
tree838b5d3935962b8ee76706a03dc09e709f4837fc
parentfcc1a1e4c2bab6373d94ff1f21d1d0f4f137d995 (diff)
downloadnetsurf-3d33157a863f979c57043d9aec1fb477d36e2dd4.tar.gz
netsurf-3d33157a863f979c57043d9aec1fb477d36e2dd4.tar.bz2
add utility string handling
-rw-r--r--test/utils.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/utils.c b/test/utils.c
index 62ccf512d..e74057ebd 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -181,6 +181,65 @@ static TCase *corestrings_case_create(void)
return tc;
}
+START_TEST(string_utils_squash_whitespace_test)
+{
+ char *res;
+ res = squash_whitespace(" A string with \t \t lots of whitespace ");
+ ck_assert(res != NULL);
+ ck_assert_str_eq(res, " A string with lots of whitespace ");
+
+ free(res);
+}
+END_TEST
+
+
+START_TEST(string_utils_cnv_space2nbsp_test)
+{
+ char *res;
+ char comparison[64];
+
+ snprintf(comparison, 64,
+ "%c%cA%c%cstring%c%c%c%cwith%c%c%c%c%c%cwhitespace%c%c",
+ 0xC2, 0xA0, 0xC2, 0xA0, 0xC2, 0xA0, 0xC2, 0xA0,
+ 0xC2, 0xA0, 0xC2, 0xA0, 0xC2, 0xA0, 0xC2, 0xA0);
+
+ res = cnv_space2nbsp(" A string with \t whitespace ");
+ ck_assert(res != NULL);
+ ck_assert_str_eq(res, comparison);
+
+ free(res);
+}
+END_TEST
+
+
+START_TEST(string_utils_snstrjoin_test)
+{
+ nserror res;
+ char *resstr = NULL;
+ size_t resstrlen;
+
+ res = snstrjoin(&resstr, &resstrlen, ',', 4, "1", "2", "3", "4");
+ ck_assert_int_eq(res, NSERROR_OK);
+ ck_assert(resstr != NULL);
+ ck_assert_int_eq(resstrlen, 8);
+ ck_assert_str_eq(resstr, "1,2,3,4");
+ free(resstr);
+}
+END_TEST
+
+
+static TCase *string_utils_case_create(void)
+{
+ TCase *tc;
+ tc = tcase_create("String utilities");
+
+ tcase_add_test(tc, string_utils_squash_whitespace_test);
+ tcase_add_test(tc, string_utils_cnv_space2nbsp_test);
+ tcase_add_test(tc, string_utils_snstrjoin_test);
+
+ return tc;
+}
+
static Suite *utils_suite_create(void)
{
Suite *s;
@@ -189,6 +248,7 @@ static Suite *utils_suite_create(void)
suite_add_tcase(s, human_friendly_bytesize_case_create());
suite_add_tcase(s, squash_whitespace_case_create());
suite_add_tcase(s, corestrings_case_create());
+ suite_add_tcase(s, string_utils_case_create());
return s;
}