SEH exception with code 0xc0000005 error

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_TESTS The above code leads to SEH exception

tools: VS2010, windows 7

Try to mock the function of a class

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);
}
share | improve this question
 
 
Why do you inherit MockedOSCPPApis from OsCPPApis and not from the OsInterfaceCPP? As far I can see, there's nothing to mock from OsCPPApis it implements add_test(). –   πάντα ῥεῖ  Dec 28 '12 at 10:30
add comment

closed as too localized by Rob KennedyShaiRory McCrossanjv42EricFeb 14 '13 at 15:45

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

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.

share | improve this answer
  add comment

The only point I'd supect to be the reason for a (most probably) NULL pointer access is

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

Usually when this is called from a main() function as intended, at least argv never would be NULL because the first argument always contains the executable name.

UPDATE:
Note my edit how argc is passed! Simply the value not the address!

share | improve this answer
 
 
Could please elaborate more? Because when I run the program with Gmock I too did get the same error. –  Rasmi Ranjan Nayak  Dec 28 '12 at 11:18
 
@RasmiRanjanNayak Then it might be a problem with the MockedOSCPPApis class implementation as I mentioned in my comment on the question. –   πάντα ῥεῖ  Dec 28 '12 at 12:38
add comment
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值