Actual function call count doesn't match EXPECT_CALL

2257 views
Skip to first unread message

Nagaraj CH

unread,
Aug 10, 2016, 10:50:02 AM8/10/16
to Google C++ Mocking Framework
class imUtils
{
public :
        virtual std::vector<std::int32_t> getSectorIds(std::int32_t);
};

class ResMap : public GTS::IMUTILS::imUtils
{
public:
        ResMap(){}

        std::vector<std::int32_t> getSectIdsFromBcfId(std::int32_t);
  
};

std::vector<std::int32_t> ResMap::getSectIdsFromBcfId(std::int32_t bcfId)
{
        std::vector<std::int32_t> sectList;
        std::cout << "*******Nagaraj Calling getSectorIds******" << std::endl;
        sectList = GTS::IMUTILS::imUtils::getSectorIds(bcfId);
        return sectList;
}

hi all, 

i am new to gmock, i have facing this issue. Please do the needful


class MockimUtils : public GTS::IMUTILS::imUtils
{
public :
        MOCK_METHOD1(getSectorIds, vector<std::int32_t>(std::int32_t bcfId));
};

TEST(ResMap, constructor)
{
        vector<std::int32_t> test_file;
        MockimUtils ImUtils;
        std::vector<std::int32_t> sectList;
        ResMap ResMapObj;
        EXPECT_CALL(ImUtils, getSectorIds(5))
                .Times(AtLeast(1));
        ResMapObj.getSectIdsFromBcfId(5);
}

o/p
Actual function call count doesn't match EXPECT_CALL(ImUtils, getSectorIds(5))...
         Expected: to be called at least once
           Actual: never called - unsatisfied and active
[  FAILED  ] ResMap.constructor (0 ms)
[----------] 1 test from ResMap (0 ms total)

Samuel Benzaquen

unread,
Aug 10, 2016, 3:07:39 PM8/10/16
to Nagaraj CH, Google C++ Mocking Framework
EXPECT_CALL tells the framework that you expect a call on that exact instance. That is, ImUtils.
But you are not using that instance at all. The calls are going to ResMapObj.
You can't intercept all calls to all objects. Only the ones on the mock instances.

One way to solve your problem is to make the mock derive from ResMap, set the EXPECT_CALL on that mock and only use that object.
However, I suggest to avoid mocking concrete types. It is usually not a good idea to override methods from concrete classes.
Don't know the details of your use case, so mocking ResMap directly might be ok.

_Sam
 
        ResMapObj.getSectIdsFromBcfId(5);
}

o/p
Actual function call count doesn't match EXPECT_CALL(ImUtils, getSectorIds(5))...
         Expected: to be called at least once
           Actual: never called - unsatisfied and active
[  FAILED  ] ResMap.constructor (0 ms)
[----------] 1 test from ResMap (0 ms total)

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/a199adfa-25fb-4b20-a9ad-3f66b2e48620%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages