I am trying to test my C library with google test but I'm having trouble mocking functions with the fff.h
framework. This is my file structure:
.
├── Makefile.am
├── configure.ac
├── include
│ ├── Makefile.am
│ └── public_header.h
├── src
│ └── libmylib
│ ├── Makefile.am
│ ├── private_functions.c
│ ├── private_functions.h
│ ├── libmylib.la
│ └── libmylib.c
└── test
└── libmylib_test
├── Makefile.am
├── fff.h
└── test.cc
I want to mock a function from the header private_functions.h
which is used in a function from the public_header.h
using the fff.h
framework.
public_function()
{
private_function(); //This function is the one I want to mock.
}
My test looks like this:
#include "gtest/gtest.h"
#include "public_header.h"
#include "fff.h"
extern "C" {
#include "private_functions.h"
}
DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC(int, function, char *, char *);
class libtest : public testing::Test
{
public:
virtual void SetUp()
{
RESET_FAKE(function);
}
virtual void TearDown()
{
}
};
TEST_F(libtest, test_fff)
{
public_function("val1", "val2");
EXPECT_EQ(function_fake.call_count, 1);
}
...
When I run make it says that the private_function()
is defined multiple times.
My test/libmylib_test/MakeFile.am
looks like this:
LIBSRC = $(top_srcdir)/src/libstorage
check_PROGRAMS = libmylib_test
libstorage_test_SOURCES = test.cc
libstorage_test_CFLAGS = $(AM_CFLAGS)
libstorage_test_CXXFLAGS = -I$(top_srcdir)/include -I$(LIBSRC) -std=c++11 $(AM_CPPFLAGS)
libstorage_test_LDFLAGS = $(AM_LDFLAGS) -static -pthread
libstorage_test_LDADD = $(top_srcdir)/src/libmylib/libmylib.la
C++
conversant (and so cannot answer), this question appears to be well researched, well presented and includes clear problem statement. And in case the close voter checks back, please leave a comment letting OP know how to fix problem. And IMO, This question does not appear to be about programming within the scope defined in the help center. does not describe this post in the least. – Kauslick