Make test more lenient for custom clang version strings
[llvm-project.git] / libc / test / src / string / strxfrm_test.cpp
blobb704dbf6052fcbb2aabcec7ccf907eef5ad63c26
1 //===-- Unittests for strxfrm ---------------------------------------------===//
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 //===----------------------------------------------------------------------===//
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";
18 const size_t n = 5;
20 char dest[n];
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";
28 const size_t n = 4;
30 char dest[n];
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";
38 const size_t n = 3;
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);
43 ASSERT_GE(result, n);
44 ASSERT_STREQ(dest, "xx");