1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
3 * Copyright 2013 Igalia S.L.
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.
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.
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.
23 #define EXPECTED_NUMBER 5
25 GMainLoop
*global_loop
= NULL
;
26 gint global_number_emissions
= 0;
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))
35 typedef struct _TestDocument TestDocument
;
36 typedef struct _TestDocumentClass TestDocumentClass
;
43 struct _TestDocumentClass
45 AtkObjectClass parent_class
;
48 GType
test_document_get_type (void) G_GNUC_CONST
;
49 static void test_document_interface_init (AtkDocumentIface
*iface
);
51 G_DEFINE_TYPE_WITH_CODE (TestDocument
,
54 G_IMPLEMENT_INTERFACE (ATK_TYPE_DOCUMENT
,
55 test_document_interface_init
));
58 test_document_class_init (TestDocumentClass
*klass
)
63 test_document_init (TestDocument
*document
)
68 test_document_interface_init (AtkDocumentIface
*iface
)
73 document_page_changed_cb (AtkDocument
*document
,
77 g_print ("Page-changed callback, page_number = %i\n", page_number
);
78 global_number_emissions
++;
82 document_emit_page_changed (gpointer data
)
84 TestDocument
* test_document
= TEST_DOCUMENT (data
);
85 static gint next_page
= 1;
87 g_print ("Moving to next page. Emitting page-change, page_number = %i\n",
89 g_signal_emit_by_name (test_document
, "page-changed", next_page
++, NULL
);
91 if (next_page
> EXPECTED_NUMBER
) {
92 g_main_loop_quit (global_loop
);
93 return G_SOURCE_REMOVE
;
95 return G_SOURCE_CONTINUE
;
99 init_test_document (void)
101 GObject
*my_document
;
103 my_document
= g_object_new (TEST_TYPE_DOCUMENT
, NULL
);
105 g_signal_connect (my_document
, "page-changed",
106 G_CALLBACK (document_page_changed_cb
),
109 g_idle_add (document_emit_page_changed
, my_document
);
119 global_loop
= g_main_loop_new (NULL
, FALSE
);
121 g_print("Starting Document test suite\n");
123 init_test_document ();
124 g_main_loop_run (global_loop
);
126 if (global_number_emissions
== EXPECTED_NUMBER
)
127 g_print ("Document tests succeeded\n");
129 g_print ("Document tests failed\n");