From dbbf76932088d686bc5b568f4d3bef28ff18d505 Mon Sep 17 00:00:00 2001 From: rpm-build Date: Dec 09 2020 17:12:07 +0000 Subject: ibus-1682157-ci.patch patch_name: ibus-1682157-ci.patch present_in_specfile: true location_in_specfile: 7 --- diff --git a/conf/dconf/config.c b/conf/dconf/config.c index 500ea1d..30ac137 100644 --- a/conf/dconf/config.c +++ b/conf/dconf/config.c @@ -335,7 +335,19 @@ ibus_config_dconf_set_value (IBusConfigService *config, } #ifdef DCONF_0_13_4 - retval = dconf_client_write_fast (client, gkey, value, error); + /* Use dconf_client_write_sync() instead of dconf_client_write_fast() + * because dconf_client_write_fast() does not sync the data when + * ibus_config_get_values() is called immediately after + * ibus_config_set_value() is called. + * We won't add a new API for the sync only since IBusConfig is + * now deprecated and GSettings is recommended. + */ + retval = dconf_client_write_sync (client, + gkey, + value, + NULL, + NULL, + error); #else retval = dconf_client_write (client, gkey, diff --git a/configure.ac b/configure.ac index 670493c..46ab7a9 100644 --- a/configure.ac +++ b/configure.ac @@ -628,6 +628,18 @@ PKG_CHECK_MODULES(XTEST, ) AM_CONDITIONAL([ENABLE_XTEST], [test x"$enable_xtest" = x"yes"]) +# --enable-install-tests +AC_ARG_ENABLE(install-tests, + AS_HELP_STRING([--enable-install-tests], + [Enable to install tests]), + [enable_install_tests=$enableval], + [enable_install_tests=no] +) +AM_CONDITIONAL([ENABLE_INSTALL_TESTS], [test x"$enable_install_tests" = x"yes"]) +if test x"$enable_install_tests" = x"no"; then + enable_install_tests="no (disabled, use --enable-install-tests to enable)" +fi + # --disable-emoji-dict option. AC_ARG_ENABLE(emoji-dict, @@ -807,5 +819,6 @@ Build options: Enable Unicode dict $enable_unicode_dict UCD directory $UCD_DIR Run test cases $enable_tests + Install tests $enable_install_tests ]) diff --git a/src/ibuscomposetable.c b/src/ibuscomposetable.c index 1c0ece4..43641c0 100644 --- a/src/ibuscomposetable.c +++ b/src/ibuscomposetable.c @@ -491,13 +491,18 @@ static gchar * ibus_compose_hash_get_cache_path (guint32 hash) { gchar *basename = NULL; + const gchar *cache_dir; gchar *dir = NULL; gchar *path = NULL; basename = g_strdup_printf ("%08x.cache", hash); - dir = g_build_filename (g_get_user_cache_dir (), - "ibus", "compose", NULL); + if ((cache_dir = g_getenv ("IBUS_COMPOSE_CACHE_DIR"))) { + dir = g_strdup (cache_dir); + } else { + dir = g_build_filename (g_get_user_cache_dir (), + "ibus", "compose", NULL); + } path = g_build_filename (dir, basename, NULL); if (g_mkdir_with_parents (dir, 0755) != 0) { g_warning ("Failed to mkdir %s", dir); @@ -866,7 +871,7 @@ ibus_compose_table_list_add_array (GSList *compose_tables, for (i = 0; i < length; i++) ibus_compose_seqs[i] = data[i]; - compose_table = g_new (IBusComposeTable, 1); + compose_table = g_new0 (IBusComposeTable, 1); compose_table->data = ibus_compose_seqs; compose_table->max_seq_len = max_seq_len; compose_table->n_seqs = n_seqs; diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index e337a59..2e75932 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -3,7 +3,7 @@ # ibus - The Input Bus # # Copyright (c) 2007-2015 Peng Huang -# Copyright (c) 2015-2018 Takao Fujiwara +# Copyright (c) 2015-2019 Takao Fujiwara # Copyright (c) 2007-2018 Red Hat, Inc. # # This library is free software; you can redistribute it and/or @@ -55,6 +55,8 @@ TESTS = \ ibus-util \ $(NULL) +CLEANFILES = + if ENABLE_ENGINE TESTS += ibus-engine-switch endif @@ -78,7 +80,60 @@ TESTS_ENVIRONMENT = \ LOG_COMPILER = $(srcdir)/runtest -EXTRA_DIST = runtest +if ENABLE_INSTALL_TESTS +bin_SCRIPTS = ibus-desktop-testing-runner +test_metas_in = meta.test.in +test_execs = $(TESTS:ibus-compose=ibus-compose-locales) +test_metas = $(addsuffix .test, $(test_execs)) +test_sources_DATA = \ + $(test_metas) \ + ibus-compose.emoji \ + ibus-compose.env \ + $(NULL) +test_sourcesdir = $(datadir)/installed-tests/ibus + +CLEANFILES += \ + $(test_metas) \ + ibus-desktop-testing-runner \ + $(NULL) + +test_execs_PROGRAMS = $(TESTS) +if ENABLE_GTK3 +test_execs_SCRIPTS = ibus-compose-locales +CLEANFILES += \ + ibus-compose-locales \ + $(NULL) +endif +test_execsdir = $(libexecdir)/installed-tests/ibus +endif + +$(test_metas): $(test_metas_in) $(test_programs) + f=`echo $@ | sed -e 's/\.test//'`; \ + TEST_EXEC=$(test_execsdir)/$$f; \ + sed -e "s|@TEST_EXEC[@]|$$TEST_EXEC|g" $(test_metas_in) > $@.tmp; \ + mv $@.tmp $@; \ + $(NULL) + +ibus-compose-locales: ibus-compose-locales.in + SRCDIR=$(test_sourcesdir); \ + sed -e "s|@SRCDIR[@]|$$SRCDIR|g" $< > $@.tmp; \ + mv $@.tmp $@; \ + $(NULL) + +ibus-desktop-testing-runner: ibus-desktop-testing-runner.in + INSTALLEDDIR=$(datadir)/installed-tests; \ + sed -e "s|@INSTALLEDDIR[@]|$$INSTALLEDDIR|g" $< > $@.tmp; \ + mv $@.tmp $@; \ + $(NULL) + +EXTRA_DIST = \ + $(test_metas_in) \ + runtest \ + ibus-compose.emoji \ + ibus-compose.env \ + ibus-compose-locales.in \ + ibus-desktop-testing-runner.in \ + $(NULL) ibus_bus_SOURCES = ibus-bus.c ibus_bus_LDADD = $(prog_ldadd) diff --git a/src/tests/ibus-compose-locales.in b/src/tests/ibus-compose-locales.in new file mode 100755 index 0000000..b36165f --- /dev/null +++ b/src/tests/ibus-compose-locales.in @@ -0,0 +1,32 @@ +#!/bin/sh + +SRCDIR=@SRCDIR@ +BUILDDIR=`dirname $0` + + +export IBUS_COMPOSE_CACHE_DIR=$PWD + +retval=0 +# Deleted for var in `cat *.env` because IFS=$'\n' is not supported in POSIX sh +while read var +do + IS_COMMENT=`echo "$var" | grep "^#"` + if [ "x$IS_COMMENT" != x ] ; then + continue + fi + # Use $* instead of $@ not to mix strings and integers + echo "# Starting $var $BUILDDIR/ibus-compose $SRCDIR $*" + # Need to enclose $@ with double quotes not to split the array. + env $var $BUILDDIR/ibus-compose $SRCDIR "$@" + retval=`expr $retval + $?` + echo "# Finished $var $BUILDDIR/ibus-compose $SRCDIR $* with $retval" + + CACHE_FILES=`ls *.cache` + if [ x"$CACHE_FILES" != x ] ; then + echo "Clean $CACHE_FILES" + rm $CACHE_FILES + fi +done << EOF_ENVS +`cat $SRCDIR/ibus-compose.env` +EOF_ENVS +exit $retval diff --git a/src/tests/ibus-compose.c b/src/tests/ibus-compose.c index aabb36a..e60cebf 100644 --- a/src/tests/ibus-compose.c +++ b/src/tests/ibus-compose.c @@ -7,9 +7,10 @@ #define NC "\033[0m" IBusBus *m_bus; +gchar *m_compose_file; IBusComposeTable *m_compose_table; IBusEngine *m_engine; -int m_retval; +gchar *m_srcdir; static gboolean window_focus_in_event_cb (GtkWidget *entry, GdkEventFocus *event, @@ -31,8 +32,11 @@ create_engine_cb (IBusFactory *factory, const gchar *name, gpointer data) engine_path, ibus_bus_get_connection (m_bus)); g_free (engine_path); - langs = g_get_language_names (); - for (l = langs; *l; l++) { + if (m_compose_file) { + compose_path = g_build_filename (m_srcdir, m_compose_file, NULL); + } else { + langs = g_get_language_names (); + for (l = langs; *l; l++) { if (g_str_has_prefix (*l, "en_US")) break; if (g_strcmp0 (*l, "C") == 0) @@ -45,6 +49,7 @@ create_engine_cb (IBusFactory *factory, const gchar *name, gpointer data) break; g_free (compose_path); compose_path = NULL; + } } if (compose_path != NULL) { m_compose_table = ibus_compose_table_new_with_file (compose_path); @@ -104,8 +109,7 @@ register_ibus_engine () static gboolean finit (gpointer data) { - m_retval = -1; - g_warning ("time out"); + g_test_incomplete ("time out"); gtk_main_quit (); return FALSE; } @@ -120,7 +124,9 @@ set_engine_cb (GObject *object, GAsyncResult *res, gpointer data) int index_stride; if (!ibus_bus_set_global_engine_async_finish (bus, res, &error)) { - g_warning ("set engine failed: %s", error->message); + gchar *msg = g_strdup_printf ("set engine failed: %s", error->message); + g_test_incomplete (msg); + g_free (msg); g_error_free (error); return; } @@ -203,7 +209,7 @@ window_inserted_text_cb (GtkEntryBuffer *buffer, test = GREEN "PASS" NC; } else { test = RED "FAIL" NC; - m_retval = -1; + g_test_fail (); } g_print ("%05d/%05d %s expected: %04X typed: %04X\n", seq, @@ -242,17 +248,52 @@ create_window () gtk_widget_show_all (window); } +static void +test_compose (void) +{ + GLogLevelFlags flags; + if (!register_ibus_engine ()) { + g_test_fail (); + return; + } + + create_window (); + /* FIXME: + * IBusIMContext opens GtkIMContextSimple as the slave and + * GtkIMContextSimple opens the compose table on el_GR.UTF-8, and the + * multiple outputs in el_GR's compose causes a warning in gtkcomposetable + * and the warning always causes a fatal in GTest: + " "GTK+ supports to output one char only: " + */ + flags = g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); + gtk_main (); + g_log_set_always_fatal (flags); +} + int main (int argc, char *argv[]) { + const gchar *test_name; + gchar *test_path; + ibus_init (); + /* Avoid a warning of "AT-SPI: Could not obtain desktop path or name" + * with gtk_main(). + */ + g_setenv ("NO_AT_BRIDGE", "1", TRUE); + g_test_init (&argc, &argv, NULL); gtk_init (&argc, &argv); - if (!register_ibus_engine ()) - return -1; - - create_window (); - gtk_main (); + m_srcdir = argc > 1 ? g_strdup (argv[1]) : g_strdup ("."); + m_compose_file = g_strdup (g_getenv ("COMPOSE_FILE")); +#if GLIB_CHECK_VERSION (2, 58, 0) + test_name = g_get_language_names_with_category ("LC_CTYPE")[0]; +#else + test_name = g_getenv ("LANG"); +#endif + test_path = g_build_filename ("/ibus-compose", test_name, NULL); + g_test_add_func (test_path, test_compose); + g_free (test_path); - return m_retval; + return g_test_run (); } diff --git a/src/tests/ibus-compose.emoji b/src/tests/ibus-compose.emoji new file mode 100644 index 0000000..57e7ae6 --- /dev/null +++ b/src/tests/ibus-compose.emoji @@ -0,0 +1,2 @@ + : "♌" U264C # LEO + : "∫" diff --git a/src/tests/ibus-compose.env b/src/tests/ibus-compose.env new file mode 100644 index 0000000..a9e289e --- /dev/null +++ b/src/tests/ibus-compose.env @@ -0,0 +1,4 @@ +LANG=el_GR.UTF-8 +LANG=fi_FI.UTF-8 +LANG=pt_BR.UTF-8 +LANG=en_US.UTF-8 COMPOSE_FILE=ibus-compose.emoji diff --git a/src/tests/ibus-config.c b/src/tests/ibus-config.c index c6141ab..32931bf 100644 --- a/src/tests/ibus-config.c +++ b/src/tests/ibus-config.c @@ -16,6 +16,10 @@ finish_create_config_async_success (GObject *source_object, IBusConfig *config = ibus_config_new_async_finish (res, &error); + if (error) { + g_message ("Failed to generate IBusConfig: %s", error->message); + g_error_free (error); + } g_assert (IBUS_IS_CONFIG (config)); /* Since we reuse single D-Bus connection, we need to remove the @@ -133,254 +137,6 @@ test_config_set_get (void) g_object_unref (config); } -typedef struct { - GMainLoop *loop; - guint timeout_id; - gchar *section; - gchar *name; -} WatchData; - -typedef struct { - gchar *section; - gchar *name; -} WatchKey; - -typedef struct { - WatchKey *watched; /* watched keys (null-terminated) */ - WatchKey *changed; /* changed keys (null-terminated) */ - WatchKey *notified; /* notified keys (same length as - changed, not null-terminated) */ -} WatchTestData; - -static WatchKey default_watched[] = { - { NULL } -}; -static WatchKey default_changed[] = { - { "test/s1", "n1" }, - { "test/s1", "n2" }, - { "test/s2", "n1" }, - { "test/s2", "n2" }, - { NULL } -}; -static WatchKey default_notified[] = { - { "test/s1", "n1" }, - { "test/s1", "n2" }, - { "test/s2", "n1" }, - { "test/s2", "n2" } -}; -static WatchTestData default_data = { - default_watched, - default_changed, - default_notified -}; - -static WatchKey section_watched[] = { - { "test/s1", NULL }, - { NULL } -}; -static WatchKey section_notified[] = { - { "test/s1", "n1" }, - { "test/s1", "n2" }, - { NULL, NULL }, - { NULL, NULL }, -}; -static WatchTestData section_data = { - section_watched, - default_changed, - section_notified -}; - -static WatchKey section_multiple_watched[] = { - { "test/s1", NULL }, - { "test/s2", NULL }, - { NULL } -}; -static WatchKey section_multiple_notified[] = { - { "test/s1", "n1" }, - { "test/s1", "n2" }, - { "test/s2", "n1" }, - { "test/s2", "n2" }, -}; -static WatchTestData section_multiple_data = { - section_multiple_watched, - default_changed, - section_multiple_notified -}; - -static WatchKey section_name_watched[] = { - { "test/s1", "n1" }, - { NULL } -}; -static WatchKey section_name_notified[] = { - { "test/s1", "n1" }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -}; -static WatchTestData section_name_data = { - section_name_watched, - default_changed, - section_name_notified -}; - -static WatchKey section_name_multiple_watched[] = { - { "test/s1", "n1" }, - { "test/s2", "n2" }, - { NULL } -}; -static WatchKey section_name_multiple_notified[] = { - { "test/s1", "n1" }, - { NULL, NULL }, - { NULL, NULL }, - { "test/s2", "n2" }, -}; -static WatchTestData section_name_multiple_data = { - section_name_multiple_watched, - default_changed, - section_name_multiple_notified -}; - -typedef struct { - IBusConfig *config; - WatchData data; -} WatchFixture; - -static void -value_changed_cb (IBusConfig *config, - const gchar *section, - const gchar *name, - GVariant *value, - gpointer user_data) -{ - WatchData *data = (WatchData *) user_data; - - data->section = g_strdup (section); - data->name = g_strdup (name); - - g_main_loop_quit (data->loop); -} - -static gboolean -timeout_cb (gpointer user_data) -{ - WatchData *data = (WatchData *) user_data; - g_main_loop_quit (data->loop); - data->timeout_id = 0; - return FALSE; -} - -static void -change_and_test (IBusConfig *config, - const gchar *section, - const gchar *name, - const gchar *expected_section, - const gchar *expected_name, - WatchData *data) -{ - gboolean retval; - GVariant *var; - - data->section = NULL; - data->name = NULL; - - /* Unset won't notify value-changed signal. */ - var = ibus_config_get_values (config, section); - if (var != NULL) { - GVariant *value = g_variant_lookup_value (var, name, - G_VARIANT_TYPE_VARIANT); - if (value != NULL) { - ibus_config_unset (config, section, name); - g_variant_unref (value); - } - g_variant_unref (var); - } - - data->timeout_id = g_timeout_add (1, timeout_cb, data); - g_main_loop_run (data->loop); - if (data->timeout_id != 0) { - g_source_remove (data->timeout_id); - } - - retval = ibus_config_set_value (config, section, name, - g_variant_new_int32 (1)); - g_assert (retval); - - data->timeout_id = g_timeout_add (1, timeout_cb, data); - g_main_loop_run (data->loop); - if (data->timeout_id != 0) { - g_source_remove (data->timeout_id); - } - - g_assert_cmpstr (data->section, ==, expected_section); - g_assert_cmpstr (data->name, ==, expected_name); - - g_free (data->section); - g_free (data->name); -} - -static void -watch_fixture_setup (WatchFixture *fixture, gconstpointer user_data) -{ - fixture->config = ibus_config_new (ibus_bus_get_connection (bus), - NULL, - NULL); - g_assert (fixture->config); - - fixture->data.loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (fixture->config, "value-changed", - G_CALLBACK (value_changed_cb), &fixture->data); -} - -static void -watch_fixture_teardown (WatchFixture *fixture, gconstpointer user_data) -{ - g_main_loop_unref (fixture->data.loop); - - ibus_proxy_destroy (IBUS_PROXY (fixture->config)); - g_object_unref (fixture->config); -} - -static void -test_config_watch (WatchFixture *fixture, gconstpointer user_data) -{ - const WatchTestData *data = user_data; - gint i; - - for (i = 0; data->watched[i].section != NULL; i++) { - ibus_config_watch (fixture->config, - data->watched[i].section, - data->watched[i].name); - } - for (i = 0; data->changed[i].section != NULL; i++) { - change_and_test (fixture->config, - data->changed[i].section, - data->changed[i].name, - data->notified[i].section, - data->notified[i].name, - &fixture->data); - } - for (i = 0; data->watched[i].section != NULL; i++) { - ibus_config_unwatch (fixture->config, - data->watched[i].section, - data->watched[i].name); - } - if (i > 0) { - /* Check if the above unwatch takes effect. */ - for (i = 0; data->changed[i].section != NULL; i++) { - change_and_test (fixture->config, - data->changed[i].section, - data->changed[i].name, - NULL, - NULL, - &fixture->data); - } - } else { - /* Since we reuse single D-Bus connection, we need to remove the - default match rule for the next ibus_config_new() call. */ - ibus_config_unwatch (fixture->config, NULL, NULL); - } -} - gint main (gint argc, gchar **argv) @@ -390,41 +146,6 @@ main (gint argc, g_test_init (&argc, &argv, NULL); bus = ibus_bus_new (); - g_test_add ("/ibus/config-watch/default", - WatchFixture, - &default_data, - watch_fixture_setup, - test_config_watch, - watch_fixture_teardown); - - g_test_add ("/ibus/config-watch/section", - WatchFixture, - §ion_data, - watch_fixture_setup, - test_config_watch, - watch_fixture_teardown); - - g_test_add ("/ibus/config-watch/section-multiple", - WatchFixture, - §ion_multiple_data, - watch_fixture_setup, - test_config_watch, - watch_fixture_teardown); - - g_test_add ("/ibus/config-watch/section-name", - WatchFixture, - §ion_name_data, - watch_fixture_setup, - test_config_watch, - watch_fixture_teardown); - - g_test_add ("/ibus/config-watch/section-name-multiple", - WatchFixture, - §ion_name_multiple_data, - watch_fixture_setup, - test_config_watch, - watch_fixture_teardown); - g_test_add_func ("/ibus/create-config-async", test_create_config_async); g_test_add_func ("/ibus/config-set-get", test_config_set_get); diff --git a/src/tests/ibus-desktop-testing-runner.in b/src/tests/ibus-desktop-testing-runner.in new file mode 100755 index 0000000..4232c54 --- /dev/null +++ b/src/tests/ibus-desktop-testing-runner.in @@ -0,0 +1,400 @@ +#!/bin/sh +# -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- +# vim:set noet ts=4: +# +# ibus - The Input Bus +# +# Copyright (c) 2018-2020 Takao Fujiwara +# Copyright (c) 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 2 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# This test runs /usr/bin/ibus-daemon after install ibus +# +# # init 3 +# Login as root +# # /root/ibus/tests/test-console.sh --tests ibus-compose \ +# --builddir /root/ibus/src/tests --srcdir /root/ibus/src/tests + +# POSIX sh has no 'echo -e' +: ${ECHO:='/usr/bin/echo'} +# POSIX sh has $UID +# DASH saves the graves in '``' as characters not to be extracted +: ${UID:=`id -u`} + + +PROGNAME=`basename $0` +VERSION=0.1 +DISPLAY=:99.0 +BUILDDIR="." +SRCDIR="." +TEST_LOG="test-suite.log" +TEST_LOG_STDOUT=0 +RESULT_LOG="" +HAVE_GRAPHICS=1 +DESKTOP_COMMAND="dbus-launch --exit-with-session gnome-session" +PID_XORG=0 +PID_GNOME_SESSION=0 +TESTING_RUNNER="default" +TESTS="" +TIMEOUT=300 +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +print_log() +{ + if [ x"$RESULT_LOG" != x ] ; then + # avoid 'echo -e' before call 'sed'. + if [ x"$1" = x'-e' ] ; then + shift + fi + NO_ESCAPE=`echo "$@" | sed -e 's/\\\033\\[0;3.m//g' -e 's/\\\033\\[0m//g'` + $ECHO $NO_ESCAPE >> $RESULT_LOG + else + $ECHO "$@" + fi +} + +usage() +{ + $ECHO -e \ +"This test runs /usr/bin/ibus-daemon after install ibus\n" \ +"$PROGNAME [OPTIONS…]\n" \ +"\n" \ +"OPTIONS:\n" \ +"-h, --help This help\n" \ +"-v, --version Show version\n" \ +"-b, --builddir=BUILDDIR Set the BUILDDIR\n" \ +"-s, --srcdir=SOURCEDIR Set the SOURCEDIR\n" \ +"-c, --no-graphics Use Xvfb instead of Xorg\n" \ +"-d, --desktop=DESKTOP Run DESTKTOP. The default is gnome-session\n" \ +"-t, --tests=\"TESTS...\" Run TESTS programs which is separated by space\n" \ +"-r, --runner=RUNNER Run TESTS programs with a test RUNNER.\n" \ +" RUNNDER = gnome or default.\n" \ +" default is an embedded runner.\n" \ +"-T, --timeout=TIMEOUT Set timeout (default TIMEOUT is 300 sec).\n" \ +"-o, --output=OUTPUT_FILE OUtput the log to OUTPUT_FILE\n" \ +"-O, --result=RESULT_FILE OUtput the result to RESULT_FILE\n" \ +"" +} + +parse_args() +{ + # This is GNU getopt. "sudo port getopt" in BSD? + ARGS=`getopt -o hvb:s:cd:t:r:T:o:O: --long \ + help,version,builddir:,srcdir:,no-graphics,desktop:,tests:,runner:,timeout:,output:,result:\ + -- "$@"`; + eval set -- "$ARGS" + while [ 1 ] ; do + case "$1" in + -h | --help ) usage; exit 0;; + -v | --version ) $ECHO -e "$VERSION"; exit 0;; + -b | --builddir ) BUILDDIR="$2"; shift 2;; + -s | --srcdir ) SRCDIR="$2"; shift 2;; + -c | --no-graphics ) HAVE_GRAPHICS=0; shift;; + -d | --desktop ) DESKTOP_COMMAND="$2"; shift 2;; + -t | --tests ) TESTS="$2"; shift 2;; + -r | --runner ) TESTING_RUNNER="$2"; shift 2;; + -T | --timeout ) TIMEOUT="$2"; shift 2;; + -o | --output ) TEST_LOG="$2"; shift 2;; + -O | --result ) RESULT_LOG="$2"; shift 2;; + -- ) shift; break;; + * ) usage; exit 1;; + esac + done +} + +init_desktop() +{ + if [ "$RESULT_LOG" != "" ] ; then + if [ -f $RESULT_LOG ] ; then + rm $RESULT_LOG + fi + fi + HAS_STDOUT=`echo "$TEST_LOG" | grep ':stdout'` + if [ x"$HAS_STDOUT" != x ] ; then + TEST_LOG=`echo "$TEST_LOG" | sed -e 's|:stdout||'` + TEST_LOG_STDOUT=1 + fi + if [ "$TEST_LOG" = "" ] ; then + print_log -e "${RED}FAIL${NC}: ${RED}ERROR${NC}: a log file is required to get return value with 'read' command" + exit 255 + elif [ -f $TEST_LOG ] ; then + rm $TEST_LOG + fi + if [ x$FORCE_TEST != x ] ; then + RUN_ARGS="$RUN_ARGS --force" + fi + + if [ ! -f $HOME/.config/gnome-initial-setup-done ] ; then + IS_SYSTEM_ACCOUNT=false + if [ "$USER" = "root" ] ; then + IS_SYSTEM_ACCOUNT=true + fi + if test ! -f /var/lib/AccountsService/users/$USER ; then + mkdir -p /var/lib/AccountsService/users + cat >> /var/lib/AccountsService/users/$USER << _EOF +[User] +Language=ja_JP.UTF-8 +XSession=gnome +SystemAccount=$IS_SYSTEM_ACCOUNT +_EOF + fi + mkdir -p $HOME/.config + touch $HOME/.config/gnome-initial-setup-done + fi + + # Prevent from launching a XDG dialog + XDG_LOCALE_FILE="$HOME/.config/user-dirs.locale" + if [ -f $XDG_LOCALE_FILE ] ; then + XDG_LANG_ORIG=`cat $XDG_LOCALE_FILE` + XDG_LANG_NEW=`echo $LANG | sed -e 's/\(.*\)\..*/\1/'` + if [ "$XDG_LANG_ORIG" != "$XDG_LANG_NEW" ] ; then + echo "# Overriding XDG locale $XDG_LANG_ORIG with $XDG_LANG_NEW" + echo "$XDG_LANG_NEW" > $XDG_LOCALE_FILE + fi + fi + # `su` command does not run loginctl + export XDG_SESSION_TYPE='x11' + export XDG_SESSION_CLASS=user + # `su` command does not get focus in events without this variable. + # Need to restart sshd after set "PermitRootLogin yes" in sshd_config + if [ "x$XDG_RUNTIME_DIR" = x ] ; then + export XDG_RUNTIME_DIR="/run/user/$UID" + is_root_login=`grep "^PermitRootLogin" /etc/ssh/sshd_config | grep yes` + if [ "x$ANSIBLE" != x ] && [ "x$is_root_login" = x ] ; then + print_log -e "${RED}FAIL${NC}: No permission to get focus-in events in GtkWindow with ansible" + echo "su command does not configure necessary login info " \ + "with systemd and GtkWindow cannot receive focus-events " \ + "when ibus-desktop-testing-runner is executed by " \ + "ansible-playbook." >> $TEST_LOG + echo "Enabling root login via sshd, restarting sshd, set " \ + "XDG_RUNTIME_DIR can resolve the problem under " \ + "ansible-playbook." >> $TEST_LOG + exit 255 + fi + fi + # Do we need XDG_SESSION_ID and XDG_SEAT? + #export XDG_CONFIG_DIRS=/etc/xdg + #export XDG_SESSION_ID=10 + #export XDG_SESSION_DESKTOP=gnome + #export XDG_SEAT=seat0 +} + +run_dbus_daemon() +{ + # Use dbus-launch --exit-with-session later instead of --sh-syntax + # GNOME uses a unix:abstract address and it effects gsettings set values + # in each test case. + # TODO: Should we comment out this line? + export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus" +} + +run_desktop() +{ + if test $HAVE_GRAPHICS -eq 1 ; then + /usr/libexec/Xorg.wrap -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./xorg.log -config ./xorg.conf -configdir . $DISPLAY & + else + /usr/bin/Xvfb $DISPLAY -noreset +extension GLX +extension RANDR +extension RENDER -screen 0 1280x1024x24 & + fi + PID_XORG=$! + sleep 1 + export DISPLAY=$DISPLAY + echo "Running $DESKTOP_COMMAND with $USER in `tty`" + $DESKTOP_COMMAND & + PID_GNOME_SESSION=$! + sleep 30 + HAS_GNOME=`echo $DESKTOP_COMMAND | grep gnome-session` + if [ x"$HAS_GNOME" = x ] ; then + ibus-daemon --daemonize --verbose + sleep 3 + fi +} + +count_case_result() +{ + retval=$1 + pass=$2 + fail=$3 + + if test $retval -eq 0 ; then + pass=`expr $pass + 1` + else + fail=`expr $fail + 1` + fi + echo $pass $fail +} + +echo_case_result() +{ + retval=$1 + tst=$2 + subtst=${3:-''} + + if test $retval -eq 0 ; then + echo "PASS: $tst $subtst" >>$TEST_LOG + else + echo "FAIL: $tst $subtst" >>$TEST_LOG + fi +} + +run_direct_test_cases() +{ + pass=0 + fail=0 + for tst in $TESTS; do + ENVS= + if test -f $SRCDIR/${tst}.env ; then + ENVS="`cat $SRCDIR/${tst}.env`" + fi + if test x"$ENVS" = x ; then + $BUILDDIR/$tst $SRCDIR 2>>$TEST_LOG 1>>$TEST_LOG + retval=$? + read pass fail << EOF_COUNT + `count_case_result $retval $pass $fail` +EOF_COUNT + echo_case_result $retval $tst + CACHE_FILES=`ls *.cache` + if [ x"$CACHE_FILES" != x ] ; then + echo "# Clean $CACHE_FILES" >>$TEST_LOG + rm $CACHE_FILES + fi + else + i=1 + # Deleted for var in "$ENVS" because IFS=$'\n' is not supported + # in POSIX sh + while read e ; do + first=`echo "$e" | grep '^#'` + if test x"$first" = x"#" ; then + continue + fi + echo "# Starting $e $BUILDDIR/$tst $SRCDIR" >>$TEST_LOG + env $e $BUILDDIR/$tst $SRCDIR 2>>$TEST_LOG 1>>$TEST_LOG + retval=$? + echo "# Finished $e $BUILDDIR/$tst $SRCDIR with $retval" >>$TEST_LOG + read pass fail << EOF_COUNT + `count_case_result $retval $pass $fail` +EOF_COUNT + echo_case_result $retval $tst $e + CACHE_FILES=`ls *.cache` + if [ x"$CACHE_FILES" != x ] ; then + echo "# Clean $CACHE_FILES" >>$TEST_LOG + rm $CACHE_FILES + fi + i=`expr $i + 1` + done << EOF_ENVS + `echo "$ENVS"` +EOF_ENVS + fi + done + echo $pass $fail +} + +run_gnome_desktop_testing_runner() +{ + pass=0 + fail=0 + if [ x"$TESTS" = x ] ; then + TESTS='ibus' + fi + for tst in $TESTS; do + tst_dir="@INSTALLEDDIR@/$tst" + if [ ! -d "$tst_dir" ] ; then + print_log -e "${RED}FAIL${NC}: Not found %tst_dir" + fail=1 + continue + fi + gnome-desktop-testing-runner --timeout=$TIMEOUT $tst \ + 2>>$TEST_LOG 1>>$TEST_LOG + retval=$? + read pass fail << EOF + `count_case_result $retval $pass $fail` +EOF + done + child_pass=`grep '^PASS:' $TEST_LOG | wc -l` + child_fail=`grep '^FAIL:' $TEST_LOG | wc -l` + if [ $child_pass -ne 0 ] || [ $child_fail -ne 0 ] ; then + pass=$child_pass + if [ $child_fail -ne 0 ] ; then + fail=`expr $child_fail / 2` + else + fail=0 + fi + fi + echo $pass $fail +} + +run_test_suite() +{ + pass=0 + fail=0 + export GTK_IM_MODULE=ibus + export IBUS_COMPOSE_CACHE_DIR=$PWD + if [ x"$TESTING_RUNNER" = x ] ; then + TESTING_RUNNER="default" + fi + case $TESTING_RUNNER in + default) + # Get only the last value with do-while. + read pass fail << EOF_RUNNER + `run_direct_test_cases` +EOF_RUNNER + ;; + gnome) + read pass fail << EOF_RUNNER + `run_gnome_desktop_testing_runner` +EOF_RUNNER + ;; + esac + echo "" + print_log -e "${GREEN}PASS${NC}: $pass" + print_log -e "${RED}FAIL${NC}: $fail" + echo "" + if [ $TEST_LOG_STDOUT -eq 1 ] ; then + cat $TEST_LOG + else + echo "# See $TEST_LOG" + fi +} + +finit() +{ + echo "# Killing left gnome-session and Xorg" + kill $PID_GNOME_SESSION $PID_XORG + ibus exit + SUSER=`echo "$USER" | cut -c 1-7` + LEFT_CALENDAR=`ps -ef | grep gnome-shell-calendar-server | grep $SUSER | grep -v grep` + if [ x"$LEFT_CALENDAR" != x ] ; then + echo "# Killing left gnome-shell-calendar-server" + echo "$LEFT_CALENDAR" + echo "$LEFT_CALENDAR" | awk '{print $2}' | xargs kill + fi + + echo "# Finished $PROGNAME testing" +} + +main() +{ + parse_args "$@" + init_desktop + run_dbus_daemon 2>>$TEST_LOG 1>>$TEST_LOG + run_desktop 2>>$TEST_LOG 1>>$TEST_LOG + run_test_suite + finit +} + +# Need to enclose $@ with double quotes not to split the array. +main "$@" diff --git a/src/tests/ibus-engine-switch.c b/src/tests/ibus-engine-switch.c index 5c2bd51..a1eeba2 100644 --- a/src/tests/ibus-engine-switch.c +++ b/src/tests/ibus-engine-switch.c @@ -13,17 +13,25 @@ static const gchar *engine_names[] = { AFTER_ENGINE }; +static const gchar *engine_names2[] = { + AFTER_ENGINE, + BEFORE_ENGINE +}; + static void -change_global_engine (void) +change_global_engine (gboolean reverse) { gint i; for (i = 0; i < G_N_ELEMENTS (engine_names); i++) { - ibus_bus_set_global_engine (bus, engine_names[i]); + const gchar *engine_name = engine_names[i]; + if (reverse) + engine_name = engine_names2[i]; + ibus_bus_set_global_engine (bus, engine_name); IBusEngineDesc *engine_desc = ibus_bus_get_global_engine (bus); g_assert_cmpstr (ibus_engine_desc_get_name (engine_desc), ==, - engine_names[i]); + engine_name); g_object_unref (G_OBJECT (engine_desc)); } } @@ -46,6 +54,7 @@ typedef struct { gint count; guint timeout_id; guint idle_id; + gboolean reverse; } GlobalEngineChangedData; static void @@ -70,7 +79,7 @@ static gboolean change_global_engine_cb (gpointer user_data) { GlobalEngineChangedData *data = (GlobalEngineChangedData *) user_data; - change_global_engine (); + change_global_engine (data->reverse); data->idle_id = 0; return FALSE; } @@ -78,12 +87,25 @@ change_global_engine_cb (gpointer user_data) static void test_global_engine (void) { + GLogLevelFlags flags; + IBusEngineDesc *desc; GlobalEngineChangedData data; guint handler_id; if (!ibus_bus_get_use_global_engine (bus)) return; + /* "No global engine." warning is not critical message. */ + flags = g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); + desc = ibus_bus_get_global_engine (bus); + g_log_set_always_fatal (flags); + if (desc && + !g_strcmp0 (BEFORE_ENGINE, ibus_engine_desc_get_name (desc))) { + data.reverse = TRUE; + } else { + data.reverse = FALSE; + } + data.count = 0; handler_id = g_signal_connect (bus, @@ -141,7 +163,7 @@ test_context_engine_set_by_global (void) /* ibus_bus_set_global_engine() changes focused context engine. */ ibus_input_context_focus_in (context); - change_global_engine (); + change_global_engine (FALSE); /* ibus_input_context_set_engine() does not take effect when global engine is used. */ @@ -170,7 +192,7 @@ test_context_engine_set_by_focus (void) ibus_input_context_focus_in (context); - change_global_engine (); + change_global_engine (FALSE); /* When focus is lost, context engine is set to "dummy". */ ibus_input_context_focus_in (another_context); diff --git a/src/tests/ibus-inputcontext.c b/src/tests/ibus-inputcontext.c index fab183a..ed04bd6 100644 --- a/src/tests/ibus-inputcontext.c +++ b/src/tests/ibus-inputcontext.c @@ -37,18 +37,6 @@ fatal_handler(const gchar *log_domain, return TRUE; } -static gchar * -get_last_engine_id (const GList *engines) -{ - const char *result = NULL; - for (; engines; engines = g_list_next (engines)) { - IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data); - g_assert (engine_desc); - result = ibus_engine_desc_get_name (engine_desc); - } - return g_strdup (result); -} - static void call_basic_ipcs (IBusInputContext *context) { @@ -68,18 +56,23 @@ call_basic_ipcs (IBusInputContext *context) static void test_input_context (void) { - GList *engines; - gchar *active_engine_name = NULL; IBusInputContext *context; + GLogLevelFlags flags; IBusEngineDesc *engine_desc; + gchar *active_engine_name = NULL; gchar *current_ic; context = ibus_bus_create_input_context (bus, "test"); call_basic_ipcs (context); - engines = ibus_bus_list_active_engines (bus); - if (engines != NULL) { - active_engine_name = get_last_engine_id (engines); + /* "No global engine." warning is not critical message. */ + flags = g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); + engine_desc = ibus_bus_get_global_engine (bus); + g_log_set_always_fatal (flags); + if (engine_desc != NULL) { + active_engine_name = g_strdup (ibus_engine_desc_get_name(engine_desc)); + g_object_unref (engine_desc); + engine_desc = NULL; } else { active_engine_name = g_strdup ("dummy"); } @@ -111,8 +104,6 @@ test_input_context (void) g_object_unref (context); g_free (active_engine_name); - g_list_foreach (engines, (GFunc) g_object_unref, NULL); - g_list_free (engines); } static void diff --git a/src/tests/ibus-keypress.c b/src/tests/ibus-keypress.c index 1792022..dd1b004 100644 --- a/src/tests/ibus-keypress.c +++ b/src/tests/ibus-keypress.c @@ -288,6 +288,10 @@ int main (int argc, char *argv[]) { ibus_init (); + /* Avoid a warning of "AT-SPI: Could not obtain desktop path or name" + * with gtk_main(). + */ + g_setenv ("NO_AT_BRIDGE", "1", TRUE); g_test_init (&argc, &argv, NULL); gtk_init (&argc, &argv); diff --git a/src/tests/meta.test.in b/src/tests/meta.test.in new file mode 100644 index 0000000..ae2b299 --- /dev/null +++ b/src/tests/meta.test.in @@ -0,0 +1,4 @@ +[Test] +Type=session +Exec=@TEST_EXEC@ --tap +Output=TAP diff --git a/src/tests/runtest b/src/tests/runtest index ab39e9f..45a12d9 100755 --- a/src/tests/runtest +++ b/src/tests/runtest @@ -179,12 +179,14 @@ run_test_case() fi # Wait until all necessary components are up. - sleep 1 + sleep 3 export GTK_IM_MODULE=ibus fi - "../$tst" ${1+"$@"} + export IBUS_COMPOSE_CACHE_DIR=$PWD + + "../$tst" ../$top_srcdir/src/tests ${1+"$@"} retval=`expr $retval \| $?` @@ -198,7 +200,7 @@ if test -f $envfile ; then ENVS="`cat $envfile`" fi; if test x"$ENVS" = x ; then - run_test_case + run_test_case $@ else LANG_backup=$LANG i=1 @@ -210,7 +212,7 @@ else export $e echo "Run `func_basename $tst` on $e" echo "=======================" - run_test_case + run_test_case $@ echo "" i=`expr $i + 1` done