[PATCH v2 2/2] test: Add a test for strim()
Simon Glass
sjg at chromium.org
Thu May 1 13:10:09 CEST 2025
This function trims whitespace from the start and end of a string. Add a
test for it.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2:
- Bring in strim() update from Linux and adjust tests
test/lib/string.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/test/lib/string.c b/test/lib/string.c
index 8d22f3fd68f..d039f209a8c 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -221,3 +221,40 @@ static int lib_memdup(struct unit_test_state *uts)
return 0;
}
LIB_TEST(lib_memdup, 0);
+
+static int lib_strim(struct unit_test_state *uts)
+{
+ char buf[BUFLEN], *p;
+
+ strcpy(buf, "abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* leading space */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple leading spaces */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple internal spaces */
+ strcpy(buf, " a bc");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with trailing space */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with multiple trailing spaces */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with only spaces */
+ strcpy(buf, " ");
+ p = strim(buf);
+ ut_asserteq_ptr(p, buf);
+ ut_asserteq_str("", p);
+
+ return 0;
+}
+LIB_TEST(lib_strim, 0);
--
2.43.0
base-commit: b5d6220dd2f4612912989f3c2b5a710f2248cb36
branch: schn2
More information about the U-Boot
mailing list