summaryrefslogtreecommitdiff
path: root/test/lib/string.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-02-12 08:41:36 -0600
committerTom Rini <trini@konsulko.com>2025-02-12 12:37:30 -0600
commit9b35357b95e30fd670869b4348159b65e102cc82 (patch)
tree2aee5b7566dc114ee0f02c4507c94885d1eb72d2 /test/lib/string.c
parent3da1864b1f2fc3cf2b4eaa1849bcafa669ff674c (diff)
parenta091d173e32b98fe372b5b02d4e25c81f1bc9dc1 (diff)
Merge branch 'u-boot-net-20250212' of https://source.denx.de/u-boot/custodians/u-boot-net
CI: https://source.denx.de/u-boot/custodians/u-boot-net/-/pipelines/24577 net-lwip: * Fix incorrect selection of ethernet device on boards having more than one * Fix TFTP option processing * Make the WGET_HTTPS Kconfig symbol depend on DM_RNG lib: * Add strnstr()
Diffstat (limited to 'test/lib/string.c')
-rw-r--r--test/lib/string.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lib/string.c b/test/lib/string.c
index 8d22f3fd68f..31391a387b9 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -11,6 +11,7 @@
#include <command.h>
#include <log.h>
+#include <string.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
@@ -221,3 +222,42 @@ static int lib_memdup(struct unit_test_state *uts)
return 0;
}
LIB_TEST(lib_memdup, 0);
+
+/** lib_strnstr() - unit test for strnstr() */
+static int lib_strnstr(struct unit_test_state *uts)
+{
+ const char *s1 = "Itsy Bitsy Teenie Weenie";
+ const char *s2 = "eenie";
+ const char *s3 = "eery";
+
+ ut_asserteq_ptr(&s1[12], strnstr(s1, s2, SIZE_MAX));
+ ut_asserteq_ptr(&s1[12], strnstr(s1, s2, 17));
+ ut_assertnull(strnstr(s1, s2, 16));
+ ut_assertnull(strnstr(s1, s2, 0));
+ ut_asserteq_ptr(&s1[13], strnstr(&s1[3], &s2[1], SIZE_MAX));
+ ut_asserteq_ptr(&s1[13], strnstr(&s1[3], &s2[1], 14));
+ ut_assertnull(strnstr(&s1[3], &s2[1], 13));
+ ut_assertnull(strnstr(&s1[3], &s2[1], 0));
+ ut_assertnull(strnstr(s1, s3, SIZE_MAX));
+ ut_assertnull(strnstr(s1, s3, 0));
+
+ return 0;
+}
+LIB_TEST(lib_strnstr, 0);
+
+/** lib_strstr() - unit test for strstr() */
+static int lib_strstr(struct unit_test_state *uts)
+{
+ const char *s1 = "Itsy Bitsy Teenie Weenie";
+ const char *s2 = "eenie";
+ const char *s3 = "easy";
+
+ ut_asserteq_ptr(&s1[12], strstr(s1, s2));
+ ut_asserteq_ptr(&s1[13], strstr(&s1[3], &s2[1]));
+ ut_assertnull(strstr(s1, s3));
+ ut_asserteq_ptr(&s1[2], strstr(s1, &s3[2]));
+ ut_asserteq_ptr(&s1[8], strstr(&s1[5], &s3[2]));
+
+ return 0;
+}
+LIB_TEST(lib_strstr, 0);