1 //===-- Unittests for strlcat ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strlcat.h"
10 #include "test/UnitTest/Test.h"
12 TEST(LlvmLibcStrlcatTest
, TooBig
) {
13 const char *str
= "cd";
15 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 3), size_t(4));
16 EXPECT_STREQ(buf
, "ab");
17 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 4), size_t(4));
18 EXPECT_STREQ(buf
, "abc");
21 TEST(LlvmLibcStrlcatTest
, Smaller
) {
22 const char *str
= "cd";
25 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 7), size_t(4));
26 EXPECT_STREQ(buf
, "abcd");
29 TEST(LlvmLibcStrlcatTest
, SmallerNoOverwriteAfter0
) {
30 const char *str
= "cd";
31 char buf
[8]{"ab\0\0efg"};
33 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 8), size_t(4));
34 EXPECT_STREQ(buf
, "abcd");
35 EXPECT_STREQ(buf
+ 5, "fg");
38 TEST(LlvmLibcStrlcatTest
, No0
) {
39 const char *str
= "cd";
41 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 1), size_t(3));
42 EXPECT_STREQ(buf
, "ab");
43 EXPECT_EQ(LIBC_NAMESPACE::strlcat(buf
, str
, 2), size_t(4));
44 EXPECT_STREQ(buf
, "ab");