Given this code:
class ToBeTested {
public:
void doForEach() {
for (vector<Contained>::iterator it = m_contained.begin(); it != m_contained.end(); it++) {
doOnce(*it);
doTwice(*it);
doTwice(*it);
}
}
void doOnce(Contained & c) {
}
void doTwice(Contained & c) {
}
private:
vector<Contained> m_contained;
}
I want to check that if I fill a vector with three values, my functions will be called in the correct order and quantity. For example, my test might look something like this:
tobeTested.AddContained(one);
tobeTested.AddContained(two);
tobeTested.AddContained(three);
BEGIN_PROC_TEST()
SHOULD_BE_CALLED(doOnce, 1)
SHOULD_BE_CALLED(doTwice, 2)
SHOULD_BE_CALLED(doOnce, 1)
SHOULD_BE_CALLED(doTwice, 2)
SHOULD_BE_CALLED(doOnce, 1)
SHOULD_BE_CALLED(doTwice, 2)
tobeTested.doForEach()
END_PROC_TEST()
How do you recommend testing this? Are there any tools for this using the CppUnit or GoogleTest frameworks? Maybe some other unit test frameworks allow you to run such tests?
I understand that perhaps this is not possible without calling any debugging functions from these functions, but at least it can be done automatically in some test environment. I do not like to scan trace logs and check their correctness.
UPD: , , ( , , ).