Template tests: added TEMPLATE_PRODUCT_TEST_CASE
support for generating test cases based on multiple template template
types combined with template arguments for each of the template template
types specified
e.g.
```
TEMPLATE_PRODUCT_TEST_CASE("template product","[template]",
(std::tuple, std::pair, std::map),
((int,float),(char,double),(int,char)))
```
will effectively create 9 test cases with types:
std::tuple<int,float>
std::tuple<char,double>
std::tuple<int,char>
std::pair<int,float>
std::pair<char, double>
std::pair<int,char>
std::map<int,float>
std::map<char,double>
std::map<int,char>
Tested type is accessible in test case body as TestType
Unique name is created by appending ` - <index>` to test name
since preprocessor has some limitations in recursions
Closes #1454
2018-12-06 19:27:33 +01:00
|
|
|
/*
|
|
|
|
* Created by Jozef on 02/12/2018.
|
|
|
|
* Copyright 2018 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_META_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_META_HPP_INCLUDED
|
|
|
|
|
2018-12-30 23:44:20 +01:00
|
|
|
#include <type_traits>
|
|
|
|
|
2019-02-23 21:06:16 +01:00
|
|
|
namespace Catch {
|
2019-10-28 15:06:54 +01:00
|
|
|
template<typename T>
|
|
|
|
struct always_false : std::false_type {};
|
2019-04-23 23:41:13 +02:00
|
|
|
|
2019-10-28 15:06:54 +01:00
|
|
|
template <typename> struct true_given : std::true_type {};
|
|
|
|
struct is_callable_tester {
|
|
|
|
template <typename Fun, typename... Args>
|
|
|
|
true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
|
|
|
|
template <typename...>
|
|
|
|
std::false_type static test(...);
|
|
|
|
};
|
2019-04-23 23:41:13 +02:00
|
|
|
|
2019-10-28 15:06:54 +01:00
|
|
|
template <typename T>
|
|
|
|
struct is_callable;
|
2019-04-23 23:41:13 +02:00
|
|
|
|
2019-10-28 15:06:54 +01:00
|
|
|
template <typename Fun, typename... Args>
|
|
|
|
struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
|
|
|
|
// std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
|
2020-05-21 21:39:19 +02:00
|
|
|
// replaced with std::invoke_result here.
|
|
|
|
template <typename Func, typename... U>
|
|
|
|
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
|
2019-10-28 15:06:54 +01:00
|
|
|
#else
|
2020-05-21 21:39:19 +02:00
|
|
|
// Keep ::type here because we still support C++11
|
|
|
|
template <typename Func, typename... U>
|
|
|
|
using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U...)>::type>::type>::type;
|
2019-10-28 15:06:54 +01:00
|
|
|
#endif
|
2019-04-23 23:41:13 +02:00
|
|
|
|
2019-02-23 21:06:16 +01:00
|
|
|
} // namespace Catch
|
|
|
|
|
2019-05-27 17:24:16 +02:00
|
|
|
namespace mpl_{
|
|
|
|
struct na;
|
|
|
|
}
|
|
|
|
|
Template tests: added TEMPLATE_PRODUCT_TEST_CASE
support for generating test cases based on multiple template template
types combined with template arguments for each of the template template
types specified
e.g.
```
TEMPLATE_PRODUCT_TEST_CASE("template product","[template]",
(std::tuple, std::pair, std::map),
((int,float),(char,double),(int,char)))
```
will effectively create 9 test cases with types:
std::tuple<int,float>
std::tuple<char,double>
std::tuple<int,char>
std::pair<int,float>
std::pair<char, double>
std::pair<int,char>
std::map<int,float>
std::map<char,double>
std::map<int,char>
Tested type is accessible in test case body as TestType
Unique name is created by appending ` - <index>` to test name
since preprocessor has some limitations in recursions
Closes #1454
2018-12-06 19:27:33 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED
|