From: Christian Brauner Date: Sun, 25 Sep 2016 21:57:43 +0000 (+0200) Subject: tests: add unit tests for lxc_deslashify() X-Git-Tag: lxc-2.1.0~313^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1209%2Fhead;p=thirdparty%2Flxc.git tests: add unit tests for lxc_deslashify() Signed-off-by: Christian Brauner --- 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); }