1 /*
2 * Copyright Andrey Semashev 2007 - 2015.
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 /*!
8 * \file attr_attribute_value_set_ticket11190.cpp
9 * \author Andrey Semashev
10 * \date 25.04.2015
11 *
12 * \brief This header contains a test for the fix for https://svn.boost.org/trac/boost/ticket/11190.
13 */
14
15 #define BOOST_TEST_MODULE attr_attribute_value_set_ticket11190
16
17 #include <string>
18 #include <sstream>
19 #include <utility>
20 #include <boost/test/unit_test.hpp>
21 #include <boost/log/attributes/constant.hpp>
22 #include <boost/log/attributes/attribute_set.hpp>
23 #include <boost/log/attributes/attribute_value_set.hpp>
24
25 // The test checks that insertion does not invalidate existing elements in the container
BOOST_AUTO_TEST_CASE(ticket11190)26 BOOST_AUTO_TEST_CASE(ticket11190)
27 {
28 boost::log::attribute_set set, dummy;
29
30 unsigned int i = 0;
31 while (i < 100)
32 {
33 std::ostringstream strm;
34 strm << "Attr" << i;
35 boost::log::attribute_name name = strm.str();
36
37 std::pair< boost::log::attribute_set::iterator, bool > res = set.insert(name, boost::log::attributes::make_constant(5));
38 ++i;
39
40 BOOST_CHECK(res.second); // check that insertion succeeded
41 // check that lookup works
42 boost::log::attribute_set::iterator find_result = set.find(name);
43 BOOST_CHECK(find_result != set.end());
44 BOOST_CHECK(find_result == res.first);
45 }
46
47 boost::log::attribute_value_set vset(set, dummy, dummy);
48 BOOST_CHECK_EQUAL(vset.size(), set.size());
49
50 // Check that all inserted elements are findable
51 unsigned int j = 0;
52 for (boost::log::attribute_value_set::const_iterator it = vset.begin(), end = vset.end(); it != end; ++it, ++j)
53 {
54 boost::log::attribute_name key = it->first;
55 BOOST_CHECK(vset.find(key) != vset.end());
56 }
57
58 // Check that vset.size() is valid
59 BOOST_CHECK_EQUAL(j, i);
60 }
61