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