[gnome-photos/wip/rishi/unit-tests: 4/4] tests: Add unit tests
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/unit-tests: 4/4] tests: Add unit tests
- Date: Fri, 2 Nov 2018 12:45:05 +0000 (UTC)
commit aa82da2af024be461cfe3ada3449fe1cc6cf3f69
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Oct 23 20:43:27 2018 +0200
tests: Add unit tests
configure.ac | 1 +
meson.build | 3 ++
template-tap.test.in | 4 +++
tests/Makefile.am | 2 ++
tests/meson.build | 2 ++
tests/unit/Makefile.am | 30 +++++++++++++++++++
tests/unit/meson.build | 63 +++++++++++++++++++++++++++++++++++++++
tests/unit/photos-test-pipeline.c | 40 +++++++++++++++++++++++++
8 files changed, 145 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index e399bdf5..274a4cb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ help/Makefile
subprojects/libgd/Makefile
src/Makefile
tests/Makefile
+tests/unit/Makefile
po/Makefile.in
])
AC_OUTPUT
diff --git a/meson.build b/meson.build
index 2b492062..62882972 100644
--- a/meson.build
+++ b/meson.build
@@ -23,12 +23,15 @@ photos_namespace = 'org.gnome.Photos'
photos_buildtype = get_option('buildtype')
photos_installed_tests_enabled = get_option('installed_tests')
+photos_installed_tests_template_tap = files('template-tap.test.in')
+
gnome = import('gnome')
i18n = import('i18n')
source_root = meson.current_source_dir()
po_dir = join_paths(source_root, 'po')
+src_inc = include_directories('src')
top_inc = include_directories('.')
photos_commit_id = ''
diff --git a/template-tap.test.in b/template-tap.test.in
new file mode 100644
index 00000000..6adf73f0
--- /dev/null
+++ b/template-tap.test.in
@@ -0,0 +1,4 @@
+[Test]
+Type=session
+Exec=@installed_tests_dir@/@program@ --tap
+Output=TAP
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2a1a7745..9bf271e9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/glib-tap.mk
+SUBDIRS = unit
+
dogtail_tests = \
basic.py \
$(NULL)
diff --git a/tests/meson.build b/tests/meson.build
index e4396f05..eea33e20 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,3 +1,5 @@
+subdir('unit')
+
test_name = 'basic.py'
if photos_installed_tests_enabled
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
new file mode 100644
index 00000000..419f2a2e
--- /dev/null
+++ b/tests/unit/Makefile.am
@@ -0,0 +1,30 @@
+include $(top_srcdir)/glib-tap.mk
+
+AM_TESTS_ENVIRONMENT += \
+ GSETTINGS_BACKEND=memory \
+ $(NULL)
+
+test_programs = \
+ photos-test-pipeline
+ $(NULL)
+
+AM_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(NULL)
+
+AM_CPPFLAGS = \
+ $(GLIB_CFLAGS) \
+ -I$(top_builddir)/src \
+ -I$(top_srcdir)/src \
+ $(NULL)
+
+LDADD = \
+ $(GLIB_LIBS) \
+ $(top_builddir)/src/libgnome-photos.la \
+ $(NULL)
+
+AM_LDFLAGS = \
+ $(WARN_LDFLAGS) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
new file mode 100644
index 00000000..f6535d5f
--- /dev/null
+++ b/tests/unit/meson.build
@@ -0,0 +1,63 @@
+# Not entirely random of course, but at least it changes over time
+meson_minor_version = meson.version().split('.').get(1).to_int()
+photos_minor_version = meson.project_version().split('.').get(1).to_int()
+random_number = meson_minor_version + photos_minor_version
+
+test_env = environment()
+test_env.set('G_DEBUG', 'gc-friendly')
+test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
+test_env.set('GSETTINGS_BACKEND', 'memory')
+test_env.set('MALLOC_CHECK_', '2')
+test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
+
+test_deps = [
+ glib_dep,
+ libgnome_photos_dep,
+]
+
+tests = {
+ 'photos-test-pipeline': {},
+}
+
+foreach test_name, extra_args: tests
+ extra_sources = extra_args.get('extra_sources', [])
+ install = photos_installed_tests_enabled and extra_args.get('install', true)
+ is_parallel = extra_args.get('is_parallel', true)
+ source = extra_args.get('source', test_name + '.c')
+ suite = extra_args.get('suite', [])
+
+ if install
+ test_conf = configuration_data()
+ test_conf.set('installed_tests_dir', photos_installed_test_execdir)
+ test_conf.set('program', test_name)
+ configure_file(
+ input: photos_installed_tests_template_tap,
+ output: test_name + '.test',
+ configuration: test_conf,
+ install: true,
+ install_dir: photos_installed_test_metadir,
+ )
+ endif
+
+ exe = executable(
+ test_name,
+ [source, extra_sources],
+ include_directories: [src_inc, top_inc],
+ dependencies: test_deps,
+ install: install,
+ install_dir: photos_installed_test_execdir,
+ install_rpath: photos_libdir,
+ )
+
+ timeout = suite.contains('slow') ? 120 : 30
+ test(
+ test_name,
+ exe,
+ env: test_env,
+ timeout: timeout,
+ suite: suite,
+ args: ['--tap'],
+ is_parallel: is_parallel,
+ )
+endforeach
diff --git a/tests/unit/photos-test-pipeline.c b/tests/unit/photos-test-pipeline.c
new file mode 100644
index 00000000..ce0f2e75
--- /dev/null
+++ b/tests/unit/photos-test-pipeline.c
@@ -0,0 +1,40 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <locale.h>
+
+#include <glib.h>
+
+#include "photos-debug.h"
+
+
+gint
+main (gint argc, gchar *argv[])
+{
+ gint exit_status;
+
+ setlocale (LC_ALL, "");
+ g_test_init (&argc, &argv, NULL);
+ photos_debug_init ();
+
+ exit_status = g_test_run ();
+ return exit_status;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]