[PATCH master 8/8] test: self: printf: add tests for formatting wide strings

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Mar 19 22:16:41 PDT 2025


Let's repeat the same string tests we already have, but with wide (%ls)
strings instead of our normal ones.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 test/self/printf.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/test/self/printf.c b/test/self/printf.c
index eae40ed242c1..3f35b5514705 100644
--- a/test/self/printf.c
+++ b/test/self/printf.c
@@ -179,6 +179,20 @@ test_string(void)
 	test("      1234", "%10.4s", "123456");
 }
 
+static void __init
+test_wstring(void)
+{
+	if (!IS_ENABLED(CONFIG_PRINTF_WCHAR))
+		return;
+
+	test("", "%ls%.0ls", L"", L"123");
+	test("ABCD|abc|123", "%ls|%.3ls|%.*ls", L"ABCD", L"abcdef", 3, L"123456");
+	test("1  |  2|3  |  4|5  ", "%-3ls|%3ls|%-*ls|%*ls|%*ls",
+	     L"1", L"2", 3, L"3", 3, L"4", -3, L"5");
+	test("1234      ", "%-10.4ls", L"123456");
+	test("      1234", "%10.4ls", L"123456");
+}
+
 #if BITS_PER_LONG == 64
 
 #define PTR_WIDTH 16
@@ -331,6 +345,7 @@ static void __init test_printf(void)
 	test_basic();
 	test_number();
 	test_string();
+	test_wstring();
 	test_pointer();
 	test_hexstr();
 	test_jsonpath();
-- 
2.39.5




More information about the barebox mailing list