win32/vsX: Fix 'make dist'
[platform/upstream/atk.git] / tests / testdocument.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  * Copyright 2013 Igalia S.L.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <atk/atk.h>
22
23 #define EXPECTED_NUMBER 5
24
25 GMainLoop *global_loop = NULL;
26 gint global_number_emissions = 0;
27
28 #define TEST_TYPE_DOCUMENT                         (test_document_get_type ())
29 #define TEST_DOCUMENT(obj)                         (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DOCUMENT, TestDocument))
30 #define TEST_DOCUMENT_CLASS(klass)                 (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_DOCUMENT, TestDocumentClass))
31 #define TEST_IS_DOCUMENT(obj)                      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_DOCUMENT))
32 #define TEST_IS_DOCUMENT_CLASS(klass)              (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_DOCUMENT))
33 #define TEST_DOCUMENT_GET_CLASS(obj)               (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_DOCUMENT, TestDocumentClass))
34
35 typedef struct _TestDocument        TestDocument;
36 typedef struct _TestDocumentClass   TestDocumentClass;
37
38 struct _TestDocument
39 {
40   AtkObject parent;
41 };
42
43 struct _TestDocumentClass
44 {
45   AtkObjectClass parent_class;
46 };
47
48 GType       test_document_get_type (void) G_GNUC_CONST;
49 static void test_document_interface_init (AtkDocumentIface *iface);
50
51 G_DEFINE_TYPE_WITH_CODE (TestDocument,
52                          test_document,
53                          ATK_TYPE_OBJECT,
54                          G_IMPLEMENT_INTERFACE (ATK_TYPE_DOCUMENT,
55                                                 test_document_interface_init));
56
57 static void
58 test_document_class_init (TestDocumentClass *klass)
59 {
60 }
61
62 static void
63 test_document_init (TestDocument *document)
64 {
65 }
66
67 static void
68 test_document_interface_init (AtkDocumentIface *iface)
69 {
70 }
71
72 static void
73 document_page_changed_cb (AtkDocument *document,
74                           gint page_number,
75                           gpointer data)
76 {
77   g_print ("Page-changed callback, page_number = %i\n", page_number);
78   global_number_emissions++;
79 }
80
81 static gboolean
82 document_emit_page_changed (gpointer data)
83 {
84   TestDocument* test_document = TEST_DOCUMENT (data);
85   static gint next_page = 1;
86
87   g_print ("Moving to next page. Emitting page-change, page_number = %i\n",
88            next_page);
89   g_signal_emit_by_name (test_document, "page-changed", next_page++, NULL);
90
91   if (next_page > EXPECTED_NUMBER) {
92     g_main_loop_quit (global_loop);
93     return G_SOURCE_REMOVE;
94   } else
95     return G_SOURCE_CONTINUE;
96 }
97
98 static gboolean
99 init_test_document (void)
100 {
101   GObject *my_document;
102
103   my_document = g_object_new (TEST_TYPE_DOCUMENT, NULL);
104
105   g_signal_connect (my_document, "page-changed",
106                     G_CALLBACK (document_page_changed_cb),
107                     NULL);
108
109   g_idle_add (document_emit_page_changed, my_document);
110
111   return TRUE;
112 }
113
114
115 int
116 main (gint  argc,
117       char* argv[])
118 {
119   global_loop = g_main_loop_new (NULL, FALSE);
120
121   g_print("Starting Document test suite\n");
122
123   init_test_document ();
124   g_main_loop_run (global_loop);
125
126   if (global_number_emissions == EXPECTED_NUMBER)
127     g_print ("Document tests succeeded\n");
128   else
129     g_print ("Document tests failed\n");
130
131   return 0;
132 }