summaryrefslogtreecommitdiff
path: root/libc/test/src/string
diff options
context:
space:
mode:
authorAlex Brachet <abrachet@google.com>2022-05-19 21:47:28 +0000
committerAlex Brachet <abrachet@google.com>2022-05-19 21:48:39 +0000
commitb1183305f882f15a368cc33ed9b2f77aedb5b9a6 (patch)
treecb777194ee849529bbec278d071c40b1fa257e2b /libc/test/src/string
parent027499a82434ea7a784b2e5a0227540f00fbc307 (diff)
[libc] Add strlcat
Differential Revision: https://reviews.llvm.org/D125978
Diffstat (limited to 'libc/test/src/string')
-rw-r--r--libc/test/src/string/CMakeLists.txt10
-rw-r--r--libc/test/src/string/strlcat_test.cpp37
2 files changed, 47 insertions, 0 deletions
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index 5bdb47a7e672..e60f9ab3d399 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -124,6 +124,16 @@ add_libc_unittest(
)
add_libc_unittest(
+ strlcat_test
+ SUITE
+ libc_string_unittests
+ SRCS
+ strlcat_test.cpp
+ DEPENDS
+ libc.src.string.strlcat
+)
+
+add_libc_unittest(
strlcpy_test
SUITE
libc_string_unittests
diff --git a/libc/test/src/string/strlcat_test.cpp b/libc/test/src/string/strlcat_test.cpp
new file mode 100644
index 000000000000..66db15e58927
--- /dev/null
+++ b/libc/test/src/string/strlcat_test.cpp
@@ -0,0 +1,37 @@
+//===-- Unittests for strlcat ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/string/strlcat.h"
+#include "utils/UnitTest/Test.h"
+#include <stdlib.h>
+
+TEST(LlvmLibcStrlcatTest, TooBig) {
+ const char *str = "cd";
+ char buf[4]{"ab"};
+ EXPECT_EQ(__llvm_libc::strlcat(buf, str, 3), size_t(4));
+ EXPECT_STREQ(buf, "ab");
+ EXPECT_EQ(__llvm_libc::strlcat(buf, str, 4), size_t(4));
+ EXPECT_STREQ(buf, "abc");
+}
+
+TEST(LlvmLibcStrlcatTest, Smaller) {
+ const char *str = "cd";
+ char buf[7]{"ab"};
+
+ EXPECT_EQ(__llvm_libc::strlcat(buf, str, 7), size_t(4));
+ EXPECT_STREQ(buf, "abcd");
+}
+
+TEST(LlvmLibcStrlcatTest, No0) {
+ const char *str = "cd";
+ char buf[7]{"ab"};
+ EXPECT_EQ(__llvm_libc::strlcat(buf, str, 1), size_t(3));
+ EXPECT_STREQ(buf, "ab");
+ EXPECT_EQ(__llvm_libc::strlcat(buf, str, 2), size_t(4));
+ EXPECT_STREQ(buf, "ab");
+}