[openssh-commits] [openssh] branch master updated: upstream: unit test for xextendf()

git+noreply at mindrot.org git+noreply at mindrot.org
Tue Sep 2 21:07:02 AEST 2025


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

djm pushed a commit to branch master
in repository openssh.

The following commit(s) were added to refs/heads/master by this push:
     new 8866d24cd upstream: unit test for xextendf()
8866d24cd is described below

commit 8866d24cdd1d6e73bb3220b753f94e255c49ff96
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Tue Sep 2 11:04:58 2025 +0000

    upstream: unit test for xextendf()
    
    OpenBSD-Regress-ID: ddb3b4db1a52dda23696b967470882fe2b9c3af7
---
 Makefile.in                            |  3 +-
 regress/unittests/misc/Makefile        |  3 +-
 regress/unittests/misc/test_xextendf.c | 89 ++++++++++++++++++++++++++++++++++
 regress/unittests/misc/tests.c         |  4 +-
 4 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 19a9e4dcf..9bfdc3fd3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -695,7 +695,8 @@ UNITTESTS_TEST_MISC_OBJS=\
 	regress/unittests/misc/test_argv.o \
 	regress/unittests/misc/test_strdelim.o \
 	regress/unittests/misc/test_hpdelim.o \
-	regress/unittests/misc/test_ptimeout.o
+	regress/unittests/misc/test_ptimeout.o \
+	regress/unittests/misc/test_xextendf.o
 
 regress/unittests/misc/test_misc$(EXEEXT): \
     ${UNITTESTS_TEST_MISC_OBJS} \
diff --git a/regress/unittests/misc/Makefile b/regress/unittests/misc/Makefile
index 7282be13a..a897b4b45 100644
--- a/regress/unittests/misc/Makefile
+++ b/regress/unittests/misc/Makefile
@@ -1,4 +1,4 @@
-#	$OpenBSD: Makefile,v 1.10 2025/04/15 04:00:42 djm Exp $
+#	$OpenBSD: Makefile,v 1.11 2025/09/02 11:04:58 djm Exp $
 
 PROG=test_misc
 SRCS=tests.c
@@ -9,6 +9,7 @@ SRCS+=	test_argv.c
 SRCS+=	test_strdelim.c
 SRCS+=	test_hpdelim.c
 SRCS+=	test_ptimeout.c
+SRCS+=	test_xextendf.c
 
 # From usr.bin/ssh/Makefile.inc
 SRCS+=	sshbuf.c
diff --git a/regress/unittests/misc/test_xextendf.c b/regress/unittests/misc/test_xextendf.c
new file mode 100644
index 000000000..f9562ad6b
--- /dev/null
+++ b/regress/unittests/misc/test_xextendf.c
@@ -0,0 +1,89 @@
+/* 	$OpenBSD: test_xextendf.c,v 1.1 2025/09/02 11:04:58 djm Exp $ */
+/*
+ * Regress test for misc xextendf() function.
+ *
+ * Placed in the public domain.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+
+#include "../test_helper/test_helper.h"
+
+#include "log.h"
+#include "misc.h"
+#include "xmalloc.h"
+
+void test_xextendf(void);
+
+void
+test_xextendf(void)
+{
+	char *s = NULL;
+
+	TEST_START("xextendf NULL string");
+	xextendf(&s, ",", "hello");
+	ASSERT_STRING_EQ(s, "hello");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf empty string");
+	s = xstrdup("");
+	xextendf(&s, ",", "world");
+	ASSERT_STRING_EQ(s, "world");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf append to string");
+	s = xstrdup("foo");
+	xextendf(&s, ",", "bar");
+	ASSERT_STRING_EQ(s, "foo,bar");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf append with NULL separator");
+	s = xstrdup("foo");
+	xextendf(&s, NULL, "bar");
+	ASSERT_STRING_EQ(s, "foobar");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf append with empty separator");
+	s = xstrdup("foo");
+	xextendf(&s, "", "bar");
+	ASSERT_STRING_EQ(s, "foobar");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf with format string");
+	s = xstrdup("start");
+	xextendf(&s, ":", "s=%s,d=%d", "string", 123);
+	ASSERT_STRING_EQ(s, "start:s=string,d=123");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+
+	TEST_START("xextendf multiple appends");
+	s = NULL;
+	xextendf(&s, ",", "one");
+	ASSERT_STRING_EQ(s, "one");
+	xextendf(&s, ",", "two");
+	ASSERT_STRING_EQ(s, "one,two");
+	xextendf(&s, ":", "three=%d", 3);
+	ASSERT_STRING_EQ(s, "one,two:three=3");
+	xextendf(&s, NULL, "four");
+	ASSERT_STRING_EQ(s, "one,two:three=3four");
+	free(s);
+	s = NULL;
+	TEST_DONE();
+}
diff --git a/regress/unittests/misc/tests.c b/regress/unittests/misc/tests.c
index 7611a0d3b..13588edaa 100644
--- a/regress/unittests/misc/tests.c
+++ b/regress/unittests/misc/tests.c
@@ -1,4 +1,4 @@
-/* 	$OpenBSD: tests.c,v 1.11 2025/04/15 04:00:42 djm Exp $ */
+/* 	$OpenBSD: tests.c,v 1.12 2025/09/02 11:04:58 djm Exp $ */
 /*
  * Regress test for misc helper functions.
  *
@@ -27,6 +27,7 @@ void test_argv(void);
 void test_strdelim(void);
 void test_hpdelim(void);
 void test_ptimeout(void);
+void test_xextendf(void);
 
 void
 tests(void)
@@ -38,6 +39,7 @@ tests(void)
 	test_strdelim();
 	test_hpdelim();
 	test_ptimeout();
+	test_xextendf();
 }
 
 void

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


More information about the openssh-commits mailing list