[libc-commits] [libc] [libc] Implement mbsinit (PR #150654)
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 25 10:20:36 PDT 2025
================
@@ -0,0 +1,34 @@
+//===-- Unittests for mbsinit
+//----------------------------------------------===//
+//
+// 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 "hdr/types/wchar_t.h"
+#include "src/string/memset.h"
+#include "src/wchar/mbrtowc.h"
+#include "src/wchar/mbsinit.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcMBSInitTest, EmptyState) {
+ mbstate_t ps;
+ LIBC_NAMESPACE::memset(&ps, 0, sizeof(mbstate_t));
+ ASSERT_NE(LIBC_NAMESPACE::mbsinit(&ps), 0);
+ ASSERT_NE(LIBC_NAMESPACE::mbsinit(nullptr), 0);
+}
+
+TEST(LlvmLibcMBSInitTest, ConversionTest) {
+ const char *src = "\xf0\x9f\xa4\xa3"; // 4 byte emoji
+ wchar_t dest[2];
+ mbstate_t ps;
+ LIBC_NAMESPACE::memset(&ps, 0, sizeof(mbstate_t));
+
+ ASSERT_NE(LIBC_NAMESPACE::mbsinit(&ps), 0);
----------------
sribee8 wrote:
shouldn't it return non zero here since it's in its initial conversion state?
https://github.com/llvm/llvm-project/pull/150654
More information about the libc-commits
mailing list