1//===-- Unittests for mempcpy ---------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8#include "hdr/signal_macros.h"
9#include "src/string/mempcpy.h"
10#include "test/UnitTest/Test.h"
11
12// Since this function just calls out to memcpy, and memcpy has its own unit
13// tests, it is assumed that memcpy works. These tests are just for the specific
14// mempcpy behavior (returning the end of what was copied).
15TEST(LlvmLibcMempcpyTest, Simple) {
16 const char *src = "12345";
17 char dest[10] = {};
18 void *result = LIBC_NAMESPACE::mempcpy(dest, src, 6);
19 ASSERT_EQ(static_cast<char *>(result), dest + 6);
20 ASSERT_STREQ(src, dest);
21}
22
23TEST(LlvmLibcMempcpyTest, ZeroCount) {
24 const char *src = "12345";
25 char dest[10];
26 void *result = LIBC_NAMESPACE::mempcpy(dest, src, 0);
27 ASSERT_EQ(static_cast<char *>(result), dest + 0);
28}
29
30#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
31
32TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) {
33 ASSERT_DEATH([]() { LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 1); },
34 WITH_SIGNAL(-1));
35}
36
37#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
38

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of libc/test/src/string/mempcpy_test.cpp