mocked class to library, problem with inline code

411 views
Skip to first unread message

Paul Hansen

unread,
Jan 27, 2012, 4:09:03 AM1/27/12
to Google C++ Mocking Framework
Hi

I want to put my mock'ed classes into a library. I don't use interface
and dependency injection. I want to make a mock-library where mocked
classes have the same name as the classes in the production code and
then link with the mock-library instead of the production code
library.

class ProductionClass {
MOCK_METHOD0(void ProductionMethod());
};

My problem is that MOCK_METHOD0 is preprocessed to an inline function
and the inline code does not go into the object file (and thus not
into the mock-library) when compiled.

When compiling I still use -I/path/to/production/code/header/files so
the header file of the mocked class is not included (and thus inline
code is not included)

So the question is: What do I do to make the code not-inline so it
does get into the object file?

I tried to compile with "-O0 -fno-default-inline" (using gnu g++
compiler) but MOCK_MEHTHOD0 code still does not go into object file (I
check with nm and objdump)

Thank you very much
Paul

Greg Miller

unread,
Jan 27, 2012, 10:43:37 AM1/27/12
to Paul Hansen, Google C++ Mocking Framework
Hi, Paul.

On Fri, Jan 27, 2012 at 4:09 AM, Paul Hansen <paul.han...@gmail.com> wrote:
Hi

I want to put my mock'ed classes into a library. I don't use interface
and dependency injection. I want to make a mock-library where mocked
classes have the same name as the classes in the production code and
then link with the mock-library instead of the production code
library.

class ProductionClass {
 MOCK_METHOD0(void ProductionMethod());
};

My problem is that MOCK_METHOD0 is preprocessed to an inline function
and the inline code does not go into the object file (and thus not
into the mock-library) when compiled.

When compiling I still use -I/path/to/production/code/header/files so
the header file of the mocked class is not included (and thus inline
code is not included)

Therein lies the problem. To use the mock object, your code should include the header for the mock object. Perhaps you can do this simply by changing your include path when compiling. It's asking for trouble to try to use code compiled against ProductionClass version 1 and link it with (unrelated) ProductionClass version 2—the classes may not even be the same size.

Greg
Reply all
Reply to author
Forward
0 new messages