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 "utils/UnitTest/Test.h"
11 
TEST(StrCpyTest,EmptyDest)12 TEST(StrCpyTest, EmptyDest) {
13   const char *abc = "abc";
14   char dest[4];
15 
16   char *result = __llvm_libc::strcpy(dest, abc);
17   ASSERT_EQ(dest, result);
18   ASSERT_STREQ(dest, result);
19   ASSERT_STREQ(dest, abc);
20 }
21 
TEST(StrCpyTest,OffsetDest)22 TEST(StrCpyTest, OffsetDest) {
23   const char *abc = "abc";
24   char dest[7];
25 
26   dest[0] = 'x';
27   dest[1] = 'y';
28   dest[2] = 'z';
29 
30   char *result = __llvm_libc::strcpy(dest + 3, abc);
31   ASSERT_EQ(dest + 3, result);
32   ASSERT_STREQ(dest + 3, result);
33   ASSERT_STREQ(dest, "xyzabc");
34 }
35