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

source code of libc/test/src/string/strlcat_test.cpp