75#ifndef ALEPH_TESTS_MOVED_FROM_H
76#define ALEPH_TESTS_MOVED_FROM_H
83#include <gtest/gtest.h>
101template <
class Case,
class T>
104 if constexpr (
requires { Case::fingerprint(x); })
105 return Case::fingerprint(x);
106 else if constexpr (
requires { { x.size() } -> std::convertible_to<std::size_t>; })
107 return static_cast<std::size_t
>(x.size());
109 return std::size_t(0);
115template <
class T>
class MovedFrom :
public ::testing::Test {};
124 TypeParam src = Case::make(100);
125 const auto print = moved_from_fingerprint<Case>(src);
126 TypeParam dst(std::move(src));
127 EXPECT_EQ(moved_from_fingerprint<Case>(dst),
print);
128 EXPECT_TRUE(Case::is_empty(src));
140 if constexpr (std::is_move_assignable_v<TypeParam>)
143 for (
const std::size_t n : {std::size_t(2), std::size_t(1000)})
145 TypeParam dst = Case::make(n);
146 TypeParam src = Case::make(n == 2 ? 1000 : 2);
147 const auto print = moved_from_fingerprint<Case>(src);
148 dst = std::move(src);
149 EXPECT_EQ(moved_from_fingerprint<Case>(dst),
print);
155 GTEST_SKIP() <<
"the class has no move assignment";
159 AssignmentLeavesBothObjectsUsable);
The typed suite of the moved-from tests.
TYPED_TEST_P(MovedFrom, ConstructionLeavesAnEmptyUsableSource)
TYPED_TEST_SUITE_P(MovedFrom)
REGISTER_TYPED_TEST_SUITE_P(MovedFrom, ConstructionLeavesAnEmptyUsableSource, AssignmentLeavesBothObjectsUsable)
auto moved_from_fingerprint(const T &x)
What a move must carry from its source to its destination.
How the moved-from tests build, check and use objects of a class.
void print(const MemArray< T > &s)