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


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

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:

```
BOOST_TEST((inspect(v)));
```

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 )
{
  BOOST_TEST(inspect(T::value()));
}
```

(See working example in WandBox:
https://wandbox.org/permlink/KcJqT8KvL3zIqAxL)

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?

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk