blob: 19064c07f5e8aa7d1ea5152cb8ca40e0423f2814 [file] [log] [blame]
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS
25#define ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS
26
27#include "Framework.h"
28
29#include <string>
30#include <utility>
31
32namespace arm_compute
33{
34namespace test
35{
36namespace framework
37{
38namespace detail
39{
40/** Helper class to statically register a test case. */
41template <typename T>
42class TestCaseRegistrar final
43{
44public:
45 /** Add a new test case with the given name to the framework.
46 *
47 * @param[in] test_name Name of the test case.
48 */
49 TestCaseRegistrar(std::string test_name);
50
51 /** Add a new data test case with the given name to the framework.
52 *
53 * @param[in] test_name Name of the test case.
54 * @param[in] dataset Dataset used as input for the test case.
55 */
56 template <typename D>
57 TestCaseRegistrar(std::string test_name, D &&dataset);
58};
59
60/** Helper class to statically begin and end a test suite. */
61class TestSuiteRegistrar final
62{
63public:
64 /** Remove the last added test suite from the framework. */
65 TestSuiteRegistrar();
66
67 /** Add a new test suite with the given name to the framework.
68 *
69 * @param[in] name Name of the test suite.
70 */
71 TestSuiteRegistrar(std::string name);
72};
73
74template <typename T>
75inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name)
76{
77 Framework::get().add_test_case<T>(std::move(test_name));
78}
79
80template <typename T>
81template <typename D>
82inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, D &&dataset)
83{
84 auto it = dataset.begin();
85
86 for(int i = 0; i < dataset.size(); ++i, ++it)
87 {
88 // WORKAROUND for GCC 4.9
89 // The last argument should be *it to pass just the data and not the
90 // iterator.
91 Framework::get().add_data_test_case<T>(test_name, it.description(), it);
92 }
93}
94
95inline TestSuiteRegistrar::TestSuiteRegistrar()
96{
97 Framework::get().pop_suite();
98}
99
100inline TestSuiteRegistrar::TestSuiteRegistrar(std::string name)
101{
102 Framework::get().push_suite(std::move(name));
103}
104} // namespace detail
105} // namespace framework
106} // namespace test
107} // namespace arm_compute
108#endif /* ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS */