brintos

brintos / llvm-project-archived public Read only

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