1 /* Copyright 2016-2018 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/poly_collection for library home page.
7 */
8
9 #include "test_comparison.hpp"
10
11 #include <boost/core/lightweight_test.hpp>
12 #include "any_types.hpp"
13 #include "base_types.hpp"
14 #include "function_types.hpp"
15 #include "test_utilities.hpp"
16
17 using namespace test_utilities;
18
19 template<typename PolyCollection,typename ValueFactory,typename... Types>
test_comparison()20 void test_comparison()
21 {
22 {
23 PolyCollection p1,p2;
24 const PolyCollection& cp1=p1;
25 const PolyCollection& cp2=p2;
26
27 BOOST_TEST(cp1==cp1);
28 BOOST_TEST(!(cp1!=cp1));
29 BOOST_TEST(cp1==cp2);
30 BOOST_TEST(!(cp1!=cp2));
31 }
32 {
33 PolyCollection p1,p2;
34 const PolyCollection& cp1=p1;
35 const PolyCollection& cp2=p2;
36 ValueFactory v;
37
38 fill<
39 constraints<is_not_equality_comparable>,
40 Types...
41 >(p1,v,2);
42
43 BOOST_TEST(!(cp1==cp2));
44 BOOST_TEST(cp1!=cp2);
45 }
46 {
47 PolyCollection p1,p2;
48 const PolyCollection& cp1=p1;
49 const PolyCollection& cp2=p2;
50 ValueFactory v;
51
52 p1.template register_types<Types...>();
53 fill<
54 constraints<is_not_equality_comparable>,
55 Types...
56 >(p1,v,2);
57
58 BOOST_TEST(!(cp1==cp2));
59 BOOST_TEST(cp1!=cp2);
60 }
61 {
62 PolyCollection p1,p2;
63 const PolyCollection& cp1=p1;
64 const PolyCollection& cp2=p2;
65 ValueFactory v;
66
67 fill<
68 constraints<is_not_equality_comparable>,
69 Types...
70 >(p1,v,1);
71 fill<
72 constraints<is_not_equality_comparable>,
73 Types...
74 >(p2,v,2);
75
76 BOOST_TEST(!(cp1==cp2));
77 BOOST_TEST(cp1!=cp2);
78 }
79 {
80 using not_equality_comparable=
81 boost::poly_collection::not_equality_comparable;
82
83 PolyCollection p1,p2;
84 const PolyCollection& cp1=p1;
85 const PolyCollection& cp2=p2;
86 ValueFactory v;
87
88 fill<
89 constraints<is_not_equality_comparable>,
90 Types...
91 >(p1,v,2);
92 fill<
93 constraints<is_not_equality_comparable>,
94 Types...
95 >(p2,v,2);
96
97 check_throw<not_equality_comparable>(
98 [&]{(void)(cp1==cp2);},
99 [&]{(void)(cp1!=cp2);});
100 }
101 {
102 PolyCollection p1,p2;
103 const PolyCollection& cp1=p1;
104 const PolyCollection& cp2=p2;
105 ValueFactory v;
106
107 fill<
108 constraints<is_not_equality_comparable>,
109 Types...
110 >(p1,v,2);
111 fill<
112 constraints<is_equality_comparable,is_copy_constructible>,
113 Types...
114 >(p2,v,2);
115 p1.insert(p2.begin(),p2.end());
116
117 BOOST_TEST(!(cp1==cp2));
118 BOOST_TEST(cp1!=cp2);
119 }
120 {
121 PolyCollection p1,p2;
122 const PolyCollection& cp1=p1;
123 const PolyCollection& cp2=p2;
124 ValueFactory v;
125
126 p1.template register_types<Types...>();
127 fill<
128 constraints<is_equality_comparable,is_copy_constructible>,
129 Types...
130 >(p2,v,2);
131 p1.insert(p2.begin(),p2.end());
132
133 BOOST_TEST(cp1==cp2);
134 BOOST_TEST(!(cp1!=cp2));
135
136 p1.erase(p1.begin());
137 BOOST_TEST(!(cp1==cp2));
138 BOOST_TEST(cp1!=cp2);
139 }
140 }
141
test_stateless_lambda_comparability_check()142 void test_stateless_lambda_comparability_check()
143 {
144 /* https://svn.boost.org/trac10/ticket/13012 */
145
146 {
147 boost::function_collection<void()> c1,c2;
148 c1.insert([]{});
149 BOOST_TEST(c1!=c2);
150 }
151 {
152 boost::function_collection<int(int)> c1,c2;
153 c1.insert([](int){return 0;});
154 BOOST_TEST(c1!=c2);
155 }
156 }
157
test_comparison()158 void test_comparison()
159 {
160 test_comparison<
161 any_types::collection,auto_increment,
162 any_types::t1,any_types::t2,any_types::t3,
163 any_types::t4,any_types::t5>();
164 test_comparison<
165 base_types::collection,auto_increment,
166 base_types::t1,base_types::t2,base_types::t3,
167 base_types::t4,base_types::t5>();
168 test_comparison<
169 function_types::collection,auto_increment,
170 function_types::t1,function_types::t2,function_types::t3,
171 function_types::t4,function_types::t5>();
172 test_stateless_lambda_comparability_check();
173 }
174