From: Andre Muezerie <andremue@linux.microsoft.com>
To: andremue@linux.microsoft.com
Cc: dev@dpdk.org, dmitry.kozliuk@gmail.com, roretzla@linux.microsoft.com
Subject: [PATCH v3 2/2] test/strsep: add tests for function strsep()
Date: Tue, 22 Jul 2025 09:38:54 -0700 [thread overview]
Message-ID: <1753202334-27615-2-git-send-email-andremue@linux.microsoft.com> (raw)
In-Reply-To: <1753202334-27615-1-git-send-email-andremue@linux.microsoft.com>
This patch adds tests for the strsep() function.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
app/test/meson.build | 1 +
app/test/test_strsep.c | 109 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 app/test/test_strsep.c
diff --git a/app/test/meson.build b/app/test/meson.build
index 7d38f51918..8cc960c540 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -187,6 +187,7 @@ source_file_deps = {
'test_stack.c': ['stack'],
'test_stack_perf.c': ['stack'],
'test_string_fns.c': [],
+ 'test_strsep.c': [],
'test_table.c': ['table', 'pipeline', 'port'],
'test_table_acl.c': ['net', 'table', 'pipeline', 'port'],
'test_table_combined.c': ['table', 'pipeline', 'port'],
diff --git a/app/test/test_strsep.c b/app/test/test_strsep.c
new file mode 100644
index 0000000000..6c2ff67c18
--- /dev/null
+++ b/app/test/test_strsep.c
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2025 Microsoft Corporation
+ */
+
+#include <string.h>
+#include <rte_os_shim.h>
+
+#include "test.h"
+
+static int
+test_strsep_helper(const char *str, const char *delim,
+ const char * const expected_tokens[], size_t expected_tokens_count)
+{
+ char *s_dup = str != NULL ? strdup(str) : NULL;
+ char *s = s_dup;
+ const char *token;
+ for (size_t i = 0; i < expected_tokens_count; i++) {
+ token = strsep(&s, delim);
+ if (token == NULL) {
+ printf("Expected token '%s', got NULL\n", expected_tokens[i]);
+ free(s_dup);
+ return TEST_FAILED;
+ }
+ if (strcmp(expected_tokens[i], token) != 0) {
+ printf("Expected '%s', got '%s'\n", expected_tokens[i], token);
+ free(s_dup);
+ return TEST_FAILED;
+ }
+ }
+ /* Check that there are no more tokens left */
+ token = strsep(&s, delim);
+ if (token != NULL) {
+ printf("Expected NULL, got '%s'\n", token);
+ free(s_dup);
+ return TEST_FAILED;
+ }
+ free(s_dup);
+ return TEST_SUCCESS;
+}
+
+static int
+test_strsep_single_delimiter(void)
+{
+ const char *str = "hello,world";
+ const char *delim = ",";
+ static const char * const expected_tokens[] = { "hello", "world" };
+ const size_t expected_tokens_count = RTE_DIM(expected_tokens);
+ return test_strsep_helper(str, delim, expected_tokens, expected_tokens_count);
+}
+
+static int
+test_strsep_multiple_delimiters(void)
+{
+ const char *str = "hello,world;this:is;a:test";
+ const char *delim = ",;:";
+ static const char * const expected_tokens[] = {"hello", "world", "this", "is", "a", "test"};
+ const size_t expected_tokens_count = RTE_DIM(expected_tokens);
+ return test_strsep_helper(str, delim, expected_tokens, expected_tokens_count);
+}
+
+static int
+test_strsep_string_with_no_delimiters(void)
+{
+ const char *str = "helloworld";
+ const char *delim = ",";
+ static const char * const expected_tokens[] = {"helloworld"};
+ const size_t expected_tokens_count = RTE_DIM(expected_tokens);
+ return test_strsep_helper(str, delim, expected_tokens, expected_tokens_count);
+}
+
+static int
+test_strsep_empty_string(void)
+{
+ const char *str = "";
+ const char *delim = ",";
+ static const char * const expected_tokens[] = {""};
+ const size_t expected_tokens_count = RTE_DIM(expected_tokens);
+ return test_strsep_helper(str, delim, expected_tokens, expected_tokens_count);
+}
+
+static int
+test_strsep_null(void)
+{
+ const char *str = NULL;
+ const char *delim = ",";
+ static const char * const expected_tokens[] = {""};
+ const size_t expected_tokens_count = 0;
+ return test_strsep_helper(str, delim, expected_tokens, expected_tokens_count);
+}
+
+static struct unit_test_suite test_suite = {
+ .suite_name = "Strsep test suite",
+ .unit_test_cases = {
+ TEST_CASE(test_strsep_single_delimiter),
+ TEST_CASE(test_strsep_multiple_delimiters),
+ TEST_CASE(test_strsep_string_with_no_delimiters),
+ TEST_CASE(test_strsep_empty_string),
+ TEST_CASE(test_strsep_null),
+ TEST_CASES_END()
+ }
+};
+
+static int
+test_strsep(void)
+{
+ return unit_test_suite_runner(&test_suite);
+}
+
+REGISTER_FAST_TEST(strsep_autotest, true, true, test_strsep);
--
2.50.1.vfs.0.0
prev parent reply other threads:[~2025-07-22 16:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 13:22 [PATCH 1/2] eal: add strsep() for Windows builds Andre Muezerie
2025-05-16 13:22 ` [PATCH 2/2] test/strsep: add tests for function strsep() Andre Muezerie
2025-07-21 20:39 ` [PATCH v2 1/2] eal: add strsep() for Windows builds Andre Muezerie
2025-07-21 20:39 ` [PATCH v2 2/2] test/strsep: add tests for function strsep() Andre Muezerie
2025-07-22 14:30 ` David Marchand
2025-07-22 16:37 ` Andre Muezerie
2025-07-22 16:38 ` [PATCH v3 1/2] eal: add strsep() for Windows builds Andre Muezerie
2025-07-22 16:38 ` Andre Muezerie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1753202334-27615-2-git-send-email-andremue@linux.microsoft.com \
--to=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
--cc=dmitry.kozliuk@gmail.com \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.