forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_helpers.cpp
More file actions
127 lines (98 loc) · 3.22 KB
/
Copy pathtest_helpers.cpp
File metadata and controls
127 lines (98 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <utility>
#include "catch.hpp"
#include "helpers.hpp"
using itertest::SolidInt;
using itertest::IsIterator;
using itertest::IsMoveConstructibleOnly;
namespace {
class ValidIter {
private:
int i;
public:
ValidIter& operator++(); // prefix
ValidIter operator++(int); // postfix
bool operator==(const ValidIter&) const;
bool operator!=(const ValidIter&) const;
int operator*();
void* operator->();
};
}
TEST_CASE("IsIterator fails when missing prefix ++", "[helpers]") {
struct InvalidIter : ValidIter {
InvalidIter& operator++() = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing postfix ++", "[helpers]") {
struct InvalidIter : ValidIter {
InvalidIter operator++(int) = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing ==", "[helpers]") {
struct InvalidIter : ValidIter {
bool operator==(const InvalidIter&) const = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing !=", "[helpers]") {
struct InvalidIter : ValidIter {
bool operator!=(const InvalidIter&) const = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing *", "[helpers]") {
struct InvalidIter : ValidIter {
int operator*() = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing copy-ctor", "[helpers]") {
struct InvalidIter : ValidIter {
InvalidIter(const InvalidIter&) = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator fails when missing copy assignment", "[helpers]") {
struct InvalidIter : ValidIter {
InvalidIter& operator=(const InvalidIter&) = delete;
};
REQUIRE(!IsIterator<InvalidIter>::value);
}
TEST_CASE("IsIterator passes a valid iterator", "[helpers]") {
REQUIRE(IsIterator<ValidIter>::value);
}
struct HasNothing {
HasNothing(const HasNothing&) = delete;
HasNothing& operator=(const HasNothing&) = delete;
};
struct HasMoveAndCopyCtor {
HasMoveAndCopyCtor(const HasMoveAndCopyCtor&);
HasMoveAndCopyCtor(HasMoveAndCopyCtor&&);
};
struct HasMoveCtorAndAssign {
HasMoveCtorAndAssign(HasMoveCtorAndAssign&&);
HasMoveCtorAndAssign& operator=(HasMoveCtorAndAssign&&);
};
struct HasMoveCtorAndCopyAssign {
HasMoveCtorAndCopyAssign(HasMoveCtorAndCopyAssign&&);
HasMoveCtorAndCopyAssign& operator=(const HasMoveCtorAndCopyAssign&);
};
struct HasMoveCtorOnly {
HasMoveCtorOnly(HasMoveCtorOnly&&);
};
TEST_CASE("IsMoveConstructibleOnly false without move ctor", "[helpers]") {
REQUIRE_FALSE(IsMoveConstructibleOnly<HasNothing>::value);
}
TEST_CASE("IsMoveConstructibleOnly false with copy ctor", "[helpers]") {
REQUIRE_FALSE(IsMoveConstructibleOnly<HasMoveAndCopyCtor>::value);
}
TEST_CASE("IsMoveConstructibleOnly false with move assign", "[helpers]") {
REQUIRE_FALSE(IsMoveConstructibleOnly<HasMoveCtorAndAssign>::value);
}
TEST_CASE("IsMoveConstructibleOnly false with copy assign", "[helpers]") {
REQUIRE_FALSE(IsMoveConstructibleOnly<HasMoveCtorAndCopyAssign>::value);
}
TEST_CASE("IsMoveConstructibleOnly true when met", "[helpers]") {
REQUIRE(IsMoveConstructibleOnly<HasMoveCtorOnly>::value);
}