[PATCH 7/8] test: string: add test of new strcasestr() function

Rasmus Villemoes rv at rasmusvillemoes.dk
Wed Jul 1 19:15:34 CEST 2026


Change the existing strstr() test a little so that the substring not
found is "bits", i.e. one that is actually found when doing case
insensitive search.

Then copy all of lib_strstr(), adapt the expectation for the
strcasestr(s1, s3) result, and add another "not found" case.

Signed-off-by: Rasmus Villemoes <rv at rasmusvillemoes.dk>
---
 test/lib/string.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/test/lib/string.c b/test/lib/string.c
index db6f28dbfdf..d418a40c4d4 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -284,18 +284,36 @@ static int lib_strstr(struct unit_test_state *uts)
 {
 	const char *s1 = "Itsy Bitsy Teenie Weenie";
 	const char *s2 = "eenie";
-	const char *s3 = "easy";
+	const char *s3 = "bits";
 
 	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]));
+	ut_asserteq_ptr(&s1[1], strstr(s1, &s3[2]));
+	ut_asserteq_ptr(&s1[7], strstr(&s1[5], &s3[2]));
 
 	return 0;
 }
 LIB_TEST(lib_strstr, 0);
 
+/** lib_strcasestr() - unit test for strcasestr() */
+static int lib_strcasestr(struct unit_test_state *uts)
+{
+	const char *s1 = "Itsy Bitsy Teenie Weenie";
+	const char *s2 = "eenie";
+	const char *s3 = "bits";
+
+	ut_asserteq_ptr(&s1[12], strcasestr(s1, s2));
+	ut_asserteq_ptr(&s1[13], strcasestr(&s1[3], &s2[1]));
+	ut_asserteq_ptr(&s1[5], strcasestr(s1, s3));
+	ut_asserteq_ptr(&s1[1], strcasestr(s1, &s3[2]));
+	ut_asserteq_ptr(&s1[7], strcasestr(&s1[5], &s3[2]));
+	ut_assertnull(strcasestr(&s1[6], s3));
+
+	return 0;
+}
+LIB_TEST(lib_strcasestr, 0);
+
 static int lib_strim(struct unit_test_state *uts)
 {
 	char buf[BUFLEN], *p;
-- 
2.54.0



More information about the U-Boot mailing list