brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · bad3749 Raw
58 lines · cpp
1//===-- Unittests for wcslcat ---------------------------------------------===//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/size_t.h"10#include "hdr/types/wchar_t.h"11#include "src/wchar/wcslcat.h"12#include "test/UnitTest/Test.h"13 14TEST(LlvmLibcWCSLCatTest, TooBig) {15  const wchar_t *src = L"cd";16  wchar_t dst[4]{L"ab"};17  size_t res = LIBC_NAMESPACE::wcslcat(dst, src, 3);18  ASSERT_TRUE(dst[0] == L'a');19  ASSERT_TRUE(dst[1] == L'b');20  ASSERT_TRUE(dst[2] == L'\0');21  // Should still return src length + dst length22  ASSERT_EQ(res, size_t(4));23  // Not enough space to copy d24  res = LIBC_NAMESPACE::wcslcat(dst, src, 4);25  ASSERT_TRUE(dst[0] == L'a');26  ASSERT_TRUE(dst[1] == L'b');27  ASSERT_TRUE(dst[2] == L'c');28  ASSERT_TRUE(dst[3] == L'\0');29  ASSERT_EQ(res, size_t(4));30}31 32TEST(LlvmLibcWCSLCatTest, Smaller) {33  const wchar_t *src = L"cd";34  wchar_t dst[7]{L"ab"};35  size_t res = LIBC_NAMESPACE::wcslcat(dst, src, 7);36  ASSERT_TRUE(dst[0] == L'a');37  ASSERT_TRUE(dst[1] == L'b');38  ASSERT_TRUE(dst[2] == L'c');39  ASSERT_TRUE(dst[3] == L'd');40  ASSERT_TRUE(dst[4] == L'\0');41  ASSERT_EQ(res, size_t(4));42}43 44TEST(LlvmLibcWCSLCatTest, SmallerNoOverwriteAfter0) {45  const wchar_t *src = L"cd";46  wchar_t dst[8]{L"ab\0\0efg"};47  size_t res = LIBC_NAMESPACE::wcslcat(dst, src, 8);48  ASSERT_TRUE(dst[0] == L'a');49  ASSERT_TRUE(dst[1] == L'b');50  ASSERT_TRUE(dst[2] == L'c');51  ASSERT_TRUE(dst[3] == L'd');52  ASSERT_TRUE(dst[4] == L'\0');53  ASSERT_TRUE(dst[5] == L'f');54  ASSERT_TRUE(dst[6] == L'g');55  ASSERT_TRUE(dst[7] == L'\0');56  ASSERT_EQ(res, size_t(4));57}58