[openssh-commits] [openssh] 03/04: upstream: Add unit tests for hpdelim.

git+noreply at mindrot.org git+noreply at mindrot.org
Thu Feb 10 15:17:37 AEDT 2022


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit a29af853cff41c0635f0378c00fe91bf9c91dea4
Author: dtucker at openbsd.org <dtucker at openbsd.org>
Date:   Fri Feb 4 07:53:44 2022 +0000

    upstream: Add unit tests for hpdelim.
    
    OpenBSD-Regress-ID: be97b85c19895e6a1ce13c639765a3b48fd95018
---
 Makefile.in                           |   3 +-
 regress/unittests/misc/Makefile       |   3 +-
 regress/unittests/misc/test_hpdelim.c | 149 ++++++++++++++++++++++++++++++++++
 regress/unittests/misc/tests.c        |   4 +-
 4 files changed, 156 insertions(+), 3 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 6d82c1b1..065bf91e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -656,7 +656,8 @@ UNITTESTS_TEST_MISC_OBJS=\
 	regress/unittests/misc/test_expand.o \
 	regress/unittests/misc/test_convtime.o \
 	regress/unittests/misc/test_argv.o \
-	regress/unittests/misc/test_strdelim.o
+	regress/unittests/misc/test_strdelim.o \
+	regress/unittests/misc/test_hpdelim.o
 
 regress/unittests/misc/test_misc$(EXEEXT): \
     ${UNITTESTS_TEST_MISC_OBJS} \
diff --git a/regress/unittests/misc/Makefile b/regress/unittests/misc/Makefile
index 656ae44d..e8fe1a95 100644
--- a/regress/unittests/misc/Makefile
+++ b/regress/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/unittests/misc/test_hpdelim.c b/regress/unittests/misc/test_hpdelim.c
new file mode 100644
index 00000000..a6e99367
--- /dev/null
+++ b/regress/unittests/misc/test_hpdelim.c
@@ -0,0 +1,149 @@
+/* 	$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 "includes.h"
+
+#include <sys/types.h>
+#include <stdio.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#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();
+
+}
+/* 	$OpenBSD: test_hpdelim.c,v 1.2 2022/02/06 22:58:33 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 :port");
+	START_STRING(":1234");
+	cp = hpdelim(&str);
+	ASSERT_STRING_EQ(cp, "");
+	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("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/unittests/misc/tests.c b/regress/unittests/misc/tests.c
index d086a063..d52490e3 100644
--- a/regress/unittests/misc/tests.c
+++ b/regress/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.
  *
@@ -25,6 +25,7 @@ void test_convtime(void);
 void test_expand(void);
 void test_argv(void);
 void test_strdelim(void);
+void test_hpdelim(void);
 
 void
 tests(void)
@@ -34,4 +35,5 @@ tests(void)
 	test_expand();
 	test_argv();
 	test_strdelim();
+	test_hpdelim();
 }

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list