summaryrefslogtreecommitdiff
path: root/src/tests/runtest
blob: 81dc62d1a8c80b4cb65b62c54faf549823e46015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh

# Run a test case given by the first argument in a separate directory.
# This script may also launch $top_builddir/bus/ibus-daemon for testing.

# Executing a test that uses this file
# ====================================
#
# Running a single test:
#
#   $ make check TESTS=ibus-foo
#
#   or
#
#   $ top_builddir=<...> top_srcdir=<...> builddir=<...> ./runtest ibus-foo

: ${top_builddir:=../..}
: ${top_srcdir:=../..}
: ${builddir:=.}

BUS_REQUIRED_TESTS="
ibus-bus
ibus-config
ibus-configservice
ibus-factory
ibus-inputcontext
ibus-inputcontext-create
ibus-engine-switch
ibus-compose
test-stress
"

# Portable replacement of basename.
func_basename () {
  case "$1" in
    */*)
      expr "$1" : '.*/\(.*\)'
      ;;
    *)
      echo "$1"
  esac
}

# Portable replacement of dirname.
func_dirname () {
  case "$1" in
    */*)
      expr "$1" : '\(.*\)/.*'
      ;;
    *)
      echo .
  esac
}

# Kill ibus-daemon process and remove temporary files.
func_cleanup () {
  tstdir=$1
  if test -f $tstdir/ibus-daemon.pid; then
    . $tstdir/ibus-daemon.pid
    kill $IBUS_DAEMON_PID &> /dev/null
  fi
  rm -fr $tstdir
}

# Prepare component files necessary for testing, under components/.
func_copy_component () {
  file=$1
  base=`func_basename $file`
  if test -f $file.in; then
    mkdir -p components
    sed 's|@libexecdir@|'`func_dirname $file`'|g' < $file.in > components/$base
  fi
}

trap 'func_cleanup $tstdir' 1 2 3 15

tst=$1; shift
tstdir=tmp-`func_basename $tst`

test -d $tstdir || mkdir $tstdir

( cd $tstdir

  need_bus=no
  for t in $BUS_REQUIRED_TESTS; do
    if test $t = `func_basename $tst`; then
      need_bus=yes
    fi
  done

  if test $need_bus = yes; then
    func_copy_component "../$top_srcdir/engine/simple.xml"
    func_copy_component "../$top_srcdir/conf/memconf/memconf.xml"

    IBUS_COMPONENT_PATH=$PWD/components
    export IBUS_COMPONENT_PATH

    IBUS_ADDRESS_FILE=$PWD/ibus-daemon.pid
    export IBUS_ADDRESS_FILE

    # Start ibus-daemon.
    ../$top_builddir/bus/ibus-daemon \
    --daemonize \
    --cache=none \
    --panel=disable \
    --config=default \
    --verbose;

    # Wait until all necessary components are up.
    sleep 1
  fi

  exec "../$tst" ${1+"$@"} )

retval=$?

func_cleanup $tstdir

exit $retval