Open GoogleCodeExporter opened 9 years ago
I can reproduce the same issue with compiler GNU g++ 4.7.3:
Here's code that can reproduce the issue:
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using testing::NiceMock;
class Foo {
public:
virtual ~Foo() {}
virtual void DoThis() = 0;
virtual int DoThat(bool flag) = 0;
};
class FooMock : public Foo {
public:
FooMock() {}
MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag));
};
// If uncommented, g++ 4.6.3+ will crash before main() is called
// NiceMock<FooMock> *g_mockFoo = new NiceMock<FooMock>;
// If uncommected, g++ 4.6.3+ will crash before main() is called
// NiceMock<FooMock> g_mockFoo2;
TEST(NiceMockTest, ThisTestPasses)
{
NiceMock<FooMock> mockFoo; // Does not cause crash
mockFoo.DoThis();
mockFoo.DoThat(true);
}
Original comment by Gramanda...@gmail.com
on 5 Sep 2014 at 2:12
I should elaborate why this is important to me... If I have a "C" interface
that I want to mock, to translate between c and c++ gmock library, I do this:
myfile.c
--------
void add1() { Best_Add1(); }
void sub1() { Best_Sub1(); }
myMock.cpp
----------
class MockBest {
public:
MOCK_METHOD0(Add1, void());
MOCK_METHOD0(Sub1, void());
};
NiceMock<MockBest> bestMock;
extern "C" {
Better_Add1(){
bestMock.Add1();
}
Better_Sub1(){
bestMock.Sub1();
}
};
Without NiceMock, this design works perfectly well, however, when adding in
NiceMock, I get the above crash which is preventing me from testing "C"
interfaces with GoogleMock library (unless I want to see thousands of warnings)
;-). Please help evaluate a workaround, and possibly increase the priority of
this fix.
Original comment by Gramanda...@gmail.com
on 5 Sep 2014 at 2:25
I'll try making the g_uninteresting_call_reaction map a lazily-initialized
object accessible only through an accessor function. But I really think you
should do the same with your bestMock. Then you probably wouldn't have this
problem.
class MockBest {
public:
MOCK_METHOD0(Add1, void());
MOCK_METHOD0(Sub1, void());
};
MockBest& GetMockBest() {
static NiceMock<MockBest> v = NiceMock<MockBest>();
return v;
}
extern "C" {
Better_Add1(){
GetMockBest().Add1();
}
Better_Sub1(){
GetMockBest().Sub1();
}
};
Original comment by billydon...@google.com
on 6 Sep 2014 at 6:30
Original issue reported on code.google.com by
threepea...@gmail.com
on 23 May 2014 at 8:52