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

source code of libc/test/src/string/stpcpy_test.cpp