]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2008 Joseph Gauterin, Niels Dekker |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt or copy at | |
5 | // http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | // Tests swapping std::vector objects by means of boost::swap, | |
8 | // having ::swap_test_class as vector element type. | |
9 | ||
10 | #include <boost/utility/swap.hpp> | |
11 | #include <boost/core/lightweight_test.hpp> | |
12 | #define BOOST_CHECK BOOST_TEST | |
13 | #define BOOST_CHECK_EQUAL BOOST_TEST_EQ | |
14 | ||
15 | #include <vector> | |
16 | ||
17 | //Put test class in the global namespace | |
18 | #include "./swap_test_class.hpp" | |
19 | ||
20 | //Provide swap function in the global namespace | |
21 | void swap(swap_test_class& left, swap_test_class& right) | |
22 | { | |
23 | left.swap(right); | |
24 | } | |
25 | ||
26 | int main() | |
27 | { | |
28 | typedef std::vector<swap_test_class> vector_type; | |
29 | ||
30 | const vector_type::size_type initial_size1 = 1; | |
31 | const vector_type::size_type initial_size2 = 2; | |
32 | ||
33 | const vector_type initial_value1(initial_size1, swap_test_class(1)); | |
34 | const vector_type initial_value2(initial_size2, swap_test_class(2)); | |
35 | ||
36 | vector_type object1 = initial_value1; | |
37 | vector_type object2 = initial_value2; | |
38 | ||
39 | swap_test_class::reset(); | |
40 | ||
41 | boost::swap(object1,object2); | |
42 | ||
43 | BOOST_CHECK_EQUAL(object1.size(),initial_size2); | |
44 | BOOST_CHECK_EQUAL(object2.size(),initial_size1); | |
45 | ||
46 | BOOST_CHECK(object1 == initial_value2); | |
47 | BOOST_CHECK(object2 == initial_value1); | |
48 | ||
49 | BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0); | |
50 | BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); | |
51 | ||
52 | return boost::report_errors(); | |
53 | } | |
54 |