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