diff options
author | Sahana Prasad <sahana@redhat.com> | 2019-12-20 01:44:00 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-12-20 14:35:41 +0100 |
commit | 314448786e472c99797e85af84a19b49ac897345 (patch) | |
tree | 929e03cadf21c211012c38c329f6066f9f743efc | |
parent | 35216e7254d76bdf5b03ae79ba10e4d3dbf74256 (diff) | |
download | libssh-314448786e472c99797e85af84a19b49ac897345.tar.gz libssh-314448786e472c99797e85af84a19b49ac897345.tar.xz libssh-314448786e472c99797e85af84a19b49ac897345.zip |
unittest: Adds unit tests for ssh_strreplace().
Signed-off-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | tests/unittests/torture_misc.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index ef06d65f..0f9b0def 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -655,6 +655,55 @@ static void torture_ssh_newline_vis(UNUSED_PARAM(void **state)) assert_string_equal(buffer, "a\\nb\\n"); } +static void torture_ssh_strreplace(void **state) +{ + char test_string1[] = "this;is;a;test"; + char test_string2[] = "test;is;a;this"; + char test_string3[] = "this;test;is;a"; + char *replaced_string = NULL; + + (void) state; + + /* pattern and replacement are of the same size */ + replaced_string = ssh_strreplace(test_string1, "test", "kiwi"); + assert_string_equal(replaced_string, "this;is;a;kiwi"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string2, "test", "kiwi"); + assert_string_equal(replaced_string, "kiwi;is;a;this"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string3, "test", "kiwi"); + assert_string_equal(replaced_string, "this;kiwi;is;a"); + free(replaced_string); + + /* replacement is greater than pattern */ + replaced_string = ssh_strreplace(test_string1, "test", "an;apple"); + assert_string_equal(replaced_string, "this;is;a;an;apple"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string2, "test", "an;apple"); + assert_string_equal(replaced_string, "an;apple;is;a;this"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string3, "test", "an;apple"); + assert_string_equal(replaced_string, "this;an;apple;is;a"); + free(replaced_string); + + /* replacement is less than pattern */ + replaced_string = ssh_strreplace(test_string1, "test", "an"); + assert_string_equal(replaced_string, "this;is;a;an"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string2, "test", "an"); + assert_string_equal(replaced_string, "an;is;a;this"); + free(replaced_string); + + replaced_string = ssh_strreplace(test_string3, "test", "an"); + assert_string_equal(replaced_string, "this;an;is;a"); + free(replaced_string); +} + int torture_run_tests(void) { int rc; struct CMUnitTest tests[] = { @@ -677,6 +726,7 @@ int torture_run_tests(void) { cmocka_unit_test(torture_ssh_newline_vis), cmocka_unit_test(torture_ssh_mkdirs), cmocka_unit_test(torture_ssh_quote_file_name), + cmocka_unit_test(torture_ssh_strreplace), }; ssh_init(); |