2020-09-09 14:41:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-09 14:41:58 +03:00
|
|
|
*/
|
|
|
|
|
2021-04-25 08:53:23 +03:00
|
|
|
#include <LibTest/TestCase.h>
|
2020-09-09 14:41:58 +03:00
|
|
|
|
|
|
|
#include <AK/Array.h>
|
|
|
|
#include <AK/TypedTransfer.h>
|
|
|
|
|
|
|
|
struct NonPrimitiveIntWrapper {
|
|
|
|
NonPrimitiveIntWrapper(int value)
|
|
|
|
: m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE(overlapping_source_and_destination_1)
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
Array<NonPrimitiveIntWrapper, 6> const expected { 3, 4, 5, 6, 5, 6 };
|
2020-09-09 14:41:58 +03:00
|
|
|
|
|
|
|
Array<NonPrimitiveIntWrapper, 6> actual { 1, 2, 3, 4, 5, 6 };
|
|
|
|
AK::TypedTransfer<NonPrimitiveIntWrapper>::copy(actual.data(), actual.data() + 2, 4);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 6; ++i)
|
|
|
|
EXPECT_EQ(actual[i].m_value, expected[i].m_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(overlapping_source_and_destination_2)
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
Array<NonPrimitiveIntWrapper, 6> const expected { 1, 2, 1, 2, 3, 4 };
|
2020-09-09 14:41:58 +03:00
|
|
|
|
|
|
|
Array<NonPrimitiveIntWrapper, 6> actual { 1, 2, 3, 4, 5, 6 };
|
|
|
|
AK::TypedTransfer<NonPrimitiveIntWrapper>::copy(actual.data() + 2, actual.data(), 4);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 6; ++i)
|
|
|
|
EXPECT_EQ(actual[i].m_value, expected[i].m_value);
|
|
|
|
}
|