1 | //===-- Unittests for wcscat ---------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "hdr/types/wchar_t.h" |
10 | #include "src/wchar/wcscat.h" |
11 | #include "test/UnitTest/Test.h" |
12 | |
13 | TEST(LlvmLibcWCSCatTest, EmptyDest) { |
14 | // Dest should be fully replaced with src. |
15 | wchar_t dest[4] = {L'\0'}; |
16 | const wchar_t *src = L"abc" ; |
17 | LIBC_NAMESPACE::wcscat(dest, src); |
18 | ASSERT_TRUE(dest[0] == L'a'); |
19 | ASSERT_TRUE(dest[1] == L'b'); |
20 | ASSERT_TRUE(dest[2] == L'c'); |
21 | ASSERT_TRUE(dest[3] == L'\0'); |
22 | } |
23 | |
24 | TEST(LlvmLibcWCSCatTest, NonEmptyDest) { |
25 | // Src should be appended on to dest. |
26 | wchar_t dest[7] = {L'x', L'y', L'z', L'\0'}; |
27 | const wchar_t *src = L"abc" ; |
28 | LIBC_NAMESPACE::wcscat(dest, src); |
29 | ASSERT_TRUE(dest[0] == L'x'); |
30 | ASSERT_TRUE(dest[1] == L'y'); |
31 | ASSERT_TRUE(dest[2] == L'z'); |
32 | ASSERT_TRUE(dest[3] == L'a'); |
33 | ASSERT_TRUE(dest[4] == L'b'); |
34 | ASSERT_TRUE(dest[5] == L'c'); |
35 | ASSERT_TRUE(dest[6] == L'\0'); |
36 | } |
37 | |
38 | TEST(LlvmLibcWCSCatTest, EmptySrc) { |
39 | // Dest should remain intact. |
40 | wchar_t dest[4] = {L'x', L'y', L'z', L'\0'}; |
41 | const wchar_t *src = L"" ; |
42 | LIBC_NAMESPACE::wcscat(dest, src); |
43 | ASSERT_TRUE(dest[0] == L'x'); |
44 | ASSERT_TRUE(dest[1] == L'y'); |
45 | ASSERT_TRUE(dest[2] == L'z'); |
46 | ASSERT_TRUE(dest[3] == L'\0'); |
47 | } |
48 | |