summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_zustr2stp.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
commitb6b00dd55e035bfbe311a527b567962ffa77ee43 (patch)
treecafc4d13785448e5a78bd40a51697ee07f07ac12 /tests/unit/test_zustr2stp.c
parentAdding debian version 1:4.13+dfsg1-5. (diff)
downloadshadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.tar.xz
shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.zip
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/unit/test_zustr2stp.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/test_zustr2stp.c b/tests/unit/test_zustr2stp.c
new file mode 100644
index 0000000..198d2eb
--- /dev/null
+++ b/tests/unit/test_zustr2stp.c
@@ -0,0 +1,53 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#include <stdarg.h> // Required by <cmocka.h>
+#include <stddef.h> // Required by <cmocka.h>
+#include <setjmp.h> // Required by <cmocka.h>
+#include <stdint.h> // Required by <cmocka.h>
+#include <cmocka.h>
+
+#include "string/zustr2stp.h"
+
+
+static void test_ZUSTR2STP(void **state);
+
+
+int
+main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_ZUSTR2STP),
+ };
+
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+
+static void
+test_ZUSTR2STP(void **state)
+{
+ char src[3] = {'1', '2', '3'};
+ char dst[4];
+
+ assert_true(ZUSTR2STP(&dst, src) == dst + strlen("123"));
+ assert_true(strcmp("123", dst) == 0);
+
+ src[2] = '\0';
+ assert_true(ZUSTR2STP(&dst, src) == dst + strlen("12"));
+ assert_true(strcmp("12", dst) == 0);
+
+ src[1] = '\0';
+ assert_true(ZUSTR2STP(&dst, src) == dst + strlen("1"));
+ assert_true(strcmp("1", dst) == 0);
+
+ src[0] = '\0';
+ assert_true(ZUSTR2STP(&dst, src) == dst + strlen(""));
+ assert_true(strcmp("", dst) == 0);
+}