summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2022-02-04 07:53:45 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2022-02-04 07:53:45 +0000
commit9e69d48f71815ca8e1bb52d8e0de0cbba43a23fa (patch)
tree0caa23ef61273053b7e90e934042ef1742d4f5ff /regress
parentdf8f3ded1e1d3d6259722efecbd14cf957ecde05 (diff)
Add unit tests for hpdelim.
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.bin/ssh/unittests/misc/Makefile3
-rw-r--r--regress/usr.bin/ssh/unittests/misc/test_hpdelim.c67
-rw-r--r--regress/usr.bin/ssh/unittests/misc/tests.c4
3 files changed, 72 insertions, 2 deletions
diff --git a/regress/usr.bin/ssh/unittests/misc/Makefile b/regress/usr.bin/ssh/unittests/misc/Makefile
index 656ae44dbec..e8fe1a95313 100644
--- a/regress/usr.bin/ssh/unittests/misc/Makefile
+++ b/regress/usr.bin/ssh/unittests/misc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2021/05/21 03:48:07 djm Exp $
+# $OpenBSD: Makefile,v 1.8 2022/02/04 07:53:44 dtucker Exp $
PROG=test_misc
SRCS=tests.c
@@ -7,6 +7,7 @@ SRCS+= test_expand.c
SRCS+= test_parse.c
SRCS+= test_argv.c
SRCS+= test_strdelim.c
+SRCS+= test_hpdelim.c
# From usr.bin/ssh/Makefile.inc
SRCS+= sshbuf.c
diff --git a/regress/usr.bin/ssh/unittests/misc/test_hpdelim.c b/regress/usr.bin/ssh/unittests/misc/test_hpdelim.c
new file mode 100644
index 00000000000..ccd53d99c39
--- /dev/null
+++ b/regress/usr.bin/ssh/unittests/misc/test_hpdelim.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: test_hpdelim.c,v 1.1 2022/02/04 07:53:44 dtucker Exp $ */
+/*
+ * Regress test for misc hpdelim() and co
+ *
+ * Placed in the public domain.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test_helper.h"
+
+#include "log.h"
+#include "misc.h"
+#include "xmalloc.h"
+
+void test_hpdelim(void);
+
+void
+test_hpdelim(void)
+{
+ char *orig, *str, *cp, *port;
+
+#define START_STRING(x) orig = str = xstrdup(x)
+#define DONE_STRING() free(orig)
+
+ TEST_START("hpdelim host only");
+ START_STRING("host");
+ cp = hpdelim(&str);
+ ASSERT_STRING_EQ(cp, "host");
+ ASSERT_PTR_EQ(str, NULL);
+ DONE_STRING();
+ TEST_DONE();
+
+ TEST_START("hpdelim host:port");
+ START_STRING("host:1234");
+ cp = hpdelim(&str);
+ ASSERT_STRING_EQ(cp, "host");
+ ASSERT_PTR_NE(str, NULL);
+ port = hpdelim(&str);
+ ASSERT_STRING_EQ(port, "1234");
+ ASSERT_PTR_EQ(str, NULL);
+ DONE_STRING();
+ TEST_DONE();
+
+ TEST_START("hpdelim [host]:port");
+ START_STRING("[::1]:1234");
+ cp = hpdelim(&str);
+ ASSERT_STRING_EQ(cp, "[::1]");
+ ASSERT_PTR_NE(str, NULL);
+ port = hpdelim(&str);
+ ASSERT_STRING_EQ(port, "1234");
+ ASSERT_PTR_EQ(str, NULL);
+ DONE_STRING();
+ TEST_DONE();
+
+ TEST_START("hpdelim missing ] error");
+ START_STRING("[::1:1234");
+ cp = hpdelim(&str);
+ ASSERT_PTR_EQ(cp, NULL);
+ DONE_STRING();
+ TEST_DONE();
+
+}
diff --git a/regress/usr.bin/ssh/unittests/misc/tests.c b/regress/usr.bin/ssh/unittests/misc/tests.c
index 307d6aee98a..e1917f725b5 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.8 2021/12/14 21:25:27 deraadt Exp $ */
+/* $OpenBSD: tests.c,v 1.9 2022/02/04 07:53:44 dtucker Exp $ */
/*
* Regress test for misc helper functions.
*
@@ -21,6 +21,7 @@ void test_convtime(void);
void test_expand(void);
void test_argv(void);
void test_strdelim(void);
+void test_hpdelim(void);
void
tests(void)
@@ -30,4 +31,5 @@ tests(void)
test_expand();
test_argv();
test_strdelim();
+ test_hpdelim();
}