diff options
author | Sumit Bose <sbose@redhat.com> | 2015-06-16 16:58:23 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-06-19 18:48:13 +0200 |
commit | a99845006f96f9d1e7af871ec67c71cee8408a62 (patch) | |
tree | 25a873d57d0f695652263dfc05de141859ff5a69 /src/tests | |
parent | 8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98 (diff) | |
download | sssd-a99845006f96f9d1e7af871ec67c71cee8408a62.tar.gz sssd-a99845006f96f9d1e7af871ec67c71cee8408a62.tar.xz sssd-a99845006f96f9d1e7af871ec67c71cee8408a62.zip |
utils: add get_last_x_chars()
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/cmocka/test_string_utils.c | 28 | ||||
-rw-r--r-- | src/tests/cmocka/test_utils.c | 1 | ||||
-rw-r--r-- | src/tests/cmocka/test_utils.h | 1 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/tests/cmocka/test_string_utils.c b/src/tests/cmocka/test_string_utils.c index 5d3fcf4fe..4832015a5 100644 --- a/src/tests/cmocka/test_string_utils.c +++ b/src/tests/cmocka/test_string_utils.c @@ -192,3 +192,31 @@ void test_guid_blob_to_string_buf(void **state) assert_string_equal(test_data[c].guid_str, str_buf); } } + +void test_get_last_x_chars(void **state) +{ + const char *s; + + s = get_last_x_chars(NULL, 0); + assert_null(s); + + s = get_last_x_chars("abc", 0); + assert_non_null(s); + assert_string_equal(s, ""); + + s = get_last_x_chars("abc", 1); + assert_non_null(s); + assert_string_equal(s, "c"); + + s = get_last_x_chars("abc", 2); + assert_non_null(s); + assert_string_equal(s, "bc"); + + s = get_last_x_chars("abc", 3); + assert_non_null(s); + assert_string_equal(s, "abc"); + + s = get_last_x_chars("abc", 4); + assert_non_null(s); + assert_string_equal(s, "abc"); +} diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c index e7f97f763..d3d00feda 100644 --- a/src/tests/cmocka/test_utils.c +++ b/src/tests/cmocka/test_utils.c @@ -1267,6 +1267,7 @@ int main(int argc, const char *argv[]) cmocka_unit_test(test_replace_whitespaces), cmocka_unit_test(test_reverse_replace_whitespaces), cmocka_unit_test(test_guid_blob_to_string_buf), + cmocka_unit_test(test_get_last_x_chars), cmocka_unit_test_setup_teardown(test_add_strings_lists, setup_add_strings_lists, teardown_add_strings_lists), diff --git a/src/tests/cmocka/test_utils.h b/src/tests/cmocka/test_utils.h index 61ef7e43a..8b5163165 100644 --- a/src/tests/cmocka/test_utils.h +++ b/src/tests/cmocka/test_utils.h @@ -30,5 +30,6 @@ void test_textual_public_key(void **state); void test_replace_whitespaces(void **state); void test_reverse_replace_whitespaces(void **state); void test_guid_blob_to_string_buf(void **state); +void test_get_last_x_chars(void **state); #endif /* __TESTS__CMOCKA__TEST_UTILS_H__ */ |