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