summaryrefslogtreecommitdiffstats
path: root/regress/usr.bin
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2021-03-19 04:23:50 +0000
committerdjm <djm@openbsd.org>2021-03-19 04:23:50 +0000
commit3db7c0f63c899a7470bd6ee63aa74a089acc7bac (patch)
treec9988d3d8c6d96f8b505c41e6d97fc41ec6728e1 /regress/usr.bin
parentsplit (diff)
downloadwireguard-openbsd-3db7c0f63c899a7470bd6ee63aa74a089acc7bac.tar.xz
wireguard-openbsd-3db7c0f63c899a7470bd6ee63aa74a089acc7bac.zip
add a test for misc.c:argv_split(), currently fails
Diffstat (limited to 'regress/usr.bin')
-rw-r--r--regress/usr.bin/ssh/unittests/misc/Makefile3
-rw-r--r--regress/usr.bin/ssh/unittests/misc/test_argv.c139
-rw-r--r--regress/usr.bin/ssh/unittests/misc/tests.c4
3 files changed, 144 insertions, 2 deletions
diff --git a/regress/usr.bin/ssh/unittests/misc/Makefile b/regress/usr.bin/ssh/unittests/misc/Makefile
index 63d9c4775d9..0658c38c6a2 100644
--- a/regress/usr.bin/ssh/unittests/misc/Makefile
+++ b/regress/usr.bin/ssh/unittests/misc/Makefile
@@ -1,10 +1,11 @@
-# $OpenBSD: Makefile,v 1.5 2021/03/19 03:25:01 djm Exp $
+# $OpenBSD: Makefile,v 1.6 2021/03/19 04:23:50 djm Exp $
PROG=test_misc
SRCS=tests.c
SRCS+= test_convtime.c
SRCS+= test_expand.c
SRCS+= test_parse.c
+SRCS+= test_argv.c
# From usr.bin/ssh/Makefile.inc
SRCS+= sshbuf.c
diff --git a/regress/usr.bin/ssh/unittests/misc/test_argv.c b/regress/usr.bin/ssh/unittests/misc/test_argv.c
new file mode 100644
index 00000000000..0ce86694d38
--- /dev/null
+++ b/regress/usr.bin/ssh/unittests/misc/test_argv.c
@@ -0,0 +1,139 @@
+/* $OpenBSD: test_argv.c,v 1.1 2021/03/19 04:23:50 djm Exp $ */
+/*
+ * Regress test for misc argv handling functions.
+ *
+ * Placed in the public domain.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test_helper.h"
+
+#include "log.h"
+#include "misc.h"
+
+void test_argv(void);
+
+static void
+free_argv(char **av, int ac)
+{
+ int i;
+
+ for (i = 0; i < ac; i++)
+ free(av[i]);
+ free(av);
+}
+
+void
+test_argv(void)
+{
+ char **av = NULL;
+ int ac = 0;
+
+#define RESET_ARGV() \
+ do { \
+ free_argv(av, ac); \
+ av = NULL; \
+ ac = -1; \
+ } while (0)
+
+ TEST_START("empty args");
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 0);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_PTR_EQ(av[0], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split(" ", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 0);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_PTR_EQ(av[0], NULL);
+ TEST_DONE();
+
+ TEST_START("trivial args");
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("leamas", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "leamas");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("smiley leamas", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 2);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "smiley");
+ ASSERT_STRING_EQ(av[1], "leamas");
+ ASSERT_PTR_EQ(av[2], NULL);
+ TEST_DONE();
+
+ TEST_START("quoted");
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("\"smiley\"", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "smiley");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("leamas \" smiley \"", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 2);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "leamas");
+ ASSERT_STRING_EQ(av[1], " smiley ");
+ ASSERT_PTR_EQ(av[2], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("\"smiley leamas\"", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "smiley leamas");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("smiley\" leamas\" liz", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 2);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "smiley leamas");
+ ASSERT_STRING_EQ(av[1], "liz");
+ ASSERT_PTR_EQ(av[2], NULL);
+ TEST_DONE();
+
+ TEST_START("escaped");
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("\\\"smiley\\'", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "\"smiley'");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("'\\'smiley\\\"'", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "'smiley\"");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("smiley\\'s leamas\\'", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 2);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "smiley's");
+ ASSERT_STRING_EQ(av[1], "leamas'");
+ ASSERT_PTR_EQ(av[2], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("leamas\\\\smiley", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 1);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "leamas\\smiley");
+ ASSERT_PTR_EQ(av[1], NULL);
+ RESET_ARGV();
+ ASSERT_INT_EQ(argv_split("leamas\\\\ \\\\smiley", &ac, &av), 0);
+ ASSERT_INT_EQ(ac, 2);
+ ASSERT_PTR_NE(av, NULL);
+ ASSERT_STRING_EQ(av[0], "leamas\\");
+ ASSERT_STRING_EQ(av[1], "\\smiley");
+ ASSERT_PTR_EQ(av[2], NULL);
+ TEST_DONE();
+
+ /* XXX test char *argv_assemble(int argc, char **argv) */
+}
diff --git a/regress/usr.bin/ssh/unittests/misc/tests.c b/regress/usr.bin/ssh/unittests/misc/tests.c
index 0e2218f9e87..fe9544a93fa 100644
--- a/regress/usr.bin/ssh/unittests/misc/tests.c
+++ b/regress/usr.bin/ssh/unittests/misc/tests.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tests.c,v 1.5 2021/03/19 03:25:01 djm Exp $ */
+/* $OpenBSD: tests.c,v 1.6 2021/03/19 04:23:50 djm Exp $ */
/*
* Regress test for misc helper functions.
*
@@ -20,6 +20,7 @@
void test_parse(void);
void test_convtime(void);
void test_expand(void);
+void test_argv(void);
void
tests(void)
@@ -27,4 +28,5 @@ tests(void)
test_parse();
test_convtime();
test_expand();
+ test_argv();
}