blob: ddbffabee4f69c816d874aaf2aaad2f6dc2bab9c [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
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010027#include "DatasetModes.h"
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010028#include "Framework.h"
29
30#include <string>
31#include <utility>
32
33namespace arm_compute
34{
35namespace test
36{
37namespace framework
38{
39namespace detail
40{
41/** Helper class to statically register a test case. */
42template <typename T>
43class TestCaseRegistrar final
44{
45public:
46 /** Add a new test case with the given name to the framework.
47 *
48 * @param[in] test_name Name of the test case.
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010049 * @param[in] mode Mode in which the test should be activated.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010050 */
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010051 TestCaseRegistrar(std::string test_name, DatasetMode mode);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010052
53 /** Add a new data test case with the given name to the framework.
54 *
55 * @param[in] test_name Name of the test case.
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010056 * @param[in] mode Mode in which the test should be activated.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010057 * @param[in] dataset Dataset used as input for the test case.
58 */
59 template <typename D>
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010060 TestCaseRegistrar(std::string test_name, DatasetMode mode, D &&dataset);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010061};
62
63/** Helper class to statically begin and end a test suite. */
64class TestSuiteRegistrar final
65{
66public:
67 /** Remove the last added test suite from the framework. */
68 TestSuiteRegistrar();
69
70 /** Add a new test suite with the given name to the framework.
71 *
72 * @param[in] name Name of the test suite.
73 */
74 TestSuiteRegistrar(std::string name);
75};
76
77template <typename T>
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010078inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010079{
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010080 Framework::get().add_test_case<T>(std::move(test_name), mode);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010081}
82
83template <typename T>
84template <typename D>
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010085inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, D &&dataset)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010086{
87 auto it = dataset.begin();
88
89 for(int i = 0; i < dataset.size(); ++i, ++it)
90 {
91 // WORKAROUND for GCC 4.9
92 // The last argument should be *it to pass just the data and not the
93 // iterator.
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010094 Framework::get().add_data_test_case<T>(test_name, mode, it.description(), it);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010095 }
96}
97
98inline TestSuiteRegistrar::TestSuiteRegistrar()
99{
100 Framework::get().pop_suite();
101}
102
103inline TestSuiteRegistrar::TestSuiteRegistrar(std::string name)
104{
105 Framework::get().push_suite(std::move(name));
106}
107} // namespace detail
108} // namespace framework
109} // namespace test
110} // namespace arm_compute
111#endif /* ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS */