From 318b35e3dac7b0a8b4dd6c3c97959eee64adf93d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sat, 6 Oct 2018 00:47:45 +0100 Subject: [PATCH] libeos-parental-controls: Add placeholder unit tests This commit is mostly to put the test framework in place, and create a placeholder test library for libeos-parental-controls for packaging. Signed-off-by: Philip Withnall https://phabricator.endlessm.com/T23859 --- libeos-parental-controls/meson.build | 4 +- libeos-parental-controls/tests/app-filter.c | 48 ++++++++++++++++++++ libeos-parental-controls/tests/meson.build | 50 +++++++++++++++++++++ meson.build | 9 ++++ meson_options.txt | 6 +++ template.test.in | 3 ++ 6 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 libeos-parental-controls/tests/app-filter.c create mode 100644 libeos-parental-controls/tests/meson.build create mode 100644 meson_options.txt create mode 100644 template.test.in diff --git a/libeos-parental-controls/meson.build b/libeos-parental-controls/meson.build index d801dd9..1336742 100644 --- a/libeos-parental-controls/meson.build +++ b/libeos-parental-controls/meson.build @@ -53,4 +53,6 @@ gnome.generate_gir(libeos_parental_controls, export_packages: 'libeos-parental-controls', includes: ['GObject-2.0', 'Gio-2.0'], install: true, -) \ No newline at end of file +) + +subdir('tests') \ No newline at end of file diff --git a/libeos-parental-controls/tests/app-filter.c b/libeos-parental-controls/tests/app-filter.c new file mode 100644 index 0000000..e0b1d28 --- /dev/null +++ b/libeos-parental-controls/tests/app-filter.c @@ -0,0 +1,48 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright © 2018 Endless Mobile, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * - Philip Withnall + */ + +#include "config.h" + +#include +#include +#include +#include + + +/* A placeholder smoketest which checks that the error quark works. */ +static void +test_app_filter_error_quark (void) +{ + g_assert_cmpint (epc_app_filter_error_quark (), !=, 0); +} + +int +main (int argc, + char **argv) +{ + setlocale (LC_ALL, ""); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/app-filter/error-quark", test_app_filter_error_quark); + + return g_test_run (); +} diff --git a/libeos-parental-controls/tests/meson.build b/libeos-parental-controls/tests/meson.build new file mode 100644 index 0000000..eba3e96 --- /dev/null +++ b/libeos-parental-controls/tests/meson.build @@ -0,0 +1,50 @@ +deps = [ + dependency('gio-2.0', version: '>= 2.44'), + dependency('glib-2.0', version: '>= 2.54.2'), + dependency('gobject-2.0', version: '>= 2.44'), + libeos_parental_controls_dep, +] + +envs = test_env + [ + 'G_TEST_SRCDIR=' + meson.current_source_dir(), + 'G_TEST_BUILDDIR=' + meson.current_build_dir(), +] + +test_programs = [ + ['app-filter', [], deps], +] + +installed_tests_metadir = join_paths(datadir, 'installed-tests', + 'libeos-parental-controls-' + libeos_parental_controls_api_version) +installed_tests_execdir = join_paths(libexecdir, 'installed-tests', + 'libeos-parental-controls-' + libeos_parental_controls_api_version) + +foreach program: test_programs + test_conf = configuration_data() + test_conf.set('installed_tests_dir', installed_tests_execdir) + test_conf.set('program', program[0]) + + configure_file( + input: test_template, + output: program[0] + '.test', + install: enable_installed_tests, + install_dir: installed_tests_metadir, + configuration: test_conf, + ) + + exe = executable( + program[0], + [program[0] + '.c'] + program[1], + dependencies: program[2], + include_directories: root_inc, + install: enable_installed_tests, + install_dir: installed_tests_execdir, + ) + + test( + program[0], + exe, + env: envs, + args: ['--tap'], + ) +endforeach \ No newline at end of file diff --git a/meson.build b/meson.build index daeb3b2..c8e66b0 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,7 @@ po_dir = join_paths(meson.source_root(), 'po') prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) datadir = join_paths(prefix, get_option('datadir')) +libexecdir = join_paths(prefix, get_option('libexecdir')) # FIXME: This isn’t exposed in accountsservice.pc # See https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/16 @@ -103,6 +104,14 @@ test_c_args = [ cc = meson.get_compiler('c') add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c') +enable_installed_tests = get_option('installed_tests') +test_template = files('template.test.in') +test_env = [ + 'G_DEBUG=gc-friendly,fatal-warnings', + 'MALLOC_CHECK_=2', + 'LC_ALL=C.UTF-8', +] + subdir('accounts-service') subdir('eos-parental-controls-client') subdir('libeos-parental-controls') \ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..96a517d --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,6 @@ +option( + 'installed_tests', + type: 'boolean', + value: false, + description: 'enable installed tests' +) \ No newline at end of file diff --git a/template.test.in b/template.test.in new file mode 100644 index 0000000..f701627 --- /dev/null +++ b/template.test.in @@ -0,0 +1,3 @@ +[Test] +Type=session +Exec=@installed_tests_dir@/@program@