]> git.proxmox.com Git - ceph.git/blame - ceph/src/Beast/extras/beast/unit_test/suite_info.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / extras / beast / unit_test / suite_info.hpp
CommitLineData
7c673cae
FG
1//
2// Copyright (c) 2013-2017 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
8#ifndef BEAST_UNIT_TEST_SUITE_INFO_HPP
9#define BEAST_UNIT_TEST_SUITE_INFO_HPP
10
11#include <cstring>
12#include <functional>
13#include <string>
14#include <utility>
15
16namespace beast {
17namespace unit_test {
18
19class runner;
20
21/** Associates a unit test type with metadata. */
22class suite_info
23{
24 using run_type = std::function<void(runner&)>;
25
26 std::string name_;
27 std::string module_;
28 std::string library_;
29 bool manual_;
30 run_type run_;
31
32public:
33 suite_info(
34 std::string name,
35 std::string module,
36 std::string library,
37 bool manual,
38 run_type run)
39 : name_(std::move(name))
40 , module_(std::move(module))
41 , library_(std::move(library))
42 , manual_(manual)
43 , run_(std::move(run))
44 {
45 }
46
47 std::string const&
48 name() const
49 {
50 return name_;
51 }
52
53 std::string const&
54 module() const
55 {
56 return module_;
57 }
58
59 std::string const&
60 library() const
61 {
62 return library_;
63 }
64
65 /// Returns `true` if this suite only runs manually.
66 bool
67 manual() const
68 {
69 return manual_;
70 }
71
72 /// Return the canonical suite name as a string.
73 std::string
74 full_name() const
75 {
76 return library_ + "." + module_ + "." + name_;
77 }
78
79 /// Run a new instance of the associated test suite.
80 void
81 run(runner& r) const
82 {
83 run_(r);
84 }
85
86 friend
87 bool
88 operator<(suite_info const& lhs, suite_info const& rhs)
89 {
90 return
91 std::tie(lhs.library_, lhs.module_, lhs.name_) <
92 std::tie(rhs.library_, rhs.module_, rhs.name_);
93 }
94};
95
96//------------------------------------------------------------------------------
97
98/// Convenience for producing suite_info for a given test type.
99template<class Suite>
100suite_info
101make_suite_info(
102 std::string name,
103 std::string module,
104 std::string library,
105 bool manual)
106{
107 return suite_info(
108 std::move(name),
109 std::move(module),
110 std::move(library),
111 manual,
112 [](runner& r)
113 {
114 Suite{}(r);
115 }
116 );
117}
118
119} // unit_test
120} // beast
121
122#endif