1db8a88feSMichael Jones //===-- Unittests for mempcpy ---------------------------------------------===//
2db8a88feSMichael Jones //
3db8a88feSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4db8a88feSMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5db8a88feSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6db8a88feSMichael Jones //
7db8a88feSMichael Jones //===----------------------------------------------------------------------===//
8db8a88feSMichael Jones
9db8a88feSMichael Jones #include "src/string/mempcpy.h"
10af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h"
11db8a88feSMichael Jones
12db8a88feSMichael Jones // Since this function just calls out to memcpy, and memcpy has its own unit
13db8a88feSMichael Jones // tests, it is assumed that memcpy works. These tests are just for the specific
14db8a88feSMichael Jones // mempcpy behavior (returning the end of what was copied).
TEST(LlvmLibcMempcpyTest,Simple)15db8a88feSMichael Jones TEST(LlvmLibcMempcpyTest, Simple) {
16db8a88feSMichael Jones const char *src = "12345";
17*7c6b4be6SNick Desaulniers char dest[10] = {};
18b6bc9d72SGuillaume Chatelet void *result = LIBC_NAMESPACE::mempcpy(dest, src, 6);
19db8a88feSMichael Jones ASSERT_EQ(static_cast<char *>(result), dest + 6);
20db8a88feSMichael Jones ASSERT_STREQ(src, dest);
21db8a88feSMichael Jones }
22db8a88feSMichael Jones
TEST(LlvmLibcMempcpyTest,ZeroCount)23db8a88feSMichael Jones TEST(LlvmLibcMempcpyTest, ZeroCount) {
24db8a88feSMichael Jones const char *src = "12345";
25db8a88feSMichael Jones char dest[10];
26b6bc9d72SGuillaume Chatelet void *result = LIBC_NAMESPACE::mempcpy(dest, src, 0);
279902fc8dSGuillaume Chatelet ASSERT_EQ(static_cast<char *>(result), dest + 0);
28db8a88feSMichael Jones }
29