Boost logo

Boost :

Subject: [boost] [test] Test cases parametrized by both type and value?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2018-01-05 11:39:35

Can anyone tell me if Boost.Test can solve the problem that I describe

I have a function template inspect:

template <typename T>
bool inspect(T const& v);

I want to test if it returns `true` for the following values:

    1 (type int)
    10 (type int)
    1.0 (type double)
    "Y" (type const char *)

Basically, different values of different types, but sometimes different
values have the same type. I would like to write one test or "test
template" with the following contents:


Where `v` is name of the currently tested value. (But `v`s will have
different types). I can emulate this behavior using template test cases and
artificial types:

struct int_1 {
  static int value() { return 1; }
struct int_10 {
  static int value() { return 10; }
struct double_1 {
  static double value() { return 1.0; }
struct cstr_Y {
  static const char * value() { return "Y"; }

typedef boost::mpl::list<int_1, int_10, double_1, cstr_Y> test_types;

BOOST_AUTO_TEST_CASE_TEMPLATE( my_test, T, test_types )

(See working example in WandBox:

But maybe there exists a direct solution in Boost.Test? Where I would just
pass a list of values: `{1, 10, 1.0, "Y"}`

It is easy to deduce types from values:

template <typename... T>
mpl::liss<T...> Values(T... values);

using test_types = decltype(Values(1, 10, 1.0, "Y"));

Does something like this exist, or ois it a reasonable extension?


Boost list run by bdawes at, gregod at, cpdaniel at, john at