attr_attribute_set_ticket11106.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_set_ticket11106.cpp
  9. * \author Andrey Semashev
  10. * \date 15.03.2015
  11. *
  12. * \brief This header contains a test for the fix for https://svn.boost.org/trac/boost/ticket/11106.
  13. */
  14. #define BOOST_TEST_MODULE attr_attribute_set_ticket11106
  15. #include <string>
  16. #include <sstream>
  17. #include <utility>
  18. #include <boost/test/unit_test.hpp>
  19. #include <boost/log/attributes/constant.hpp>
  20. #include <boost/log/attributes/attribute_set.hpp>
  21. // The test checks that insertion does not invalidate existing elements in the container
  22. BOOST_AUTO_TEST_CASE(ticket11106)
  23. {
  24. boost::log::attribute_set set;
  25. unsigned int i = 0;
  26. while (i < 100)
  27. {
  28. std::ostringstream strm;
  29. strm << "Attr" << i;
  30. boost::log::attribute_name name = strm.str();
  31. std::pair< boost::log::attribute_set::iterator, bool > res = set.insert(name, boost::log::attributes::make_constant(5));
  32. ++i;
  33. BOOST_CHECK(res.second); // check that insertion succeeded
  34. BOOST_CHECK(set.find(res.first->first) != set.end()); // check that lookup works
  35. // Now check that all previously inserted elements are still findable
  36. unsigned int j = 0;
  37. for (boost::log::attribute_set::const_iterator it = set.begin(), end = set.end(); it != end; ++it, ++j)
  38. {
  39. boost::log::attribute_name key = it->first;
  40. BOOST_CHECK(set.find(key) != set.end());
  41. }
  42. BOOST_CHECK_EQUAL(j, i);
  43. }
  44. }