diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-08-05 10:12:34 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-08-13 15:10:22 +0200 |
commit | 1f3127e88a87953f059c9a70d3582ae1719594b1 (patch) | |
tree | b4638413e09809da334d7dfa6ef0b75f51e2f61c /src/tests/cmocka/test_string_utils.c | |
parent | d3c6fca0f0d3b1c5d3dda3dcf3de0ae3ae4c0c38 (diff) | |
download | sssd-1f3127e88a87953f059c9a70d3582ae1719594b1.tar.gz sssd-1f3127e88a87953f059c9a70d3582ae1719594b1.tar.xz sssd-1f3127e88a87953f059c9a70d3582ae1719594b1.zip |
Only replace space with the specified substitution
https://fedorahosted.org/sssd/ticket/2397
- make sss_replace_whitespaces only replace space (' ') not any
whitespace
- make sss_replace_whitespaces only replace a single char, not the whole
string
- rename CONFDB_NSS_OVERRIDE_DEFAULT_WHITESPACE to
CONFDB_NSS_OVERRIDE_DEFAULT_SPACE
- rename the override_default_whitespace option to override_space
- rename sss_replace_whitespaces() to sss_replace_space()
- rename sss_reverse_replace_whitespaces() to sss_reverse_replace_space()
- rename nctx->override_default_wsp_str to nctx->override_space
- make the return value of sss_replace_space non-const to avoid freeing
the result without compilation warnings
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/tests/cmocka/test_string_utils.c')
-rw-r--r-- | src/tests/cmocka/test_string_utils.c | 119 |
1 files changed, 50 insertions, 69 deletions
diff --git a/src/tests/cmocka/test_string_utils.c b/src/tests/cmocka/test_string_utils.c index d10c3be47..93d7d716f 100644 --- a/src/tests/cmocka/test_string_utils.c +++ b/src/tests/cmocka/test_string_utils.c @@ -31,56 +31,40 @@ void test_replace_whitespaces(void **state) struct { const char *input; const char *output; - const char *replace_string; + const char replace_char; } data_set[] = { - { "", "", "-" }, - { " ", "-", "-" }, - { "\t", "-", "-" }, - { "\n", "-", "-" }, - { " \t\n ", "----", "-" }, - { "abcd", "abcd", "-" }, - { "a b c d", "a-b-c-d", "-" }, - { " a b c d ", "-a-b-c-d-", "-" }, - { " ", "^", "^" }, - { "\t", "^", "^" }, - { "\n", "^", "^" }, - { " \t\n ", "^^^^", "^" }, - { "abcd", "abcd", "^" }, - { "a b c d", "a^b^c^d", "^" }, - { " a b c d ", "^a^b^c^d^", "^" }, - { " ", "^", "^" }, - { "\t", ";-)", ";-)" }, - { "\n", ";-)", ";-)" }, - { " \t\n ", ";-);-);-);-)", ";-)" }, - { "abcd", "abcd", ";-)" }, - { "a b c d", "a;-)b;-)c;-)d", ";-)" }, - { " a b c d ", ";-)a;-)b;-)c;-)d;-)", ";-)" }, - { " ", " ", " " }, - { " ", " ", " " }, - { "abcd", "abcd", " " }, - { "a b c d", "a b c d", " " }, - { " a b c d ", " a b c d ", " " }, - { " ", " \t", " \t" }, - { " ", " \t \t \t \t", " \t" }, - { "abcd", "abcd", " \t" }, - { "a b c d", "a \tb \tc \td", " \t" }, - { " a b c d ", " \ta \tb \tc \td \t", " \t" }, - { NULL, NULL, NULL }, + { "", "", '-' }, + { " ", "-", '-' }, + { "abcd", "abcd", '-' }, + { "a b c d", "a-b-c-d", '-' }, + { " a b c d ", "-a-b-c-d-", '-' }, + { " ", "^", '^' }, + { "abcd", "abcd", '^' }, + { "a b c d", "a^b^c^d", '^' }, + { " a b c d ", "^a^b^c^d^", '^' }, + { " ", "^", '^' }, + { " ", " ", ' ' }, + { " ", " ", ' ' }, + { "abcd", "abcd", ' ' }, + { "a b c d", "a b c d", ' ' }, + { NULL, NULL, '\0' }, }; mem_ctx = talloc_new(NULL); assert_non_null(mem_ctx); check_leaks_push(mem_ctx); - res = sss_replace_whitespaces(mem_ctx, input_str, NULL); - assert_true(res == input_str); + res = sss_replace_space(mem_ctx, input_str, '\0'); + assert_string_equal(res, input_str); + talloc_zfree(res); - res = sss_replace_whitespaces(mem_ctx, input_str, ""); - assert_true(res == input_str); + res = sss_replace_space(mem_ctx, input_str, '\0'); + assert_string_equal(res, input_str); + talloc_zfree(res); for (i=0; data_set[i].input != NULL; ++i) { - res = sss_replace_whitespaces(mem_ctx, data_set[i].input, - data_set[i].replace_string); + res = sss_replace_space(mem_ctx, data_set[i].input, + data_set[i].replace_char); assert_non_null(res); assert_string_equal(res, data_set[i].output); talloc_zfree(res); @@ -100,46 +84,43 @@ void test_reverse_replace_whitespaces(void **state) struct { const char *input; const char *output; - const char *replace_string; + const char replace_char; } data_set[] = { - { "", "", "-" }, - { "-", " ", "-" }, - { "----", " ", "-" }, - { "abcd", "abcd", "-" }, - { "a-b-c-d", "a b c d", "-" }, - { "-a-b-c-d-", " a b c d ", "-" }, - { "^", " ", "^" }, - { "^^^^", " ", "^" }, - { "abcd", "abcd", "^" }, - { "a^b^c^d", "a b c d", "^" }, - { "^a^b^c^d^", " a b c d ", "^" }, - { ";-)", " ", ";-)" }, - { ";-);-);-);-)", " ", ";-)" }, - { "abcd", "abcd", ";-)" }, - { "a;-)b;-)c;-)d", "a b c d", ";-)" }, - { ";-)a;-)b;-)c;-)d;-)", " a b c d ", ";-)" }, - { " ", " ", " " }, - { " ", " ", " " }, - { "abcd", "abcd", " " }, - { "a b c d", "a b c d", " " }, - { " a b c d ", " a b c d ", " " }, - { NULL, NULL, NULL }, + { "", "", '-' }, + { "-", " ", '-' }, + { "----", " ", '-' }, + { "abcd", "abcd", '-' }, + { "a-b-c-d", "a b c d", '-' }, + { "-a-b-c-d-", " a b c d ", '-' }, + { "^", " ", '^' }, + { "^^^^", " ", '^' }, + { "abcd", "abcd", '^' }, + { "a^b^c^d", "a b c d", '^' }, + { "^a^b^c^d^", " a b c d ", '^' }, + { " ", " ", ' ' }, + { " ", " ", ' ' }, + { "abcd", "abcd", ' ' }, + { "a b c d", "a b c d", ' ' }, + { " a b c d ", " a b c d ", ' ' }, + { NULL, NULL, '\0' }, }; mem_ctx = talloc_new(NULL); assert_non_null(mem_ctx); check_leaks_push(mem_ctx); - res = sss_reverse_replace_whitespaces(mem_ctx, input_str, NULL); - assert_true(res == input_str); + res = sss_reverse_replace_space(mem_ctx, input_str, '\0'); + assert_string_equal(res, input_str); + talloc_free(res); - res = sss_reverse_replace_whitespaces(mem_ctx, input_str, ""); - assert_true(res == input_str); + res = sss_reverse_replace_space(mem_ctx, input_str, '\0'); + assert_string_equal(res, input_str); + talloc_free(res); for (i=0; data_set[i].input != NULL; ++i) { input_str = discard_const_p(char, data_set[i].input); - res = sss_reverse_replace_whitespaces(mem_ctx, input_str, - data_set[i].replace_string); + res = sss_reverse_replace_space(mem_ctx, input_str, + data_set[i].replace_char); assert_non_null(res); assert_string_equal(res, data_set[i].output); talloc_zfree(res); |