suite_list.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_UNIT_TEST_SUITE_LIST_HPP
  10. #define BOOST_BEAST_UNIT_TEST_SUITE_LIST_HPP
  11. #include <boost/beast/_experimental/unit_test/suite_info.hpp>
  12. #include <boost/beast/_experimental/unit_test/detail/const_container.hpp>
  13. #include <boost/assert.hpp>
  14. #include <typeindex>
  15. #include <set>
  16. #include <unordered_set>
  17. namespace boost {
  18. namespace beast {
  19. namespace unit_test {
  20. /// A container of test suites.
  21. class suite_list
  22. : public detail::const_container <std::set <suite_info>>
  23. {
  24. private:
  25. #ifndef NDEBUG
  26. std::unordered_set<std::string> names_;
  27. std::unordered_set<std::type_index> classes_;
  28. #endif
  29. public:
  30. /** Insert a suite into the set.
  31. The suite must not already exist.
  32. */
  33. template<class Suite>
  34. void
  35. insert(
  36. char const* name,
  37. char const* module,
  38. char const* library,
  39. bool manual);
  40. };
  41. //------------------------------------------------------------------------------
  42. template<class Suite>
  43. void
  44. suite_list::insert(
  45. char const* name,
  46. char const* module,
  47. char const* library,
  48. bool manual)
  49. {
  50. #ifndef NDEBUG
  51. {
  52. std::string s;
  53. s = std::string(library) + "." + module + "." + name;
  54. auto const result(names_.insert(s));
  55. BOOST_ASSERT(result.second); // Duplicate name
  56. }
  57. {
  58. auto const result(classes_.insert(
  59. std::type_index(typeid(Suite))));
  60. BOOST_ASSERT(result.second); // Duplicate type
  61. }
  62. #endif
  63. cont().emplace(make_suite_info<Suite>(
  64. name, module, library, manual));
  65. }
  66. } // unit_test
  67. } // beast
  68. } // boost
  69. #endif