1 //===-- Unittests for strlcat ---------------------------------------------===// 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/strlcat.h" 10 #include "utils/UnitTest/Test.h" 11 #include <stdlib.h> 12 13 TEST(LlvmLibcStrlcatTest, TooBig) { 14 const char *str = "cd"; 15 char buf[4]{"ab"}; 16 EXPECT_EQ(__llvm_libc::strlcat(buf, str, 3), size_t(4)); 17 EXPECT_STREQ(buf, "ab"); 18 EXPECT_EQ(__llvm_libc::strlcat(buf, str, 4), size_t(4)); 19 EXPECT_STREQ(buf, "abc"); 20 } 21 22 TEST(LlvmLibcStrlcatTest, Smaller) { 23 const char *str = "cd"; 24 char buf[7]{"ab"}; 25 26 EXPECT_EQ(__llvm_libc::strlcat(buf, str, 7), size_t(4)); 27 EXPECT_STREQ(buf, "abcd"); 28 } 29 30 TEST(LlvmLibcStrlcatTest, No0) { 31 const char *str = "cd"; 32 char buf[7]{"ab"}; 33 EXPECT_EQ(__llvm_libc::strlcat(buf, str, 1), size_t(3)); 34 EXPECT_STREQ(buf, "ab"); 35 EXPECT_EQ(__llvm_libc::strlcat(buf, str, 2), size_t(4)); 36 EXPECT_STREQ(buf, "ab"); 37 } 38