Boost logo

Boost :

Subject: Re: [boost] [boost-test] question about using templates for tests
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-07-19 14:46:39


On Saturday 19 July 2014 13:47:14 Damian Vicino wrote:
> Hi,
> I’m trying to test a template with different parameters and I can’t figure
> out how to do it for the following case.
>
> My class is something like this:
> template<class T, class M,
> template<class, class> class F>
> class C
> {
> T t;
> M m;
> F<T, std::shared_ptr<C<T, M, F>;
> Public:
> …
> }
>
> So my test, should receive 3 template classes, first 2 normal classes and a
> third which receives 2 Template Parameters.
>
> For now I’m just duplicating the tests for each implementation I write for F
> and they pass. Anyway, it is starting to be hard to maintain, a template
> solution would be great.
>
> F is suppose to receive a priority_queue like parameter, something getting a
> value and a comparison operator. For example, this is one of the
> parameters I’m testing with:
> template <class VALUE_TYPE, class COMPARE_TYPE>
> using priority_queue_vector = std::priority_queue<VALUE_TYPE,
> std::vector<VALUE_TYPE>, COMPARE_TYPE>;
>
> Is it possible to do this with current Boost.Test?

You can create test templates like this:

typedef mpl::vector< T1, T2, T3 > types;

BOOST_AUTO_TEST_CASE_TEMPLATE(my_test, T, types)
{
  // Here T will be one of the 'types'
}

In your case you can create an mpl::vector of specializations of your class C
you want to test.


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