Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SamPan0212 opened this issue Jul 20, 2023 · 0 comments

Comments

@SamPan0212
Copy link

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_basic_add){
//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_add_timeout){
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

@fish2bird fish2bird mentioned this issue Aug 25, 2023
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant