attr_attribute_value_set_ticket11190.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #define BOOST_TEST_MODULE attr_attribute_value_set_ticket11190
  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. #include <boost/log/attributes/attribute_value_set.hpp>
  22. // The test checks that insertion does not invalidate existing elements in the container
  23. BOOST_AUTO_TEST_CASE(ticket11190)
  24. {
  25. boost::log::attribute_set set, dummy;
  26. unsigned int i = 0;
  27. while (i < 100)
  28. {
  29. std::ostringstream strm;
  30. strm << "Attr" << i;
  31. boost::log::attribute_name name = strm.str();
  32. std::pair< boost::log::attribute_set::iterator, bool > res = set.insert(name, boost::log::attributes::make_constant(5));
  33. ++i;
  34. BOOST_CHECK(res.second); // check that insertion succeeded
  35. // check that lookup works
  36. boost::log::attribute_set::iterator find_result = set.find(name);
  37. BOOST_CHECK(find_result != set.end());
  38. BOOST_CHECK(find_result == res.first);
  39. }
  40. boost::log::attribute_value_set vset(set, dummy, dummy);
  41. BOOST_CHECK_EQUAL(vset.size(), set.size());
  42. // Check that all inserted elements are findable
  43. unsigned int j = 0;
  44. for (boost::log::attribute_value_set::const_iterator it = vset.begin(), end = vset.end(); it != end; ++it, ++j)
  45. {
  46. boost::log::attribute_name key = it->first;
  47. BOOST_CHECK(vset.find(key) != vset.end());
  48. }
  49. // Check that vset.size() is valid
  50. BOOST_CHECK_EQUAL(j, i);
  51. }