I would really advise taking a look at the Google C ++ Mocking Framework . Even if you don’t want to mock something, it allows you to easily write quite complex statements.
for example
//checks that vector v is {5, 10, 15} ASSERT_THAT(v, ElementsAre(5, 10, 15)); //checks that map m only have elements 1 => 10, 2 => 20 ASSERT_THAT(m, ElementsAre(Pair(1, 10), Pair(2, 20))); //checks that in vector v all the elements are greater than 10 and less than 20 ASSERT_THAT(v, Each(AllOf(Gt(10), Lt(20)))); //checks that vector v consist of // 5, number greater than 10, anything. ASSERT_THAT(v, ElementsAre(5, Gt(10), _));
There are many matches for all kinds of situations, and you can combine them to achieve just about anything.
Did I tell you that ElementsAre only needs iterators and the size() method in the class? So it works not only with any container from STL, but also with custom containers.
Google Mock claims to be nearly as portable as Google Test, and to be honest, I don’t understand why you won’t use it. This is just awesome.
vava May 9 '10 at 2:53 a.m. 2010-05-09 14:53
source share