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 12 TEST(LlvmLibcStrCpyTest, EmptySrc) { 13 const char *empty = ""; 14 char dest[4] = {'a', 'b', 'c', '\0'}; 15 16 char *result = __llvm_libc::strcpy(dest, empty); 17 ASSERT_EQ(dest, result); 18 ASSERT_STREQ(dest, result); 19 ASSERT_STREQ(dest, empty); 20 } 21 22 TEST(LlvmLibcStrCpyTest, EmptyDest) { 23 const char *abc = "abc"; 24 char dest[4]; 25 26 char *result = __llvm_libc::strcpy(dest, abc); 27 ASSERT_EQ(dest, result); 28 ASSERT_STREQ(dest, result); 29 ASSERT_STREQ(dest, abc); 30 } 31 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 = __llvm_libc::strcpy(dest + 3, abc); 41 ASSERT_EQ(dest + 3, result); 42 ASSERT_STREQ(dest + 3, result); 43 ASSERT_STREQ(dest, "xyzabc"); 44 } 45