Skip to content

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

@SamPan0212

Description

@SamPan0212

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions