1 //===-- Unittests for stpcpy ----------------------------------------------===//
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/stpcpy.h"
10 #include "test/UnitTest/Test.h"
12 #include "src/string/string_utils.h"
14 TEST(LlvmLibcStpCpyTest
, EmptySrc
) {
15 const char *empty
= "";
16 size_t src_size
= LIBC_NAMESPACE::internal::string_length(empty
);
17 char dest
[4] = {'a', 'b', 'c', '\0'};
19 char *result
= LIBC_NAMESPACE::stpcpy(dest
, empty
);
20 ASSERT_EQ(dest
+ src_size
, result
);
21 ASSERT_EQ(result
[0], '\0');
22 ASSERT_STREQ(dest
, empty
);
25 TEST(LlvmLibcStpCpyTest
, EmptyDest
) {
26 const char *abc
= "abc";
27 size_t src_size
= LIBC_NAMESPACE::internal::string_length(abc
);
30 char *result
= LIBC_NAMESPACE::stpcpy(dest
, abc
);
31 ASSERT_EQ(dest
+ src_size
, result
);
32 ASSERT_EQ(result
[0], '\0');
33 ASSERT_STREQ(dest
, abc
);
36 TEST(LlvmLibcStpCpyTest
, OffsetDest
) {
37 const char *abc
= "abc";
38 size_t src_size
= LIBC_NAMESPACE::internal::string_length(abc
);
39 char dest
[7] = {'x', 'y', 'z'};
41 char *result
= LIBC_NAMESPACE::stpcpy(dest
+ 3, abc
);
42 ASSERT_EQ(dest
+ 3 + src_size
, result
);
43 ASSERT_EQ(result
[0], '\0');
44 ASSERT_STREQ(dest
, "xyzabc");