Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 1 | /* |
| 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 Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 27 | #include "DatasetModes.h" |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 28 | #include "Framework.h" |
| 29 | |
| 30 | #include <string> |
| 31 | #include <utility> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace framework |
| 38 | { |
| 39 | namespace detail |
| 40 | { |
| 41 | /** Helper class to statically register a test case. */ |
| 42 | template <typename T> |
| 43 | class TestCaseRegistrar final |
| 44 | { |
| 45 | public: |
| 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 Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 49 | * @param[in] mode Mode in which the test should be activated. |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 50 | */ |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 51 | TestCaseRegistrar(std::string test_name, DatasetMode mode); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 52 | |
| 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 Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 56 | * @param[in] mode Mode in which the test should be activated. |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 57 | * @param[in] dataset Dataset used as input for the test case. |
| 58 | */ |
| 59 | template <typename D> |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 60 | TestCaseRegistrar(std::string test_name, DatasetMode mode, D &&dataset); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /** Helper class to statically begin and end a test suite. */ |
| 64 | class TestSuiteRegistrar final |
| 65 | { |
| 66 | public: |
| 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 | |
| 77 | template <typename T> |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 78 | inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode) |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 79 | { |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 80 | Framework::get().add_test_case<T>(std::move(test_name), mode); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | template <typename T> |
| 84 | template <typename D> |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 85 | inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, D &&dataset) |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 86 | { |
| 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 Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 94 | Framework::get().add_data_test_case<T>(test_name, mode, it.description(), it); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | inline TestSuiteRegistrar::TestSuiteRegistrar() |
| 99 | { |
| 100 | Framework::get().pop_suite(); |
| 101 | } |
| 102 | |
| 103 | inline 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 */ |