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 <string>
10 
11 #include "src/string/strcpy.h"
12 #include "gtest/gtest.h"
13 
14 TEST(StrCpyTest, EmptyDest) {
15   std::string abc = "abc";
16   char dest[4];
17 
18   char *result = __llvm_libc::strcpy(dest, abc.c_str());
19   ASSERT_EQ(dest, result);
20   ASSERT_EQ(std::string(dest), abc);
21   ASSERT_EQ(std::string(dest).size(), abc.size());
22 }
23 
24 TEST(StrCpyTest, OffsetDest) {
25   std::string abc = "abc";
26   char dest[7];
27 
28   dest[0] = 'x';
29   dest[1] = 'y';
30   dest[2] = 'z';
31 
32   char *result = __llvm_libc::strcpy(dest + 3, abc.c_str());
33   ASSERT_EQ(dest + 3, result);
34   ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
35   ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
36 }
37