sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
66 stars 39 forks source link

in Googletest, mockcpp throw C++ exception lead to subsequent testcase timeout #51

Open SamPan0212 opened 1 year ago

SamPan0212 commented 1 year ago

OS: Ubuntu 18.04 Compiler: Clang15.0.6 Googletest: Googletest 1.13.0 mockcpp: 2.7

func.c int add(int a, int b){ return a+b; }

func.h int add(int a, int b);

mockcpp.cpp

include "gtest/gtest.h"

include "gmock/gmock.h"

include "mockcpp/mockcpp.hpp"

extern "C" {

include "func.h"

}

TEST(mockcpp, test_basicadd){ //This is a simple case to get mockcpp exception_ MOCKER(add).expects(once()).with(eq(2),eq(2)).will(returnValue(4)); int ret; ret = add(1,2); EXPECT_EQ(ret, 3); GlobalMockObject::verify(); }

TEST(mockcpp, test_basic_addtimeout){ int ret; //time out when call mock object_ ret = add(2,3); EXPECT_EQ(ret, 5); }

int main(int argc, char *argv[]) { ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); }

As the title says, mockcpp will throw an exception at the end of the test_basic_add case. in this case, because there is no execution that matched argument function. But in the next testcase, it will timeout when calling add, although we have called the verify() function

Observed from the debugger tool, it is stuck on mockcpp::ApiHookFunctor() ApiHookFunctor.h:168:1 -> std::mutex::lock

So I would like to ask if it is possible to provide a more comprehensive function than verify to clear all settings (including unlock mutex) We can put it in the SetUp, so that each testcase has a clean environment Or, is there any suitable solution to avoid this problem?

thanks -Sam