1 //===-- Unittests for strlcpy ---------------------------------------------===//
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/strlcpy.h"
10 #include "test/UnitTest/Test.h"
12 TEST(LlvmLibcStrlcpyTest
, TooBig
) {
13 const char *str
= "abc";
15 EXPECT_EQ(LIBC_NAMESPACE::strlcpy(buf
, str
, 2), size_t(3));
16 EXPECT_STREQ(buf
, "a");
18 EXPECT_EQ(LIBC_NAMESPACE::strlcpy(nullptr, str
, 0), size_t(3));
21 TEST(LlvmLibcStrlcpyTest
, Smaller
) {
22 const char *str
= "abc";
23 char buf
[7]{"111111"};
25 EXPECT_EQ(LIBC_NAMESPACE::strlcpy(buf
, str
, 7), size_t(3));
26 EXPECT_STREQ(buf
, "abc");
27 EXPECT_STREQ(buf
+ 4, "11");