erase_exception_tests.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2006-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "./containers.hpp"
  5. #include "../helpers/helpers.hpp"
  6. #include "../helpers/invariants.hpp"
  7. #include "../helpers/random_values.hpp"
  8. test::seed_t initialize_seed(835193);
  9. template <class T> struct erase_test_base : public test::exception_base
  10. {
  11. test::random_values<T> values;
  12. erase_test_base(unsigned int count = 5) : values(count, test::limited_range)
  13. {
  14. }
  15. typedef T data_type;
  16. data_type init() const { return T(values.begin(), values.end()); }
  17. void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const
  18. {
  19. std::string scope(test::scope);
  20. BOOST_TEST(scope.find("hash::") != std::string::npos ||
  21. scope.find("equal_to::") != std::string::npos ||
  22. scope == "operator==(object, object)");
  23. test::check_equivalent_keys(x);
  24. }
  25. };
  26. template <class T> struct erase_by_key_test1 : public erase_test_base<T>
  27. {
  28. void run(T& x) const
  29. {
  30. typedef typename test::random_values<T>::const_iterator iterator;
  31. for (iterator it = this->values.begin(), end = this->values.end();
  32. it != end; ++it) {
  33. x.erase(test::get_key<T>(*it));
  34. }
  35. DISABLE_EXCEPTIONS;
  36. BOOST_TEST(x.empty());
  37. test::check_equivalent_keys(x);
  38. }
  39. };
  40. EXCEPTION_TESTS((erase_by_key_test1), CONTAINER_SEQ)
  41. RUN_TESTS()