chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

I have the following function I would like to test:

bool QualityLib::isGood(int quality)
MSC_NAMESPACE::ObjectQuality objectQuality;

return objectQuality.isGood();

Here is my test:

void tst_QualityLib::isGood()
ObjectQuality *fakeObjectQuality = FAKE_ALL<ObjectQuality>();

const int QUALITY = 192;

QualityLib qualityLib(0);

bool result = qualityLib.isGood(QUALITY);
ASSERT_WAS_CALLED (fakeObjectQuality->setValue(_));
ASSERT_WAS_CALLED (fakeObjectQuality->isGood());
QCOMPARE(result, true);

How to I test that the value 192 was actually passed to setValue() ? Also can I use ASSERT_WAS_CALLED to test the ObjectQuality constructor, istead of using my setValue method?

asked by JamesKing (8.2k points)

2 Answers

0 votes
Hi James,

In order to check arguments values you can use the DoInstead API.
So in your case it can be something like this:

class Helper
void FakeSetValue(int val);

void Helper::FakeSetValue(int val)
ASSERT_EQ(192, val);
// test code
Helper h;
WHEN_CALLED(fakeObjectQuality->setValue(0)).DoMemberFunctionInstead(&h, FakeSetValue);
answered by Shai Barak (1.5k points)
0 votes
Thanks for the detailed answer!
answered by JamesKing (8.2k points)