xref: /freebsd/contrib/kyua/model/test_result.hpp (revision 99689201a1eb7bcd503987c5220b79330dc058b7)
1b0d29bc4SBrooks Davis // Copyright 2014 The Kyua Authors.
2b0d29bc4SBrooks Davis // All rights reserved.
3b0d29bc4SBrooks Davis //
4b0d29bc4SBrooks Davis // Redistribution and use in source and binary forms, with or without
5b0d29bc4SBrooks Davis // modification, are permitted provided that the following conditions are
6b0d29bc4SBrooks Davis // met:
7b0d29bc4SBrooks Davis //
8b0d29bc4SBrooks Davis // * Redistributions of source code must retain the above copyright
9b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer.
10b0d29bc4SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
11b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer in the
12b0d29bc4SBrooks Davis //   documentation and/or other materials provided with the distribution.
13b0d29bc4SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
14b0d29bc4SBrooks Davis //   may be used to endorse or promote products derived from this software
15b0d29bc4SBrooks Davis //   without specific prior written permission.
16b0d29bc4SBrooks Davis //
17b0d29bc4SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18b0d29bc4SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19b0d29bc4SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20b0d29bc4SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21b0d29bc4SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22b0d29bc4SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23b0d29bc4SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24b0d29bc4SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25b0d29bc4SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26b0d29bc4SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27b0d29bc4SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28b0d29bc4SBrooks Davis 
29b0d29bc4SBrooks Davis /// \file model/test_result.hpp
30b0d29bc4SBrooks Davis /// Definition of the "test result" concept.
31b0d29bc4SBrooks Davis 
32b0d29bc4SBrooks Davis #if !defined(MODEL_TEST_RESULT_HPP)
33b0d29bc4SBrooks Davis #define MODEL_TEST_RESULT_HPP
34b0d29bc4SBrooks Davis 
35b0d29bc4SBrooks Davis #include "model/test_result_fwd.hpp"
36b0d29bc4SBrooks Davis 
37*99689201SIgor Ostapenko #include <map>
38b0d29bc4SBrooks Davis #include <ostream>
39b0d29bc4SBrooks Davis #include <string>
40b0d29bc4SBrooks Davis 
41b0d29bc4SBrooks Davis namespace model {
42b0d29bc4SBrooks Davis 
43b0d29bc4SBrooks Davis 
44*99689201SIgor Ostapenko /// Test result type metadata.
45*99689201SIgor Ostapenko struct test_result_type_desc {
46*99689201SIgor Ostapenko     enum test_result_type id;
47*99689201SIgor Ostapenko     std::string name;
48*99689201SIgor Ostapenko     bool is_run;
49*99689201SIgor Ostapenko     bool is_good;
50*99689201SIgor Ostapenko };
51*99689201SIgor Ostapenko 
52*99689201SIgor Ostapenko 
53*99689201SIgor Ostapenko /// Description of each test result type.
54*99689201SIgor Ostapenko extern const std::map<enum test_result_type,
55*99689201SIgor Ostapenko     const struct test_result_type_desc> test_result_types;
56*99689201SIgor Ostapenko 
57*99689201SIgor Ostapenko 
58b0d29bc4SBrooks Davis /// Representation of a single test result.
59b0d29bc4SBrooks Davis ///
60b0d29bc4SBrooks Davis /// A test result is a simple pair of (type, reason).  The type indicates the
61b0d29bc4SBrooks Davis /// semantics of the results, and the optional reason provides an extra
62b0d29bc4SBrooks Davis /// description of the result type.
63b0d29bc4SBrooks Davis ///
64b0d29bc4SBrooks Davis /// In general, a 'passed' result will not have a reason attached, because a
65b0d29bc4SBrooks Davis /// successful test case does not deserve any kind of explanation.  We used to
66b0d29bc4SBrooks Davis /// special-case this with a very complex class hierarchy, but it proved to
67b0d29bc4SBrooks Davis /// result in an extremely-complex to maintain code base that provided no
68b0d29bc4SBrooks Davis /// benefits.  As a result, we allow any test type to carry a reason.
69b0d29bc4SBrooks Davis class test_result {
70b0d29bc4SBrooks Davis     /// The type of the result.
71b0d29bc4SBrooks Davis     test_result_type _type;
72b0d29bc4SBrooks Davis 
73b0d29bc4SBrooks Davis     /// A description of the result; may be empty.
74b0d29bc4SBrooks Davis     std::string _reason;
75b0d29bc4SBrooks Davis 
76b0d29bc4SBrooks Davis public:
77b0d29bc4SBrooks Davis     test_result(const test_result_type, const std::string& = "");
78b0d29bc4SBrooks Davis 
79b0d29bc4SBrooks Davis     test_result_type type(void) const;
80b0d29bc4SBrooks Davis     const std::string& reason(void) const;
81b0d29bc4SBrooks Davis 
82b0d29bc4SBrooks Davis     bool good(void) const;
83b0d29bc4SBrooks Davis 
84b0d29bc4SBrooks Davis     bool operator==(const test_result&) const;
85b0d29bc4SBrooks Davis     bool operator!=(const test_result&) const;
86b0d29bc4SBrooks Davis };
87b0d29bc4SBrooks Davis 
88b0d29bc4SBrooks Davis 
89b0d29bc4SBrooks Davis std::ostream& operator<<(std::ostream&, const test_result&);
90b0d29bc4SBrooks Davis 
91b0d29bc4SBrooks Davis 
92b0d29bc4SBrooks Davis }  // namespace model
93b0d29bc4SBrooks Davis 
94b0d29bc4SBrooks Davis #endif  // !defined(MODEL_TEST_RESULT_HPP)
95