summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-06-22 18:38:03 -0700
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-07-09 18:20:42 +0000
commitc20acf63d1ec457b11d40915e89a5decc5d4532d (patch)
treef6a413d73a07cb14c0f6964731fdb3f09d6d5941
parent592128cd44aac754d4ae87950d410895a78fddd7 (diff)
downloadsdbusplus-c20acf63d1ec457b11d40915e89a5decc5d4532d.tar.gz
sdbusplus-c20acf63d1ec457b11d40915e89a5decc5d4532d.zip
test: Support mocking with googletest
We should include gmock in our gtest dependencies so that we can use it in future test cases. There is no harm in adding this depdency as we should always build it with googletest and doesnt interfere with current gtests. Tested: All of the tests still pass and newer tests using gmock will now work. Change-Id: Ie53f63f4926b88178c384cc1150b98555dafd7ec Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--configure.ac25
-rw-r--r--test/Makefile.am5
2 files changed, 28 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index a959d31..b1f7c70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,6 +92,7 @@ AS_IF([test "x$enable_tests" != "xno"], [
# Check/set gtest specific functions.
AS_IF([test "x$enable_tests" != "xno"], [
PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
+ PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
@@ -113,6 +114,17 @@ AS_IF([test "x$enable_tests" != "xno"], [
AC_LANG_POP([C++])
AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
+ AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
+ AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
+ AC_LANG_PUSH([C++])
+ AC_CHECK_HEADERS([gmock/gmock.h], [], [
+ AS_IF([test "x$enable_tests" = "xyes"], [
+ AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
+ ])
+ ])
+ AC_LANG_POP([C++])
+ AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
+
AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
AC_CHECK_LIB([gtest], [main], [
@@ -125,6 +137,19 @@ AS_IF([test "x$enable_tests" != "xno"], [
])
])
AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
+
+ AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
+ AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
+ AC_CHECK_LIB([gmock], [main], [
+ AS_IF([test "x$GMOCK_LIBS" = "x"], [
+ AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
+ ])
+ ], [
+ AS_IF([test "x$enable_tests" = "xyes"], [
+ AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
+ ])
+ ])
+ AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
])
# Code coverage
diff --git a/test/Makefile.am b/test/Makefile.am
index 5061933..0c71949 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,12 +3,13 @@
if WANT_LIBSDBUSPLUS
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) \
- $(GTEST_CFLAGS) $(SYSTEMD_CFLAGS) $(CODE_COVERAGE_CPPFLAGS)
+ $(GTEST_CFLAGS) $(GMOCK_CFLAGS) $(SYSTEMD_CFLAGS) \
+ $(CODE_COVERAGE_CPPFLAGS)
AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
test_ldadd = $(top_builddir)/libsdbusplus.la $(SYSTEMD_LIBS) \
$(OESDK_TESTCASE_FLAGS) $(CODE_COVERAGE_LIBS)
-gtest_ldadd = $(test_ldadd) $(GTEST_LIBS) -lgtest_main
+gtest_ldadd = $(test_ldadd) $(GTEST_LIBS) $(GMOCK_LIBS) -lgmock_main
legacy_test_cxxflags = $(AM_CXXFLAGS) $(PTHREAD_CFLAGS)
legacy_test_ldadd = $(test_ldadd) $(PTHREAD_LIBS)
OpenPOWER on IntegriCloud