brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · eafbb2d Raw
49 lines · cpp
1//===-- Unittests for wcsdup ----------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "hdr/types/wchar_t.h"10#include "src/wchar/wcsdup.h"11#include "test/UnitTest/ErrnoCheckingTest.h"12#include "test/UnitTest/Test.h"13 14using LlvmLibcWcsDupTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;15 16TEST_F(LlvmLibcWcsDupTest, EmptyString) {17  const wchar_t *empty = L"";18 19  wchar_t *result = LIBC_NAMESPACE::wcsdup(empty);20  ASSERT_ERRNO_SUCCESS();21 22  ASSERT_NE(result, static_cast<wchar_t *>(nullptr));23  ASSERT_NE(empty, const_cast<const wchar_t *>(result));24  ASSERT_TRUE(empty[0] == result[0]);25  ::free(result);26}27 28TEST_F(LlvmLibcWcsDupTest, AnyString) {29  const wchar_t *abc = L"abc";30 31  wchar_t *result = LIBC_NAMESPACE::wcsdup(abc);32  ASSERT_ERRNO_SUCCESS();33 34  ASSERT_NE(result, static_cast<wchar_t *>(nullptr));35  ASSERT_NE(abc, const_cast<const wchar_t *>(result));36  ASSERT_TRUE(abc[0] == result[0]);37  ASSERT_TRUE(abc[1] == result[1]);38  ASSERT_TRUE(abc[2] == result[2]);39  ASSERT_TRUE(abc[3] == result[3]);40  ::free(result);41}42 43TEST_F(LlvmLibcWcsDupTest, NullPtr) {44  wchar_t *result = LIBC_NAMESPACE::wcsdup(nullptr);45  ASSERT_ERRNO_SUCCESS();46 47  ASSERT_EQ(result, static_cast<wchar_t *>(nullptr));48}49