I want to test a template class with gtest. I read about TYPED_TEST
s in gtest manual and looked at the official example (samples\sample6_unittest.cc) they reference. This template from the example has only one template parameter.
But, my code has two template parameters, how can I test it?
I have the following code:
// two element type
template <typename E, typename F>
class QueueNew
{
public:
QueueNew() {}
void Enqueue(const E& element) {}
E* Dequeue() {}
F size() const
{
return (F)123;
}
};
for which I wrote the test code below:
template <class E, class F>
QueueNew<E, F>* CreateQueue();
template <>
QueueNew<int, int>* CreateQueue<int, int>()
{
return new QueueNew < int, int > ;
}
template <>
QueueNew<char, char>* CreateQueue<char, char>()
{
return new QueueNew < char, char > ;
}
template <class E, class F>
class QueueTestNew;
template <class E>
class QueueTestNew<E, int> : public testing::Test
{
protected:
QueueTestNew() : queue(CreateQueue<E, int>()){}
virtual ~QueueTestNew(){ delete queue; }
QueueNew<E, int>* const queue;
};
template <class E>
class QueueTestNew<char, E> : public testing::Test
{
protected:
QueueTestNew() : queue(CreateQueue<char, E>()){}
virtual ~QueueTestNew(){ delete queue; }
QueueNew<char, E>* const queue;
};
// The list of types we want to test.
typedef ::testing::Types <char, int> Implementations;
TYPED_TEST_CASE(QueueTestNew, Implementations);
TYPED_TEST(QueueTestNew, DefaultConstructor)
{
EXPECT_EQ(123u, this->queue->size());
}
but when building, I get the error:
error C2976: 'QueueTestNew' : too few template arguments
see declaration of 'QueueTestNew'
...
I think my test template method with gtest is wrong, so how should I do this?
QueueTestNew
to be type-parametrized by the that struct (nesting the additional template params). – Saiva