From 925c69f16ac2f4f843448cabbcef319350758260 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Mar 2017 23:07:26 +0000 Subject: add additional string handling tests --- test/utils.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test') diff --git a/test/utils.c b/test/utils.c index 4202792fb..3d5319a28 100644 --- a/test/utils.c +++ b/test/utils.c @@ -21,6 +21,8 @@ * Tests for utility functions. */ +#include "utils/config.h" + #include #include #include @@ -230,6 +232,41 @@ START_TEST(string_utils_cnv_space2nbsp_test) } END_TEST +START_TEST(string_utils_strcasestr_test) +{ + + char *res; + const char *haystack = "A big old long haystack string that has a small Needle in the middle of it with a different case"; + + res = strcasestr(haystack, "notfound"); + ck_assert(res == NULL); + + res = strcasestr(haystack, "needle"); + ck_assert(res != NULL); + + ck_assert_str_eq(res, haystack + 48); + +} +END_TEST + +START_TEST(string_utils_strchrnul_test) +{ + + char *res; + const char *haystack = "A big old long haystack string that has a small Needle in the middle of it with a different case"; + + res = strchrnul(haystack, 'Z'); + ck_assert(res != NULL); + ck_assert(*res == 0); + + res = strchrnul(haystack, 'N'); + ck_assert(res != NULL); + + ck_assert_str_eq(res, haystack + 48); + +} +END_TEST + static TCase *string_utils_case_create(void) { @@ -237,6 +274,8 @@ static TCase *string_utils_case_create(void) tc = tcase_create("String utilities"); tcase_add_test(tc, string_utils_cnv_space2nbsp_test); + tcase_add_test(tc, string_utils_strcasestr_test); + tcase_add_test(tc, string_utils_strchrnul_test); return tc; } -- cgit v1.2.3