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