From 1a514c157dc61e5d86f60686909385a31e0d01de Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sun, 25 Sep 2016 23:57:43 +0200 Subject: [PATCH] tests: add unit tests for lxc_deslashify() Signed-off-by: Christian Brauner --- src/tests/lxc-test-utils.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/tests/lxc-test-utils.c b/src/tests/lxc-test-utils.c index 4c1c37325..5b213c84f 100644 --- a/src/tests/lxc-test-utils.c +++ b/src/tests/lxc-test-utils.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _GNU_SOURCE #include #include #include @@ -28,6 +29,37 @@ #include "lxctest.h" #include "utils.h" +void test_lxc_deslashify(void) +{ + char *s = strdup("/A///B//C/D/E/"); + if (!s) + exit(EXIT_FAILURE); + lxc_test_assert_abort(lxc_deslashify(&s)); + lxc_test_assert_abort(strcmp(s, "/A/B/C/D/E") == 0); + free(s); + + s = strdup("/A"); + if (!s) + exit(EXIT_FAILURE); + lxc_test_assert_abort(lxc_deslashify(&s)); + lxc_test_assert_abort(strcmp(s, "/A") == 0); + free(s); + + s = strdup(""); + if (!s) + exit(EXIT_FAILURE); + lxc_test_assert_abort(lxc_deslashify(&s)); + lxc_test_assert_abort(strcmp(s, "") == 0); + free(s); + + s = strdup("//"); + if (!s) + exit(EXIT_FAILURE); + lxc_test_assert_abort(lxc_deslashify(&s)); + lxc_test_assert_abort(strcmp(s, "/") == 0); + free(s); +} + void test_lxc_string_replace(void) { char *s; @@ -84,6 +116,7 @@ int main(int argc, char *argv[]) { test_lxc_string_replace(); test_lxc_string_in_array(); + test_lxc_deslashify(); exit(EXIT_SUCCESS); } -- 2.47.2