Search code examples
googletestgooglemock

googlemock ON_CALL with SetArgPointee will not change from test case to test case


I have a TEST_F with the following:

    struct _pulse thePulse;
    thePulse.code = _PULSE_CODE_DISCONNECT;

    ON_CALL(Mock::Mock_QnxInterface::MockQnxInterface::getInstance(), MsgReceivePulse(_, _,_, _)).WillByDefault(DoAll(SetArgPointee<1>(thePulse),Return(EOK)));

I then have another test case that has the same lines of code, but this time, the value of thePulse.codeis _PULSE_CODE_MINAVAIL.

When I run the test suite, the case statement that checks for those constants always detects _PULSE_CODE_DISCONNECT but never the other case.

        if (EOK !=  MsgReceivePulse(attach->chid, (void*)&pulse, sizeof(pulse), NULL)) {
             // error handling code here
   
            } else {

                switch (pulse.code) {

                case _PULSE_CODE_DISCONNECT:
                    // code to clean up per-client info
                    break;
                case _PULSE_CODE_MINAVAIL:
                    // shut down the thread       
                    break;
                }
            }

It is as though the return side-effect of the mocked function MsgReceivePulse is using the same value from test case to test case. What am I doing wrong here?

I have tried EXPECT_CALL with similar options, using SetArgPointee without success.


Solution

  • I solved the problem. The EXPECT_CALL was set up properly, however, because I was testing a multi-threaded application, I realized that I was not properly stopping and restarting the thread after the first test case. The branch was never reached because that portion of code was never executed. After making the correction, the tests ran with different expectations.