本文介绍了EXPECT_CALL of googlemock导致“未知文件:错误:在测试主体中抛出的代码0xc0000005的SEH异常”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是googlemock的新手。我当前的项目需要googlemock来使用。我从google帮助网站的gmock基础知识。但是当我试图在我的项目中实现相同的,它提出了 SEH异常与代码0xc0000005 错误。
我的项目有多个线程,其中一个线程调用RUN_ALL_TESTS
上面的代码导致 SEH exception

I am novice to googlemock. My current project needs googlemock to use. I have learned from basics of gmock from google help site. But when I have tried to implement the same in my project it threw SEH exception with code 0xc0000005 error.My project has multiple threads, one of the thread call RUN_ALL_TESTSThe above code leads to SEH exception

工具:VS2010,windows 7

tools: VS2010, windows 7

尝试模拟类的函数

using ::testing::Return;
using ::testing::Test;
using ::testing::NiceMock;

class OsInterfaceCPP
{  

public: 

    OsInterfaceCPP(void){};
    virtual ~OsInterfaceCPP(void){};
    virtual int add_test(int a, int b) = 0;
    int calladdtest(int aa, int bb)
    {
        return add_test(aa,bb);
    }
};  
class OsCPPApis : public OsInterfaceCPP 
{  
public: 
    OsCPPApis(void){};
    virtual ~OsCPPApis(void){};
    virtual int add_test(int aa, int bb)
    {
        return (aa+bb);
    }
};

class MockedOSCPPApis : public  OsCPPApis
{
public:
    MockedOSCPPApis(void){};
    virtual ~MockedOSCPPApis(void){};
    MOCK_METHOD2(add_test, int(int aaa, int bbb));
};


OSapiTestFunc::OSapiTestFunc(void){}

OSapiTestFunc::~OSapiTestFunc(void){}

void OSapiTestFunc::SetUp(){}

void OSapiTestFunc::TearDown(){}

void OSapiTestFunc::RunTests()
{
    int argc=0;
    char **argv = 0;
    ::testing::InitGoogleMock(&argc, argv); 

}

TEST_F(OSapiTestFunc, OS_Test1)
{

    OsCPPApis TestOscppapis;
    MockedOSCPPApis Testmockosapi;
    int a, b;
    a = 2;
    b = 5;
    bool test1var = true;
    EXPECT_CALL(Testmockosapi,add_test(a, b));

    TestOscppapis.add_test(5,3);
}


推荐答案

0xC0000005是不存在的内存。我现在看不到你的代码这里发生的确切位置。但这肯定是出了问题。你可能想用调试器运行,看看它认为它出错了。

0xC0000005 is a "you accessed memory that doesn't exist". I can't see exactly where in your code this happens right now. But that's definitely what goes wrong. You may want to run with a debugger and see where it thinks it goes wrong.

这篇关于EXPECT_CALL of googlemock导致“未知文件:错误:在测试主体中抛出的代码0xc0000005的SEH异常”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:23