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
struct ServerObjectFixture2 {

ServerObjectFixture2() {

m_pFakeServObj = FAKE_ALL<ServerObject>();

}

~ServerObjectFixture2() {

}

ServerObject* m_pFakeServObj;

};

BOOST_FIXTURE_TEST_CASE(testGetWhenPlatfromReturnsDataOnSearch, ServerObjectFixture2) {

ServerObjectDataList outList;

ServerObjectData *servObj = new ServerObjectData();

servObj->setGenericName(GENERIC_NAME);

servObj->setAttachmentFilePath(ATTACHMENT_NAME);

servObj->setChangeType(CHANGE_TYPE);

servObj->setComments(COMMENTS);

servObj->setOwner(OWNER);

servObj->setXREF(XREF);

servObj->setObjectID(OBJ_ID);

servObj->setObjectName(OBJ_NAME);

servObj->setObjectType(OBJ_TYPE);

servObj->setReason(REASON);

servObj->setAttributeValue(ATTR_1_KEY, ATTR_1_VALUE);

servObj->setAttributeValue(ATTR_2_KEY, ATTR_2_VALUE);

servObj->setAttributeValue(ATTR_3_KEY, ATTR_3_VALUE);

outList.push_back(servObj);

WHEN_CALLED(m_pFakeServObj->searchObjByName(ANY_REF(std::string), ANY_REF(std::string), RET(outList), ANY_REF(MessageList))).Ignore();

WHEN_CALLED(m_pFakeServObj->searchObjByID(ANY_REF(std::string), ANY_REF(std::string), RET(outList), ANY_REF(MessageList))).Ignore();

GetHandler *getHdlr = new GetHandler(\\\" \\\", \\\" \\\", \\\" \\\", \\\" \\\", \\\" \\\", \\\" \\\");

GetRequest req(\\\"\\\", \\\"\\\", \\\"\\\", \\\"\\\", \\\"\\\", \\\"\\\");

GetResponse resp;

getHdlr->handle(req, resp);

std::string str = resp.getResponse();

}

GetHandler is implemented in a seperate dll and ServerObject is also coming from a seperate dll.

GetHandler::handle creates ServerObject object internally.

The intent is to FAKE ServerObject::searchObjByName and ServerObject::searchObjByID, these are public and exported APIs in ServerObject dll.

In the above scenario, ServerObject is not getting faked.

What am I missing?
asked by abhikbagchi (600 points)
edited by abhikbagchi

1 Answer

0 votes

Hi,

From what I can see in the code you sent, the FAKE_ALL macro is being used outside of the test itself.

I suggest you write the fake inside the test so it will activate it.

For example, if you want to fake ServerObject::searchObjByName and ServerObject::searchObjByID

Inside the test write: 

ServerObjectFixture2* fakeobject = FAKE_ALL<ServerObject>();

Or, if the struct was made just for the fake, you can not use the struct and simply write: ServerObject* fakeobject = FAKE_ALL<ServerObject>(); inside the test.

Cheers,

Alon Sapozhnikov.

Support Specialist at TypeMock. 

answered by Alon_TypeMock (10.6k points)

Thanks for your prompt response. I tried out what you suggested, but still it's not working

BOOST_FIXTURE_TEST_CASE(testGetWhenPlatfromReturnsDataOnSearch, ServerObjectFixture2) {

ServerObject* m_pFakeServObj = FAKE_ALL<ServerObject>();

ServerObjectDataList outList;

ServerObjectData *servObj = new ServerObjectData();

servObj->setGenericName(GENERIC_NAME);

servObj->setAttachmentFilePath(ATTACHMENT_NAME);

servObj->setChangeType(CHANGE_TYPE);

servObj->setComments(COMMENTS);

servObj->setOwner(OWNER);

servObj->setXREF(XREF);

servObj->setObjectID(OBJ_ID);

servObj->setObjectName(OBJ_NAME);

servObj->setObjectType(OBJ_TYPE);

servObj->setReason(REASON);

servObj->setAttributeValue(ATTR_1_KEY, ATTR_1_VALUE);

servObj->setAttributeValue(ATTR_2_KEY, ATTR_2_VALUE);

servObj->setAttributeValue(ATTR_3_KEY, ATTR_3_VALUE);

outList.push_back(servObj);

WHEN_CALLED(m_pFakeServObj->searchObjByName(ANY_REF(std::string), ANY_REF(std::string), RET(outList), ANY_REF(MessageList))).Ignore();

WHEN_CALLED(m_pFakeServObj->searchObjByID(ANY_REF(std::string), ANY_REF(std::string), RET(outList), ANY_REF(MessageList))).Ignore();

GetHandler *getHdlr = new GetHandler(" ", " ", " ", " ", " ", " ");

GetRequest req("", "", "", "", "", "");

GetResponse resp;

getHdlr->handle(req, resp);

std::string str = resp.getResponse();

}

A quick question, in what operating system are you running the tests, Linux or Windows?

As for the test itself, from what I see the test should pass.

Perhaps it's a local bug.

Please try the following:

Try to reproduce it without the separate DLL's.

And keep me posted.

OS: Windows 10 Enterprise

OK, tnx for the quick reply.

I will wait for your update on running without the separated DLLs.

...