[libc-commits] [libc] [llvm] [libc] wcslcpy implementation (PR #146571)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Jul 8 10:52:36 PDT 2025
================
@@ -0,0 +1,51 @@
+//===-- Unittests for wcslcpy ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/types/size_t.h"
+#include "hdr/types/wchar_t.h"
+#include "src/wchar/wcslcpy.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcWCSLCpyTest, BiggerSource) {
+ const wchar_t *src = L"abcde";
+ wchar_t dst[3];
+ size_t res = LIBC_NAMESPACE::wcslcpy(dst, src, 3);
+ ASSERT_TRUE(dst[0] == L'a');
+ ASSERT_TRUE(dst[1] == L'b');
+ // Should append null terminator
+ ASSERT_TRUE(dst[2] == L'\0');
+ // Should still return length of src
+ ASSERT_EQ(res, size_t(5));
+}
+
+TEST(LlvmLibcWCSLCpyTest, CopyZero) {
+ const wchar_t *src = L"abcde";
+ wchar_t dst = L'f';
+ // Copying zero should not change destination
+ size_t res = LIBC_NAMESPACE::wcslcpy(&dst, src, 0);
+ ASSERT_TRUE(dst == L'f');
+ // Should still return length of src
+ ASSERT_EQ(res, size_t(5));
+}
+
+TEST(LlvmLibcWCSLCpyTest, SmallerSource) {
+ const wchar_t *src = L"abc";
+ wchar_t dst[7]{L"111111"};
----------------
michaelrj-google wrote:
nit: change this to `123456` or similar to make it more clear how many there are
https://github.com/llvm/llvm-project/pull/146571
More information about the libc-commits
mailing list