gtest_ 使用 setargpointee 在函数中赋值

gtest_ assigning value in a function by using setargpointee

我正在使用 gtest 测试适配器函数,但无法在我的测试中成功使用 SetArgPointee。

class Adapter:{
    public:
    int getTaskStateAdapter(){
       //do something
       int task_state = -1;
       int exit_value = -1;
       result = getTaskState(&task_state, &exit_value);

       if(result != 0){
          //throws here
       }
       if(exit_value != 0){
          //throws here
       }

    return task_state; 
    }
}

我正在测试的是检查如果 exit_value 不为 0,适配器函数是否会抛出异常。

TEST(class_name, test_name){
    EXPECT_CALL(ClassMock::instance(), getTaskState(_,_)).WillOnce(DoAll(SetArgPointee<1>(-1), Return(0)));//Mock class is included in the test file

    EXPECT_THROW(Adapter::getTaskAdapter(), ERxEXC::Exception);//ERxEXC::Exception is a self-defined exception
}

然而,无论我在 SetArgPointee 中设置什么值 exit_value,都没有抛出异常。

这些测试代码完全正确,问题出在源码上。