[gnome-photos] Add infrastructure for application tests
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add infrastructure for application tests
- Date: Thu, 20 Mar 2014 13:23:48 +0000 (UTC)
commit 51a0b2c0b0214e682ac28cb1a16e78e675cb0602
Author: Pranav Kant <pranav913 gmail com>
Date: Wed Mar 19 13:50:20 2014 +0530
Add infrastructure for application tests
Based on gnome-weather.
https://bugzilla.gnome.org/show_bug.cgi?id=725156
Makefile.am | 6 ++-
configure.ac | 11 ++++-
glib-tap.mk | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++
m4/glibtests.m4 | 28 +++++++++++
tests/Makefile.am | 29 +++++++++++
tests/basic.py | 24 +++++++++
tests/testutil.py | 68 +++++++++++++++++++++++++++
7 files changed, 297 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 622fbf7..c55c782 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4 -I libgd ${ACLOCAL_FLAGS}
-SUBDIRS = . data libgd src po
+SUBDIRS = . data libgd src po tests
INTLTOOL_FILES = \
intltool-extract.in \
@@ -58,8 +58,10 @@ MAINTAINERCLEANFILES = \
$(NULL)
GITIGNOREFILES = \
- m4 \
config \
+ m4/intltool.m4 \
+ m4/libtool.m4 \
+ m4/lt* \
$(NULL)
AUTHORS:
diff --git a/configure.ac b/configure.ac
index 3339e09..28c2951 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@ AC_CONFIG_SRCDIR([src])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
-AM_INIT_AUTOMAKE([dist-xz no-dist-gzip tar-ustar])
+AM_INIT_AUTOMAKE([dist-xz no-dist-gzip serial-tests tar-ustar])
AM_MAINTAINER_MODE([enable])
AC_PROG_CC
@@ -119,6 +119,14 @@ LIBGD_INIT([
tagged-entry
])
+AC_ARG_ENABLE(dogtail,
+ [AS_HELP_STRING([--enable-dogtail],
+ [test using dogtail [default=yes]])],,
+ enable_dogtail=yes)
+AM_CONDITIONAL(ENABLE_DOGTAIL, test "$enable_dogtail" != no)
+
+GLIB_TESTS
+
GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
AC_SUBST(GLIB_COMPILE_RESOURCES)
@@ -135,6 +143,7 @@ data/org.gnome.Photos.desktop.in
data/icons/Makefile
libgd/Makefile
src/Makefile
+tests/Makefile
po/Makefile.in
])
AC_OUTPUT
diff --git a/glib-tap.mk b/glib-tap.mk
new file mode 100644
index 0000000..de272a7
--- /dev/null
+++ b/glib-tap.mk
@@ -0,0 +1,134 @@
+# GLIB - Library of useful C routines
+
+TESTS_ENVIRONMENT= \
+ G_TEST_SRCDIR="$(abs_srcdir)" \
+ G_TEST_BUILDDIR="$(abs_builddir)" \
+ G_DEBUG=gc-friendly \
+ MALLOC_CHECK_=2 \
+ MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/tap-test
+
+NULL =
+
+# initialize variables for unconditional += appending
+BUILT_SOURCES =
+BUILT_EXTRA_DIST =
+CLEANFILES = *.log *.trs
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+TESTS =
+
+installed_test_LTLIBRARIES =
+installed_test_PROGRAMS =
+installed_test_SCRIPTS =
+nobase_installed_test_DATA =
+
+noinst_LTLIBRARIES =
+noinst_PROGRAMS =
+noinst_SCRIPTS =
+noinst_DATA =
+
+check_LTLIBRARIES =
+check_PROGRAMS =
+check_SCRIPTS =
+check_DATA =
+
+# We support a fairly large range of possible variables. It is expected that all types of files in a test
suite
+# will belong in exactly one of the following variables.
+#
+# First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
+#
+# test_programs, test_scripts, test_data, test_ltlibraries
+#
+# The above are used to list files that are involved in both uninstalled and installed testing. The
+# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
+# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data
is
+# installed in the same way as it appears in the package layout.
+#
+# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
+# like so:
+#
+# installed_test_programs, uninstalled_test_programs
+# installed_test_scripts, uninstalled_test_scripts
+# installed_test_data, uninstalled_test_data
+# installed_test_ltlibraries, uninstalled_test_ltlibraries
+#
+# Additionally, we support 'extra' infixes for programs and scripts. This is used for support
programs/scripts
+# that should not themselves be run as testcases (but exist to be used from other testcases):
+#
+# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
+# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
+#
+# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or
data
+# file automatically end up in the tarball.
+#
+# dist_test_scripts, dist_test_data, dist_test_extra_scripts
+# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
+# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
+#
+# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows
the
+# standard automake convention of not disting programs scripts or data by default.
+#
+# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their
disted
+# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under
+# gtester. That's a bit strange for scripts, but it's possible.
+
+TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
+ $(dist_test_scripts) $(dist_uninstalled_test_scripts)
+
+# Note: build even the installed-only targets during 'make check' to ensure that they still work.
+# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
+# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
+# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
+all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(uninstalled_test_extra_programs)
$(installed_test_extra_programs)
+all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(uninstalled_test_extra_scripts)
$(installed_test_extra_scripts)
+all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts)
\
+ $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts)
$(dist_installed_test_extra_scripts)
+all_test_scripts += $(all_dist_test_scripts)
+EXTRA_DIST += $(all_dist_test_scripts)
+all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data)
+all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
+all_test_data += $(all_dist_test_data)
+EXTRA_DIST += $(all_dist_test_data)
+all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
+
+if ENABLE_ALWAYS_BUILD_TESTS
+noinst_LTLIBRARIES += $(all_test_ltlibs)
+noinst_PROGRAMS += $(all_test_programs)
+noinst_SCRIPTS += $(all_test_scripts)
+noinst_DATA += $(all_test_data)
+else
+check_LTLIBRARIES += $(all_test_ltlibs)
+check_PROGRAMS += $(all_test_programs)
+check_SCRIPTS += $(all_test_scripts)
+check_DATA += $(all_test_data)
+endif
+
+if ENABLE_INSTALLED_TESTS
+installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(installed_test_extra_programs)
+installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(test_installed_extra_scripts)
+installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
+ $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
+nobase_installed_test_DATA += $(test_data) $(installed_test_data)
+nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
+installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
+installed_testcases = $(test_programs) $(installed_test_programs) \
+ $(test_scripts) $(installed_test_scripts) \
+ $(dist_test_scripts) $(dist_installed_test_scripts)
+
+installed_test_meta_DATA = $(installed_testcases:=.test)
+
+%.test: %$(EXEEXT) Makefile
+ $(AM_V_GEN) (echo '[Test]' > $ tmp; \
+ echo 'Type=session-exclusive' >> $ tmp; \
+ echo 'Exec=$(installed_testdir)/$(notdir $<)' >> $ tmp; \
+ mv $ tmp $@)
+
+CLEANFILES += $(installed_test_meta_DATA)
+endif
diff --git a/m4/glibtests.m4 b/m4/glibtests.m4
new file mode 100644
index 0000000..7d5920a
--- /dev/null
+++ b/m4/glibtests.m4
@@ -0,0 +1,28 @@
+dnl GLIB_TESTS
+dnl
+
+AC_DEFUN([GLIB_TESTS],
+[
+ AC_ARG_ENABLE(installed-tests,
+ AS_HELP_STRING([--enable-installed-tests],
+ [Enable installation of some test cases]),
+ [case ${enableval} in
+ yes) ENABLE_INSTALLED_TESTS="1" ;;
+ no) ENABLE_INSTALLED_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-installed-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], test "$ENABLE_INSTALLED_TESTS" = "1")
+ AC_ARG_ENABLE(always-build-tests,
+ AS_HELP_STRING([--enable-always-build-tests],
+ [Enable always building tests during 'make all']),
+ [case ${enableval} in
+ yes) ENABLE_ALWAYS_BUILD_TESTS="1" ;;
+ no) ENABLE_ALWAYS_BUILD_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-always-build-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_ALWAYS_BUILD_TESTS], test "$ENABLE_ALWAYS_BUILD_TESTS" = "1")
+ if test "$ENABLE_INSTALLED_TESTS" = "1"; then
+ AC_SUBST(installed_test_metadir, [${datadir}/installed-tests/]AC_PACKAGE_NAME)
+ AC_SUBST(installed_testdir, [${libexecdir}/installed-tests/]AC_PACKAGE_NAME)
+ fi
+])
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..ff7d6ce
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,29 @@
+include $(top_srcdir)/glib-tap.mk
+
+dogtail_tests = \
+ basic.py \
+ $(NULL)
+
+TESTS_ENVIRONMENT += \
+ LC_ALL=C \
+ GSETTINGS_BACKEND=memory \
+ $(NULL)
+
+if ENABLE_DOGTAIL
+dist_test_scripts = $(dogtail_tests)
+dist_test_data = \
+ testutil.py \
+ $(NULL)
+
+CLEANFILES += \
+ *.pyc \
+ $(NULL)
+
+else
+EXTRA_DIST += \
+ $(dogtail_tests) \
+ testutil.py \
+ $(NULL)
+endif
+
+include $(top_srcdir)/git.mk
diff --git a/tests/basic.py b/tests/basic.py
new file mode 100755
index 0000000..a767685
--- /dev/null
+++ b/tests/basic.py
@@ -0,0 +1,24 @@
+#! /usr/bin/python
+
+from testutil import *
+
+from gi.repository import Gio, GLib
+
+import os, sys
+import pyatspi
+from dogtail import tree
+from dogtail import utils
+from dogtail.procedural import *
+
+init()
+try:
+ app = start()
+
+ albums_button = app.child('Albums')
+ albums_button.click()
+ recent_button = app.child('Recent')
+ recent_button.click()
+ favorites_button = app.child('Favorites')
+ favorites_button.click()
+finally:
+ fini()
diff --git a/tests/testutil.py b/tests/testutil.py
new file mode 100644
index 0000000..da26386
--- /dev/null
+++ b/tests/testutil.py
@@ -0,0 +1,68 @@
+# -*- mode: python -*-
+
+from gi.repository import GLib, Gio
+
+from dogtail.utils import isA11yEnabled, enableA11y
+if not isA11yEnabled():
+ enableA11y(True)
+
+from dogtail import tree
+from dogtail import utils
+from dogtail.predicate import *
+from dogtail.procedural import *
+
+import os, sys
+import subprocess
+
+APPLICATION_ID = "org.gnome.Photos"
+
+_bus = None
+
+class IsTextEqual(Predicate):
+ """Predicate subclass that looks for top-level windows"""
+ def __init__(self, text):
+ self.text = text
+
+ def satisfiedByNode(self, node):
+ try:
+ textIface = node.queryText()
+ #print textIface.getText(0, -1)
+ return textIface.getText(0, -1) == self.text
+ except NotImplementedError:
+ return False
+
+ def describeSearchResult(self):
+ return '%s text node' % self.text
+
+def _do_bus_call(method, params):
+ global _bus
+
+ if _bus == None:
+ _bus = Gio.bus_get_sync(Gio.BusType.SESSION)
+
+ _bus.call_sync(APPLICATION_ID, '/' + APPLICATION_ID.replace('.', '/'),
+ 'org.freedesktop.Application',
+ method, params, None,
+ Gio.DBusCallFlags.NONE,
+ -1, None)
+
+def start():
+ builddir = os.environ.get('G_TEST_BUILDDIR', None)
+ if builddir and not 'TESTUTIL_DONT_START' in os.environ:
+ subprocess.Popen([os.path.join(builddir, '..', 'src', 'gnome-photos-service')],
+ cwd=os.path.join(builddir, '..'))
+ utils.doDelay(2)
+
+ _do_bus_call("Activate", GLib.Variant('(a{sv})', ([],)))
+ utils.doDelay(3)
+
+ app = tree.root.application('gnome-photos')
+ focus.application('gnome-photos')
+
+ return app
+
+def init():
+ pass
+
+def fini():
+ _do_bus_call("ActivateAction", GLib.Variant('(sava{sv})', ('quit', [], [])))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]