1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4
 *
5
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the
19
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 * Boston, MA 02110-1301, USA.
21
 */
22

            
23
/*
24
 * Testing AT-SPI requires both a test application and AT client.
25
 * Test applications are built using the Dummy ATK implementation: MyAtk.
26
 * This file contains the entry point for all test applications.
27
 * The test will provide its own implementation of atk_get_root,
28
 * and as such provide all the application state for the test.
29
 */
30

            
31
#include "atk-object-xml-loader.h"
32
#include "my-atk.h"
33
#include <atk-bridge.h>
34
#include <atk/atk.h>
35
#include <glib-unix.h>
36
#include <glib.h>
37
#include <locale.h>
38
#include <signal.h>
39
#include <stdio.h>
40
#include <stdlib.h>
41
#include <string.h>
42
#include <unistd.h>
43

            
44
static AtkObject *root_accessible;
45

            
46
static GMainLoop *mainloop;
47

            
48
static gchar *tdata_path = NULL;
49

            
50
void
51
161
test_init (gchar *path)
52
{
53
  gchar *td;
54

            
55
161
  if (path == NULL)
56
    {
57
      g_print ("No test data file provided\n");
58
      exit (EXIT_FAILURE);
59
    }
60
161
  tdata_path = path;
61

            
62
161
  td = g_build_path (G_DIR_SEPARATOR_S, tdata_path, NULL, NULL);
63
161
  root_accessible = ATK_OBJECT (atk_object_xml_parse (td));
64
161
  g_free (td);
65
161
}
66

            
67
AtkObject *
68
322
test_get_root (void)
69
{
70
322
  return root_accessible;
71
}
72

            
73
static AtkObject *
74
322
get_root (void)
75
{
76
322
  return test_get_root ();
77
}
78

            
79
const gchar *
80
132
get_toolkit_name (void)
81
{
82
132
  return strdup ("atspitesting-toolkit");
83
}
84

            
85
static void
86
161
setup_atk_util (void)
87
{
88
  AtkUtilClass *klass;
89

            
90
161
  klass = g_type_class_ref (ATK_TYPE_UTIL);
91
161
  klass->get_root = get_root;
92
161
  klass->get_toolkit_name = get_toolkit_name;
93
161
  g_type_class_unref (klass);
94
161
}
95

            
96
static GOptionEntry optentries[] = {
97
  { "test-data-file", 0, 0, G_OPTION_ARG_STRING, &tdata_path, "Path to file of test data", NULL },
98
  { NULL }
99
};
100

            
101
static gboolean
102
161
sigterm_received_cb (gpointer user_data)
103
{
104
161
  GMainLoop *mainloop = user_data;
105
161
  g_print ("test application received SIGTERM\n");
106
161
  g_main_loop_quit (mainloop);
107
161
  return G_SOURCE_REMOVE;
108
}
109

            
110
int
111
161
main (int argc, char *argv[])
112
{
113
  GOptionContext *opt;
114
161
  GError *err = NULL;
115
161
  opt = g_option_context_new (NULL);
116
161
  g_option_context_add_main_entries (opt, optentries, NULL);
117
161
  g_option_context_set_ignore_unknown_options (opt, TRUE);
118

            
119
161
  if (!g_option_context_parse (opt, &argc, &argv, &err))
120
    g_error ("Option parsing failed: %s\n", err->message);
121

            
122
161
  setlocale (LC_ALL, "");
123
161
  setup_atk_util ();
124
161
  test_init (tdata_path);
125

            
126
161
  atk_bridge_adaptor_init (&argc, &argv);
127

            
128
161
  mainloop = g_main_loop_new (NULL, FALSE);
129
161
  g_unix_signal_add (SIGTERM, sigterm_received_cb, mainloop);
130
161
  g_main_loop_run (mainloop);
131

            
132
161
  g_print ("test application exited main loop; terminating after cleanup\n");
133

            
134
161
  atk_bridge_adaptor_cleanup ();
135

            
136
161
  g_print ("test application %d exiting!\n", getpid ());
137
161
  return 0;
138
}