1// Copyright 2011 Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9//   notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright
11//   notice, this list of conditions and the following disclaimer in the
12//   documentation and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors
14//   may be used to endorse or promote products derived from this software
15//   without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29/// \file engine/drivers/run_tests.hpp
30/// Driver to run a collection of tests.
31///
32/// This driver module implements the logic to execute a collection of tests.
33/// The presentation layer is able to monitor progress by hooking into
34/// particular points of the driver.
35
36#if !defined(ENGINE_DRIVERS_RUN_TESTS_HPP)
37#define ENGINE_DRIVERS_RUN_TESTS_HPP
38
39extern "C" {
40#include <stdint.h>
41}
42
43#include <set>
44
45#include "engine/filters.hpp"
46#include "engine/test_case.hpp"
47#include "utils/config/tree.hpp"
48#include "utils/datetime.hpp"
49#include "utils/fs/path.hpp"
50#include "utils/optional.hpp"
51
52namespace engine {
53class test_result;
54namespace drivers {
55namespace run_tests {
56
57
58/// Abstract definition of the hooks for this driver.
59class base_hooks {
60public:
61    virtual ~base_hooks(void) = 0;
62
63    /// Called when the processing of a test case begins.
64    ///
65    /// \param test_case The test case.
66    virtual void got_test_case(const engine::test_case_ptr& test_case) = 0;
67
68    /// Called when a result of a test case becomes available.
69    ///
70    /// \param test_case The test case.
71    /// \param result The result of the execution of the test case.
72    /// \param duration The time it took to run the test.
73    virtual void got_result(const engine::test_case_ptr& test_case,
74                            const engine::test_result& result,
75                            const utils::datetime::delta& duration) = 0;
76};
77
78
79/// Tuple containing the results of this driver.
80class result {
81public:
82    /// The identifier assigned to the operation.
83    int64_t action_id;
84
85    /// Filters that did not match any available test case.
86    ///
87    /// The presence of any filters here probably indicates a usage error.  If a
88    /// test filter does not match any test case, it is probably a typo.
89    std::set< test_filter > unused_filters;
90
91    /// Initializer for the tuple's fields.
92    ///
93    /// \param action_id_ The identifier assigned to the operation.
94    /// \param unused_filters_ The filters that did not match any test case.
95    result(const int64_t action_id_,
96           const std::set< test_filter >& unused_filters_) :
97        action_id(action_id_),
98        unused_filters(unused_filters_)
99    {
100    }
101};
102
103
104result drive(const utils::fs::path&, const utils::optional< utils::fs::path >,
105             const utils::fs::path&, const std::set< test_filter >&,
106             const utils::config::tree&, base_hooks&);
107
108
109}  // namespace run_tests
110}  // namespace drivers
111}  // namespace engine
112
113#endif  // !defined(ENGINE_DRIVERS_RUN_TESTS_HPP)
114