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 
10 #ifndef BOOST_BEAST_UNIT_TEST_SUITE_LIST_HPP
11 #define BOOST_BEAST_UNIT_TEST_SUITE_LIST_HPP
12 
13 #include <boost/beast/_experimental/unit_test/suite_info.hpp>
14 #include <boost/beast/_experimental/unit_test/detail/const_container.hpp>
15 #include <boost/assert.hpp>
16 #include <typeindex>
17 #include <set>
18 #include <unordered_set>
19 
20 namespace boost {
21 namespace beast {
22 namespace unit_test {
23 
24 /// A container of test suites.
25 class suite_list
26     : public detail::const_container <std::set <suite_info>>
27 {
28 private:
29 #ifndef NDEBUG
30     std::unordered_set<std::string> names_;
31     std::unordered_set<std::type_index> classes_;
32 #endif
33 
34 public:
35     /** Insert a suite into the set.
36 
37         The suite must not already exist.
38     */
39     template<class Suite>
40     void
41     insert(
42         char const* name,
43         char const* module,
44         char const* library,
45         bool manual);
46 };
47 
48 //------------------------------------------------------------------------------
49 
50 template<class Suite>
51 void
insert(char const * name,char const * module,char const * library,bool manual)52 suite_list::insert(
53     char const* name,
54     char const* module,
55     char const* library,
56     bool manual)
57 {
58 #ifndef NDEBUG
59     {
60         std::string s;
61         s = std::string(library) + "." + module + "." + name;
62         auto const result(names_.insert(s));
63         BOOST_ASSERT(result.second); // Duplicate name
64     }
65 
66     {
67         auto const result(classes_.insert(
68             std::type_index(typeid(Suite))));
69         BOOST_ASSERT(result.second); // Duplicate type
70     }
71 #endif
72     cont().emplace(make_suite_info<Suite>(
73         name, module, library, manual));
74 }
75 
76 } // unit_test
77 } // beast
78 } // boost
79 
80 #endif
81 
82