summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorsafarp <safar.pavel@gmail.com>2022-03-20 09:53:52 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-03-30 11:30:43 +0430
commit704e1d13f46f33302f80698018e86554a5006d14 (patch)
tree70a7a11eb578703e85fc3d7c76f7aa00690426dc /Tests
parent824cf570d30888a4309274d467c7c22dde884a69 (diff)
downloadserenity-704e1d13f46f33302f80698018e86554a5006d14.zip
AK: Allow printing wide characters using %ls modifier
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/CMakeLists.txt1
-rw-r--r--Tests/AK/TestPrint.cpp58
2 files changed, 59 insertions, 0 deletions
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt
index fac063f6fd..38b066fcbe 100644
--- a/Tests/AK/CMakeLists.txt
+++ b/Tests/AK/CMakeLists.txt
@@ -48,6 +48,7 @@ set(AK_TEST_SOURCES
TestNonnullRefPtr.cpp
TestNumberFormat.cpp
TestOptional.cpp
+ TestPrint.cpp
TestQueue.cpp
TestQuickSort.cpp
TestRedBlackTree.cpp
diff --git a/Tests/AK/TestPrint.cpp b/Tests/AK/TestPrint.cpp
new file mode 100644
index 0000000000..780415cce0
--- /dev/null
+++ b/Tests/AK/TestPrint.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2022, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibTest/TestCase.h>
+#include <wchar.h>
+
+TEST_CASE(swprint_no_format)
+{
+ wchar_t buffer[256];
+ size_t len = swprintf(buffer, 64, L"Well, hello friends!");
+
+ VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
+ VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
+ VERIFY(wcslen(buffer) == len);
+}
+
+TEST_CASE(swprint_single_wchar_argument)
+{
+ wchar_t buffer[256];
+ size_t len = swprintf(buffer, 64, L"Well, %ls friends!", L"hello");
+
+ VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
+ VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
+ VERIFY(wcslen(buffer) == len);
+}
+
+TEST_CASE(swprint_single_char_argument)
+{
+ wchar_t buffer[256];
+ size_t len = swprintf(buffer, 64, L"Well, %s friends!", "hello");
+
+ VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
+ VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
+ VERIFY(wcslen(buffer) == len);
+}
+
+TEST_CASE(swprint_single_narrow_char_argument)
+{
+ wchar_t buffer[256];
+ size_t len = swprintf(buffer, 64, L"Well, %hs friends!", "hello");
+
+ VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
+ VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
+ VERIFY(wcslen(buffer) == len);
+}
+
+TEST_CASE(swprint_mixed_arguments)
+{
+ wchar_t buffer[256];
+ size_t len = swprintf(buffer, 64, L"Well, %ls friends! %hs is less then %s.", L"hello", "10", "20");
+
+ VERIFY(wcscmp(buffer, L"Well, hello friends! 10 is less then 20.") == 0);
+ VERIFY(wcscmp(buffer, L"Well, hello friends! 10 is less then 2.") != 0);
+ VERIFY(wcslen(buffer) == len);
+}