33#include " stdsharp/concepts/concepts.h"
44#include " test.h"
55
6- using namespace stdsharp ;
7- using namespace std ;
8-
96struct test_worst_type
107{
118 test_worst_type () = default ;
@@ -18,82 +15,9 @@ struct test_worst_type
1815 test_worst_type& operator =(test_worst_type&&) = default ;
1916};
2017
21- template <typename Normal, typename Unique, typename Worst>
22- void allocation_type_requirement_test ()
23- {
24- STATIC_REQUIRE (copyable<Normal>);
25- STATIC_REQUIRE (nothrow_movable<Unique>);
26- STATIC_REQUIRE (nothrow_swappable<Unique>);
27- STATIC_REQUIRE (nothrow_movable<Worst>);
28- STATIC_REQUIRE (nothrow_swappable<Worst>);
29- }
30-
31- template <typename T, typename Value, typename Predicate>
32- void allocation_emplace_value_test (T& box, const Value& value, Predicate predicate)
33- {
34- WHEN (" emplace a value" )
35- {
36- const auto & res = box.emplace (value);
37-
38- THEN (" the return value should correct" ) { predicate (res, value); }
39-
40- AND_THEN (" type should be expected" ) { REQUIRE (box.template is_type <Value>()); }
41- }
42- }
43-
44- template <typename T>
45- void allocation_emplace_execution_test (T& box)
46- {
47- auto invoked = 0u ;
48-
49- struct local : reference_wrapper<unsigned >
50- {
51- local (unsigned & value): reference_wrapper(value) { ++get (); }
52- };
53-
54- WHEN (" assign custom type twice" )
55- {
56- INFO (" custom type" );
57-
58- box.template emplace <local>(invoked);
59- box.template emplace <local>(invoked);
60-
61- THEN (" assign operator should be invoked" ) { REQUIRE (invoked == 2 ); }
62-
63- AND_THEN (" destroy allocation and check content" )
64- {
65- box.reset ();
66- REQUIRE (!box.has_value ());
67- }
68- }
69- }
70-
71- template <typename T>
72- void allocation_functionality_test (T box = {})
73- {
74- GIVEN (" an object allocation" )
75- {
76- allocation_emplace_value_test (
77- box,
78- 1 ,
79- [](const int v, const int value) { REQUIRE (v == value); }
80- );
81-
82- allocation_emplace_value_test (
83- box,
84- std::array<unsigned , 5 >{1 , 2 , 3 , 4 , 5 },
85- [](const auto & v, const auto & value) { REQUIRE (v == value); }
86- );
87-
88- allocation_emplace_value_test (
89- box,
90- vector<int >{1 , 2 },
91- [](const vector<int >& v, const vector<int >& value)
92- {
93- REQUIRE_THAT (v, Catch::Matchers::RangeEquals (value)); //
94- }
95- );
96-
97- allocation_emplace_execution_test (box);
98- }
99- }
18+ #define ALLOCATION_TYPE_REQUIRE (Normal, Unique, Worst ) \
19+ STATIC_REQUIRE (copyable<Normal>); \
20+ STATIC_REQUIRE (nothrow_movable<Unique>); \
21+ STATIC_REQUIRE (nothrow_swappable<Unique>); \
22+ STATIC_REQUIRE (nothrow_movable<Worst>); \
23+ STATIC_REQUIRE (nothrow_swappable<Worst>)
0 commit comments