1 //===-- Unittests for strxfrm ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strxfrm.h"
10 #include "test/UnitTest/Test.h"
12 #include "src/string/string_utils.h"
14 // TODO: Add more comprehensive tests once locale support is added.
16 TEST(LlvmLibcStrxfrmTest
, SimpleTestSufficientlySizedN
) {
17 const char *src
= "abc";
21 size_t result
= LIBC_NAMESPACE::strxfrm(dest
, src
, n
);
22 ASSERT_EQ(result
, LIBC_NAMESPACE::internal::string_length(src
));
23 ASSERT_STREQ(dest
, src
);
26 TEST(LlvmLibcStrxfrmTest
, SimpleTestExactSizedN
) {
27 const char *src
= "abc";
31 size_t result
= LIBC_NAMESPACE::strxfrm(dest
, src
, n
);
32 ASSERT_EQ(result
, LIBC_NAMESPACE::internal::string_length(src
));
33 ASSERT_STREQ(dest
, src
);
36 TEST(LlvmLibcStrxfrmTest
, SimpleTestInsufficientlySizedN
) {
37 const char *src
= "abc";
40 // Verify strxfrm does not modify dest if src len >= n
41 char dest
[n
] = {'x', 'x', '\0'};
42 size_t result
= LIBC_NAMESPACE::strxfrm(dest
, src
, n
);
44 ASSERT_STREQ(dest
, "xx");