tts v2.3.0
The Tiny Test System
 
Loading...
Searching...
No Matches

◆ TTS_CASE_TPL

#define TTS_CASE_TPL (   ID,
  ... 
)
Value:
[[maybe_unused]] static bool const TTS_CAT(case_,TTS_FUNCTION) = ::tts::detail::test_captures<__VA_ARGS__>{ID} \
+ TTS_PROTOTYPE() \

Introduces a template test case and registers it into the current test driver.

The code block following TTS_CASE contains user-defined code for a given test case. Those tests are parametrized by a template type of your choice passed as lambda function parameters of the template type tts::type and instantiated for each type in the types list.

Such types list can be provided as:

  • a variadic list of types separated by commas
  • an instance of the tts::types template class
  • an instance of a Type Generator, ie a type exposing a public types_list type definition

Test cases performing no actual tests will be reported as invalid.

Parameters
IDA literal string describing the scenario intents.
...Lists of types to generate the test case from.

Example

#define TTS_MAIN
#include <tts/tts.hpp>
#include <array>
TTS_CASE_TPL( "Check types using variadic list", char, short, int, double, void* )
<typename T>( tts::type<T> )
{
TTS_GREATER_EQUAL(sizeof(T), 1);
};
TTS_CASE_TPL( "Check types using a types list", tts::types<float,double> )
<typename T>( tts::type<T> )
{
TTS_EQUAL(1/T{2}, T{0.5});
};
// A Types Generator is any type exposing a types_list internal type
// In this example we use such a type to generate the list of types:
//
// tts::types<std::array<std::byte,1>,...,std::array<std::byte,N>>>;
template<int N, typename Indexes = std::make_index_sequence<N>> struct sizes;
template<int N, std::size_t... I> struct sizes<N, std::index_sequence<I...>>
{
using types_list = tts::types<std::array<std::byte,I+1>...>;
};
TTS_CASE_TPL( "Check types using a types list generator", sizes<5> )
<typename T>( tts::type<T> )
{
T x;
TTS_EQUAL(sizeof(x), x.size());
};
#define TTS_CASE_TPL(ID,...)
Introduces a template test case and registers it into the current test driver.
Definition: case.hpp:210
#define TTS_GREATER_EQUAL(LHS, RHS,...)
Performs greater-or-equal-than comparison between two expressions.
Definition: relation.hpp:260
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition: relation.hpp:90
Type wrapper.
Definition: types.hpp:37
Type list structure.
Definition: types.hpp:22