brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · c59b61f Raw
51 lines · cpp
1//===-- Unittests for wcpcpy ---------------------------------------------===//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/wcpcpy.h"11#include "test/UnitTest/Test.h"12 13TEST(LlvmLibcWCPCpyTest, EmptySrc) {14  // Empty src should lead to empty destination.15  wchar_t dest[4] = {L'a', L'b', L'c', L'\0'};16  const wchar_t *src = L"";17  LIBC_NAMESPACE::wcpcpy(dest, src);18  ASSERT_TRUE(dest[0] == src[0]);19  ASSERT_TRUE(dest[0] == L'\0');20}21 22TEST(LlvmLibcWCPCpyTest, EmptyDest) {23  // Empty dest should result in src24  const wchar_t *src = L"abc";25  wchar_t dest[4];26  wchar_t *result = LIBC_NAMESPACE::wcpcpy(dest, src);27  ASSERT_EQ(dest + 3, result);28  ASSERT_TRUE(result[0] == L'\0');29  ASSERT_TRUE(dest[0] == L'a');30  ASSERT_TRUE(dest[1] == L'b');31  ASSERT_TRUE(dest[2] == L'c');32}33 34TEST(LlvmLibcWCPCpyTest, OffsetDest) {35  // Offsetting should result in a concatenation.36  const wchar_t *src = L"abc";37  wchar_t dest[7];38  dest[0] = L'x';39  dest[1] = L'y';40  dest[2] = L'z';41  wchar_t *result = LIBC_NAMESPACE::wcpcpy(dest + 3, src);42  ASSERT_TRUE(dest[0] == L'x');43  ASSERT_TRUE(dest[1] == L'y');44  ASSERT_TRUE(dest[2] == L'z');45  ASSERT_TRUE(dest[3] == src[0]);46  ASSERT_TRUE(dest[4] == src[1]);47  ASSERT_TRUE(dest[5] == src[2]);48  ASSERT_TRUE(result[0] == L'\0');49  ASSERT_EQ(dest + 6, result);50}51