[libc-commits] [libc] [libc][search] implement POSIX `lsearch` function (PR #116870)
via libc-commits
libc-commits at lists.llvm.org
Wed Nov 27 09:27:07 PST 2024
================
@@ -0,0 +1,79 @@
+//===-- Unittests for lsearch ---------------------------------------------===//
+//
+// 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/search/lsearch.h"
+#include "test/UnitTest/Test.h"
+
+int compar(const void *a, const void *b) {
+ return *reinterpret_cast<const int *>(a) != *reinterpret_cast<const int *>(b);
+}
+
+TEST(LlvmLibcLsearchTest, SearchHead) {
+ int list[4] = {1, 2, 3, 4};
+ size_t len = 3;
+ int key = 1;
+ void *ret = LIBC_NAMESPACE::lsearch(&key, list, &len, sizeof(int), compar);
+
+ ASSERT_EQ(static_cast<int *>(ret), &list[0]);
+ ASSERT_EQ(len, static_cast<size_t>(3));
+ ASSERT_EQ(list[1], 2);
+ ASSERT_EQ(list[2], 3);
+ ASSERT_EQ(list[3], 4);
+ ASSERT_EQ(list[3], 4);
----------------
duncpro wrote:
resolved by [47f7800](https://github.com/llvm/llvm-project/pull/116870/commits/47f780083d8041a4cddffc484294067a22bf6e58)
https://github.com/llvm/llvm-project/pull/116870
More information about the libc-commits
mailing list