[gnome-commander/googletest] Creates a class of tests to be run only if x11 libs are available
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/googletest] Creates a class of tests to be run only if x11 libs are available
- Date: Tue, 24 Nov 2015 20:43:04 +0000 (UTC)
commit d7ee5edbefdd5206e78db464411c766d58312b06
Author: Uwe Scholz <uwescholz src gnome org>
Date: Sat Nov 14 18:56:00 2015 +0100
Creates a class of tests to be run only if x11 libs are available
I started with the already existing test for the dualrenderer in the
internal viewer library. In the configure step the search for x11 libs
is added as we need to search for a running X-session in those tests. If
no x11 libs are available by accident, the tests are already skipped in
the Makefile of the tests-directory.
If the libs are available but no session is running, the test are
automatically skipped in the binary files of the tests (see
iv_dualrenderer_test.cc as a first example).
configure.ac | 8 ++++++++
tests/Makefile.am | 18 +++++++++++++-----
tests/iv_dualrenderer_test.cc | 13 +++++++++++--
3 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6ea9a17..0de08d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,6 +108,14 @@ fi
AC_SUBST(GMODULE_AVAIL)
+dnl Find out if x11 libs are available. The variable X11_LIBS is set
+dnl if libX11 is found.
+PKG_CHECK_MODULES(X11, x11,
+ [AC_MSG_RESULT([x11-libs found, associated tests will be executed if a display is available])],
+ [AC_MSG_WARN([x11 missing, tests which need a display will be skipped by default])])
+AM_CONDITIONAL(HAVE_X11, test -n "$X11_LIBS")
+
+
dnl Check for gtk+
AC_MSG_CHECKING(if gtk+ >= ${GTK_REQ} exists)
if pkg-config --exists gtk+-2.0 ; then
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 479ecd7..9de37b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,21 +19,29 @@ TESTS = \
iv_fileops \
iv_bm_search \
iv_datapresentation \
- iv_dualrenderer \
iv_imagerenderer \
iv_inputmodes \
iv_textrenderer
+if HAVE_X11
+TESTS += \
+ iv_dualrenderer
+endif
+
+
check_PROGRAMS = $(TESTS)
# *** Internal Viewer Tests *** Most of these only consist of serialised
# function calls for acceptance tests, acutally. Functions of the internal
-# viewer library are not fully tested by unit tests. Currently, I don't
+# viewer library are not fully tested by unit tests! Currently, I don't
# feel that there is a need of adding unit tests for this nicely working
-# library. Some of these tests require a running X session.
-iv_dualrenderer_SOURCES = iv_dualrenderer_test.cc gcmd_tests_main.cc
+# library. Some of these tests require a running X session. It is checked
+# if a session is running in the binaries. If not, the test is skipped.
+if HAVE_X11
+iv_dualrenderer_SOURCES = iv_dualrenderer_test.cc
iv_dualrenderer_CXXFLAGS = $(INTVLIBS)
-iv_dualrenderer_LDFLAGS = $(INTVLIBS) -lgtest
+iv_dualrenderer_LDFLAGS = $(INTVLIBS) -lX11 -lgtest
+endif
iv_imagerenderer_SOURCES = iv_imagerenderer_test.cc gcmd_tests_main.cc
iv_imagerenderer_CXXFLAGS = $(INTVLIBS)
diff --git a/tests/iv_dualrenderer_test.cc b/tests/iv_dualrenderer_test.cc
index f0e7cf8..a175502 100644
--- a/tests/iv_dualrenderer_test.cc
+++ b/tests/iv_dualrenderer_test.cc
@@ -26,10 +26,11 @@
*/
#include "gtest/gtest.h"
-#include <iv_dualrenderer_test.h>
+#include <intviewer/libgviewer.h>
+#include <X11/Xlib.h> // to check for an available display
+class DualRendererTest : public ::testing::Test {};
TEST_F(DualRendererTest, dualrenderer_test) {
-
GtkWidget *window;
GtkWidget *tscrollbox, *iscrollbox;
GtkWidget *imgr;
@@ -92,3 +93,11 @@ TEST_F(DualRendererTest, dualrenderer_test) {
}
gtk_widget_destroy (window);
}
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ if (XOpenDisplay(NULL))
+ return RUN_ALL_TESTS();
+ else
+ return(77);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]