1fc2c8b23SAlex Brachet //===-- Unittests for strlcpy ---------------------------------------------===// 2fc2c8b23SAlex Brachet // 3fc2c8b23SAlex Brachet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fc2c8b23SAlex Brachet // See https://llvm.org/LICENSE.txt for license information. 5fc2c8b23SAlex Brachet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fc2c8b23SAlex Brachet // 7fc2c8b23SAlex Brachet //===----------------------------------------------------------------------===// 8fc2c8b23SAlex Brachet 9fc2c8b23SAlex Brachet #include "src/string/strlcpy.h" 10af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h" 11fc2c8b23SAlex Brachet 12fc2c8b23SAlex Brachet TEST(LlvmLibcStrlcpyTest, TooBig) { 13fc2c8b23SAlex Brachet const char *str = "abc"; 14fc2c8b23SAlex Brachet char buf[2]; 15b6bc9d72SGuillaume Chatelet EXPECT_EQ(LIBC_NAMESPACE::strlcpy(buf, str, 2), size_t(3)); 16fc2c8b23SAlex Brachet EXPECT_STREQ(buf, "a"); 17fc2c8b23SAlex Brachet 18b6bc9d72SGuillaume Chatelet EXPECT_EQ(LIBC_NAMESPACE::strlcpy(nullptr, str, 0), size_t(3)); 19fc2c8b23SAlex Brachet } 20fc2c8b23SAlex Brachet 21fc2c8b23SAlex Brachet TEST(LlvmLibcStrlcpyTest, Smaller) { 22fc2c8b23SAlex Brachet const char *str = "abc"; 23fc2c8b23SAlex Brachet char buf[7]{"111111"}; 24fc2c8b23SAlex Brachet 25b6bc9d72SGuillaume Chatelet EXPECT_EQ(LIBC_NAMESPACE::strlcpy(buf, str, 7), size_t(3)); 26fc2c8b23SAlex Brachet EXPECT_STREQ(buf, "abc"); 27*b03c8c4fSGeorge Burgess IV EXPECT_STREQ(buf + 4, "11"); 28fc2c8b23SAlex Brachet } 29