jeudi 13 juin 2019

segmentation fault after running all gtest test case

I am testing a C++ function, which inside will call a C function. So I am mocking the C function using most voted answer here:

Can gmock be used for stubbing C functions?

So now I have a global variable in my ".t.cpp", my ".t.cpp" looks like:

LibXMock LibXMockObj; 
TEST(Test, test1){
    ....
    EXPECT_CALL(LibXMockObj, lib_x_function()).WillOnce(DoAll(SetArrayArgument<1>(123), Return(1)));
    ...
}

TEST(Test, test2){ 
    ...
    EXPECT_CALL(LibXMockObj, lib_x_function()).WillOnce(DoAll(SetArrayArgument<1>(121234), Return(2)));
    ...
}

TEST(Test, test3){
    ...
    EXPECT_CALL(LibXMockObj, lib_x_function()).WillOnce(Throw(bsl::runtime_error(Throw(runtime_error("someError")));
   ...
   delete &MockObj;
}

I got memory leak. So I searched and add "Mock::AllowLeak(&MockObj);" within each test case. But it gives me segment fault after passing all the tests

[----------] Global test environment tear-down
[==========] 10 tests from 10 test cases ran. (52 ms total)
[  PASSED  ] 10 tests.
Segmentation Fault (core dumped)

Anyone knows why? Is it about the global mock object? Thanks

Aucun commentaire:

Enregistrer un commentaire