summaryrefslogtreecommitdiff
path: root/tests/atk_test_util.c
blob: c776ae1ed5bd68ceb2e3d206d966e357c956f694 (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
/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <signal.h>
#include "atk_test_util.h"

static void assert_clean_exit (int sig)
{
  kill (child_pid, SIGTERM);
}

void clean_exit_on_fail ()
{
  signal (SIGABRT, assert_clean_exit);
}

void
run_app (const char *file_name)
{
  child_pid = fork ();
  if (child_pid == 0) {
    execlp ("./app-test",
            "./app-test",
            "--test-data-file",
            file_name,
            NULL);
    _exit (EXIT_SUCCESS);
  }
}

AtspiAccessible * get_root_obj (const char *file_name)
{
  int i;
  AtspiAccessible *obj = NULL;

  run_app (file_name);

  /* sleep is needed to wait for fored test application*/
  sleep (1);

  obj = atspi_get_desktop (0);
  gint child_count = atspi_accessible_get_child_count (obj, NULL);
  if (child_count < 1) {
    g_test_message ("Fail, test application not found\n");
    g_test_fail ();
    kill (child_pid, SIGTERM);
    return NULL;
  }

  for (i=0; i<child_count; i++) {
    AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,i, NULL);
    if (!strcmp (atspi_accessible_get_name (child, NULL), "root_object"))
      return child;
  }
  g_test_message ("test object not found\n");
  g_test_fail ();

  kill (child_pid, SIGTERM);
  return NULL;
}