diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-10-16 10:31:04 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-17 17:09:58 +0100 |
commit | 13e6d9d71a57d6127207af66b708f545719064da (patch) | |
tree | b29822b2662554dae0772fe05a1dad1dcd37aa19 /Tests/LibC/TestWchar.cpp | |
parent | e6164d35fade3bd5e74ff2a06251e9e1eb1e3118 (diff) | |
download | serenity-13e6d9d71a57d6127207af66b708f545719064da.zip |
LibC: Implement wcslcpy
Diffstat (limited to 'Tests/LibC/TestWchar.cpp')
-rw-r--r-- | Tests/LibC/TestWchar.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Tests/LibC/TestWchar.cpp b/Tests/LibC/TestWchar.cpp index a158f33748..dc173eccb4 100644 --- a/Tests/LibC/TestWchar.cpp +++ b/Tests/LibC/TestWchar.cpp @@ -414,3 +414,28 @@ TEST_CASE(mbsrtowcs) EXPECT_EQ(buf[2], L'\0'); EXPECT_EQ(src, nullptr); } + +TEST_CASE(wcslcpy) +{ + auto buf = static_cast<wchar_t*>(malloc(8 * sizeof(wchar_t))); + if (!buf) { + FAIL("Could not allocate space for copy target"); + return; + } + + size_t ret; + + // If buffer is long enough, a straight-forward string copy is performed. + ret = wcslcpy(buf, L"abc", 8); + EXPECT_EQ(ret, 3ul); + EXPECT_EQ(wmemcmp(L"abc", buf, 4), 0); + + // If buffer is (supposedly) too small, the string will be truncated. + ret = wcslcpy(buf, L"1234", 4); + EXPECT_EQ(ret, 4ul); + EXPECT_EQ(wmemcmp(L"123", buf, 4), 0); + + // If the buffer is null, the length of the input is returned. + ret = wcslcpy(nullptr, L"abc", 0); + EXPECT_EQ(ret, 3ul); +} |