tests: add unit tests for lxc_deslashify()

parent c56a9652
......@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment