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