Boost Filesystem path seg-fault

896 views
Skip to first unread message

Jonathan Herbst

unread,
Sep 27, 2011, 2:15:15 PM9/27/11
to Google C++ Mocking Framework
I am seeing a segmentation fault when I use a boost::filesystem::path
as a parameter to an expected method call and the call is not
matched. Has anyone else seen this problem? Am I doing something
wrong?

I have isolated the problem in the code below:
TestFoo1 succeeds; TestFoo2, 3, and 4 give me a segmentation fault.

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <boost/filesystem.hpp>

using namespace boost::filesystem;

class Foo
{
public:
Foo() {}
virtual ~Foo() {}

virtual void M(path& p, int i) {}
};

class Bar
{
public:
Bar(Foo* foo):
m_foo(foo)
{}

void M(path& p, int i)
{
m_foo->M(p, i);
}

Foo* m_foo;
};

class MockFoo: public Foo
{
public:
MOCK_METHOD2(M, void(path& p, int i));
};

TEST(BarTest, TestFoo1)
{
MockFoo foo;
Bar bar(&foo);
path p = "path1";

EXPECT_CALL(foo, M(p, 5)).Times(1);
bar.M(p, 5);
}

TEST(BarTest, TestFoo2)
{
MockFoo foo;
Bar bar(&foo);
path p = "path1";

EXPECT_CALL(foo, M(p, 5)).Times(1);
bar.M(p, 6);
}

TEST(BarTest, TestFoo3)
{
MockFoo foo;
Bar bar(&foo);
path p = "path1";
path p2 = "path2";

EXPECT_CALL(foo, M(p2, 6)).Times(1);
bar.M(p, 6);
}

TEST(BarTest, TestFoo4)
{
MockFoo foo;
Bar bar(&foo);
path p = "path1";

bar.M(p, 6);
}

int main(int argc, char** argv)
{
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}

Vlad Losev

unread,
Oct 2, 2011, 3:17:59 AM10/2/11
to Google C++ Mocking Framework
If you build the samples with -g and run them under gdb, what extra information does it give you? What about running the program under Vlagrind?

amanji...@gmx.de

unread,
Oct 4, 2011, 3:00:16 PM10/4/11
to Google C++ Mocking Framework


On Sep 27, 8:15 pm, Jonathan Herbst <jherb...@gmail.com> wrote:
> I am seeing a segmentation fault when I use a boost::filesystem::path
> as a parameter to an expected method call and the call is not
> matched.  Has anyone else seen this problem? Am I doing something
> wrong?

Hi,

AFAIK there is a recursion occuring before you segfault -->
stackvoverflow. gtest somehow can't figure out how to print a
boost::filesystem::path ....

solution - define this:

namespace testing {
namespace internal {
void PrintTo(const boost::filesystem::path& p, std::ostream*
os) {
*os << p;
}
}
}
Message has been deleted

Jonathan Herbst

unread,
Oct 6, 2011, 8:22:18 PM10/6/11
to Google C++ Mocking Framework
Holy crap thanks, that works perfectly. I had tried overloading
printing functions, but I think I got the namespaces wrong.
Reply all
Reply to author
Forward
0 new messages