1// Boost.TypeErasure library
2//
3// Copyright 2011 Steven Watanabe
4//
5// Distributed under the Boost Software License Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// $Id$
10
11#include <boost/type_erasure/any.hpp>
12#include <boost/type_erasure/builtin.hpp>
13#include <boost/type_erasure/operators.hpp>
14#include <boost/type_erasure/any_cast.hpp>
15#include <boost/type_erasure/tuple.hpp>
16#include <boost/mpl/vector.hpp>
17
18#define BOOST_TEST_MAIN
19#include <boost/test/unit_test.hpp>
20
21using namespace boost::type_erasure;
22
23BOOST_AUTO_TEST_CASE(test_basic)
24{
25 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<> > test_concept;
26 any<test_concept> x(1);
27 any<test_concept> y(2);
28
29 BOOST_CHECK(!(x == y));
30 BOOST_CHECK((x == x));
31 BOOST_CHECK((x != y));
32 BOOST_CHECK(!(x != x));
33}
34
35BOOST_AUTO_TEST_CASE(test_mixed_unequal)
36{
37 typedef boost::mpl::vector<copy_constructible<_a>, copy_constructible<_b>, equality_comparable<_a, _b> > test_concept;
38 tuple<test_concept, _a, _b> t(1, 2.0);
39 any<test_concept, _a> x(get<0>(t));
40 any<test_concept, _b> y(get<1>(t));
41
42 BOOST_CHECK(!(x == y));
43 BOOST_CHECK((x != y));
44}
45
46BOOST_AUTO_TEST_CASE(test_mixed_equal)
47{
48 typedef boost::mpl::vector<copy_constructible<_a>, copy_constructible<_b>, equality_comparable<_a, _b> > test_concept;
49 tuple<test_concept, _a, _b> t(1, 1);
50 any<test_concept, _a> x(get<0>(t));
51 any<test_concept, _b> y(get<1>(t));
52
53 BOOST_CHECK((x == y));
54 BOOST_CHECK(!(x != y));
55}
56
57BOOST_AUTO_TEST_CASE(test_fixed_lhs_unequal)
58{
59 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<int, _self> > test_concept;
60 int x(1);
61 any<test_concept> y(2.0);
62
63 BOOST_CHECK(!(x == y));
64 BOOST_CHECK((x != y));
65}
66
67BOOST_AUTO_TEST_CASE(test_fixed_lhs_equal)
68{
69 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<int, _self> > test_concept;
70 int x(1);
71 any<test_concept> y(1);
72
73 BOOST_CHECK((x == y));
74 BOOST_CHECK(!(x != y));
75}
76
77BOOST_AUTO_TEST_CASE(test_fixed_rhs_unequal)
78{
79 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<_self, int> > test_concept;
80 any<test_concept> x(2.0);
81 int y(1);
82
83 BOOST_CHECK(!(x == y));
84 BOOST_CHECK((x != y));
85}
86
87BOOST_AUTO_TEST_CASE(test_fixed_rhs_equal)
88{
89 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<_self, int> > test_concept;
90 any<test_concept> x(1);
91 int y(1);
92
93 BOOST_CHECK((x == y));
94 BOOST_CHECK(!(x != y));
95}
96
97BOOST_AUTO_TEST_CASE(test_relaxed)
98{
99 typedef boost::mpl::vector<copy_constructible<>, equality_comparable<>, relaxed> test_concept;
100 any<test_concept> x(1);
101 any<test_concept> y(2);
102 any<test_concept> z(std::string("test"));
103
104 BOOST_CHECK(!(x == y));
105 BOOST_CHECK((x == x));
106 BOOST_CHECK((x != y));
107 BOOST_CHECK(!(x != x));
108
109 BOOST_CHECK(!(x == z));
110 BOOST_CHECK((x != z));
111}
112
113BOOST_AUTO_TEST_CASE(test_overload)
114{
115 typedef boost::mpl::vector<
116 copy_constructible<_a>,
117 copy_constructible<_b>,
118 equality_comparable<_a>,
119 equality_comparable<_a, int>,
120 equality_comparable<int, _a>,
121 equality_comparable<_b>,
122 equality_comparable<_b, int>,
123 equality_comparable<int, _b>,
124 equality_comparable<_a, _b>
125 > test_concept;
126
127 tuple<test_concept, _a, _b> t(1, 2.0);
128 any<test_concept, _a> x(get<0>(t));
129 any<test_concept, _b> y(get<1>(t));
130
131 BOOST_CHECK(x == x);
132 BOOST_CHECK(!(x != x));
133 BOOST_CHECK(x == 1);
134 BOOST_CHECK(x != 2);
135 BOOST_CHECK(1 == x);
136 BOOST_CHECK(2 != x);
137
138 BOOST_CHECK(y == y);
139 BOOST_CHECK(!(y != y));
140 BOOST_CHECK(y == 2);
141 BOOST_CHECK(y != 3);
142 BOOST_CHECK(2 == y);
143 BOOST_CHECK(3 != y);
144
145 BOOST_CHECK(!(x == y));
146 BOOST_CHECK(x != y);
147}
148

source code of boost/libs/type_erasure/test/test_equal.cpp