1 | #include <string.h> |
---|
2 | #include "testtextlib.h" |
---|
3 | |
---|
4 | #define NUM_ROWS_TO_LOOP 30 |
---|
5 | |
---|
6 | typedef struct |
---|
7 | { |
---|
8 | GtkWidget *tb_others; |
---|
9 | GtkWidget *tb_ref_selection; |
---|
10 | GtkWidget *tb_ref_at; |
---|
11 | GtkWidget *tb_ref_accessible_child; |
---|
12 | GtkWidget *child_entry; |
---|
13 | GtkWidget *row_entry; |
---|
14 | GtkWidget *col_entry; |
---|
15 | GtkWidget *index_entry; |
---|
16 | }TestChoice; |
---|
17 | |
---|
18 | static void _check_table (AtkObject *in_obj); |
---|
19 | void table_runtest(AtkObject *); |
---|
20 | static void other_runtest(AtkObject *obj); |
---|
21 | static void ref_at_runtest(AtkObject *obj, gint row, gint col); |
---|
22 | static void ref_accessible_child_runtest(AtkObject *obj, gint childno); |
---|
23 | static void ref_selection_runtest (AtkObject *obj, gint index); |
---|
24 | static void _selection_tests(AtkObject *obj); |
---|
25 | static void _display_header_info(gchar *type, |
---|
26 | AtkObject *header_obj, gint header_num); |
---|
27 | static void _process_child(AtkObject *child_obj); |
---|
28 | |
---|
29 | static void _notify_table_row_inserted (GObject *obj, |
---|
30 | gint start_offset, gint length); |
---|
31 | static void _notify_table_column_inserted (GObject *obj, |
---|
32 | gint start_offset, gint length); |
---|
33 | static void _notify_table_row_deleted (GObject *obj, |
---|
34 | gint start_offset, gint length); |
---|
35 | static void _notify_table_column_deleted (GObject *obj, |
---|
36 | gint start_offset, gint length); |
---|
37 | static void _notify_table_row_reordered (GObject *obj); |
---|
38 | static void _notify_table_column_reordered (GObject *obj); |
---|
39 | static void _notify_table_child_added (GObject *obj, |
---|
40 | gint index, AtkObject *child); |
---|
41 | static void _notify_table_child_removed (GObject *obj, |
---|
42 | gint index, AtkObject *child); |
---|
43 | static void _property_signal_connect (AtkObject *obj); |
---|
44 | static void _property_change_handler (AtkObject *obj, |
---|
45 | AtkPropertyValues *values); |
---|
46 | |
---|
47 | static gboolean tested_set_headers = FALSE; |
---|
48 | static void test_choice_gui (AtkObject **obj); |
---|
49 | static void nogui_runtest (AtkObject *obj); |
---|
50 | static void nogui_ref_at_runtest (AtkObject *obj); |
---|
51 | static void nogui_process_child (AtkObject *obj); |
---|
52 | |
---|
53 | static TestChoice *tc; |
---|
54 | static gint g_visibleGUI = 0; |
---|
55 | static AtkTable *g_table = NULL; |
---|
56 | static AtkObject *current_obj = NULL; |
---|
57 | gboolean g_done = FALSE; |
---|
58 | gboolean g_properties = TRUE; |
---|
59 | |
---|
60 | /* |
---|
61 | * destroy |
---|
62 | * |
---|
63 | * Destroy Callback |
---|
64 | * |
---|
65 | */ |
---|
66 | static void destroy (GtkWidget *widget, gpointer data) |
---|
67 | { |
---|
68 | gtk_main_quit(); |
---|
69 | } |
---|
70 | |
---|
71 | static void choicecb (GtkWidget *widget, gpointer data) |
---|
72 | { |
---|
73 | AtkObject **ptr_to_obj = (AtkObject **)data; |
---|
74 | AtkObject *obj = *ptr_to_obj; |
---|
75 | |
---|
76 | if (GTK_TOGGLE_BUTTON(tc->tb_others)->active) |
---|
77 | { |
---|
78 | other_runtest(obj); |
---|
79 | } |
---|
80 | else if (GTK_TOGGLE_BUTTON(tc->tb_ref_selection)->active) |
---|
81 | { |
---|
82 | const gchar *indexstr; |
---|
83 | gint index; |
---|
84 | |
---|
85 | indexstr = gtk_entry_get_text(GTK_ENTRY(tc->index_entry)); |
---|
86 | index = string_to_int((gchar *)indexstr); |
---|
87 | |
---|
88 | ref_selection_runtest(obj, index); |
---|
89 | } |
---|
90 | else if (GTK_TOGGLE_BUTTON(tc->tb_ref_at)->active) |
---|
91 | { |
---|
92 | const gchar *rowstr, *colstr; |
---|
93 | gint row, col; |
---|
94 | |
---|
95 | rowstr = gtk_entry_get_text(GTK_ENTRY(tc->row_entry)); |
---|
96 | colstr = gtk_entry_get_text(GTK_ENTRY(tc->col_entry)); |
---|
97 | row = string_to_int((gchar *)rowstr); |
---|
98 | col = string_to_int((gchar *)colstr); |
---|
99 | |
---|
100 | ref_at_runtest(obj, row, col); |
---|
101 | } |
---|
102 | else if (GTK_TOGGLE_BUTTON(tc->tb_ref_accessible_child)->active) |
---|
103 | { |
---|
104 | const gchar *childstr; |
---|
105 | gint childno; |
---|
106 | childstr = gtk_entry_get_text(GTK_ENTRY(tc->child_entry)); |
---|
107 | childno = string_to_int((gchar *)childstr); |
---|
108 | |
---|
109 | ref_accessible_child_runtest(obj, childno); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | static void _check_table (AtkObject *in_obj) |
---|
114 | { |
---|
115 | AtkObject *obj = NULL; |
---|
116 | G_CONST_RETURN char *no_properties; |
---|
117 | G_CONST_RETURN char *no_gui; |
---|
118 | |
---|
119 | no_properties = g_getenv ("TEST_ACCESSIBLE_NO_PROPERTIES"); |
---|
120 | no_gui = g_getenv ("TEST_ACCESSIBLE_NO_GUI"); |
---|
121 | |
---|
122 | if (no_properties != NULL) |
---|
123 | g_properties = FALSE; |
---|
124 | if (no_gui != NULL) |
---|
125 | g_visibleGUI = 1; |
---|
126 | |
---|
127 | obj = find_object_by_type(in_obj, "GailTreeView"); |
---|
128 | if (obj != NULL) |
---|
129 | g_print("Found GailTreeView table in child!\n"); |
---|
130 | else |
---|
131 | { |
---|
132 | obj = find_object_by_type(in_obj, "GailCList"); |
---|
133 | if (obj != NULL) |
---|
134 | g_print("Found GailCList in child!\n"); |
---|
135 | else |
---|
136 | { |
---|
137 | g_print("No object found %s\n", g_type_name (G_OBJECT_TYPE (in_obj))); |
---|
138 | return; |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | g_print ("In _check_table\n"); |
---|
143 | |
---|
144 | if (!already_accessed_atk_object(obj)) |
---|
145 | { |
---|
146 | /* Set up signal handlers */ |
---|
147 | |
---|
148 | g_print ("Adding signal handler\n"); |
---|
149 | g_signal_connect_closure_by_id (obj, |
---|
150 | g_signal_lookup ("column_inserted", G_OBJECT_TYPE (obj)), |
---|
151 | 0, |
---|
152 | g_cclosure_new (G_CALLBACK (_notify_table_column_inserted), |
---|
153 | NULL, NULL), |
---|
154 | FALSE); |
---|
155 | g_signal_connect_closure_by_id (obj, |
---|
156 | g_signal_lookup ("row_inserted", G_OBJECT_TYPE (obj)), |
---|
157 | 0, |
---|
158 | g_cclosure_new (G_CALLBACK (_notify_table_row_inserted), |
---|
159 | NULL, NULL), |
---|
160 | FALSE); |
---|
161 | g_signal_connect_closure_by_id (obj, |
---|
162 | g_signal_lookup ("column_deleted", G_OBJECT_TYPE (obj)), |
---|
163 | 0, |
---|
164 | g_cclosure_new (G_CALLBACK (_notify_table_column_deleted), |
---|
165 | NULL, NULL), |
---|
166 | FALSE); |
---|
167 | g_signal_connect_closure_by_id (obj, |
---|
168 | g_signal_lookup ("row_deleted", G_OBJECT_TYPE (obj)), |
---|
169 | 0, |
---|
170 | g_cclosure_new (G_CALLBACK (_notify_table_row_deleted), |
---|
171 | NULL, NULL), |
---|
172 | FALSE); |
---|
173 | g_signal_connect_closure_by_id (obj, |
---|
174 | g_signal_lookup ("column_reordered", G_OBJECT_TYPE (obj)), |
---|
175 | 0, |
---|
176 | g_cclosure_new (G_CALLBACK (_notify_table_column_reordered), |
---|
177 | NULL, NULL), |
---|
178 | FALSE); |
---|
179 | g_signal_connect_closure_by_id (obj, |
---|
180 | g_signal_lookup ("row_reordered", G_OBJECT_TYPE (obj)), |
---|
181 | 0, |
---|
182 | g_cclosure_new (G_CALLBACK (_notify_table_row_reordered), |
---|
183 | NULL, NULL), |
---|
184 | FALSE); |
---|
185 | g_signal_connect_closure (obj, "children_changed::add", |
---|
186 | g_cclosure_new (G_CALLBACK (_notify_table_child_added), |
---|
187 | NULL, NULL), |
---|
188 | FALSE); |
---|
189 | |
---|
190 | g_signal_connect_closure (obj, "children_changed::remove", |
---|
191 | g_cclosure_new (G_CALLBACK (_notify_table_child_removed), |
---|
192 | NULL, NULL), |
---|
193 | FALSE); |
---|
194 | |
---|
195 | } |
---|
196 | g_table = ATK_TABLE(obj); |
---|
197 | |
---|
198 | atk_object_connect_property_change_handler (obj, |
---|
199 | (AtkPropertyChangeHandler*) _property_change_handler); |
---|
200 | |
---|
201 | current_obj = obj; |
---|
202 | /* |
---|
203 | * The use of ¤t_obj allows us to change the object being processed |
---|
204 | * in the GUI. |
---|
205 | */ |
---|
206 | if (g_visibleGUI != 1) |
---|
207 | test_choice_gui(¤t_obj); |
---|
208 | else if (no_gui != NULL) |
---|
209 | nogui_runtest(obj); |
---|
210 | } |
---|
211 | |
---|
212 | static |
---|
213 | void other_runtest(AtkObject *obj) |
---|
214 | { |
---|
215 | AtkObject *header_obj; |
---|
216 | AtkObject *out_obj; |
---|
217 | G_CONST_RETURN gchar *out_string; |
---|
218 | GString *out_desc; |
---|
219 | gint n_cols, n_rows; |
---|
220 | gint rows_to_loop = NUM_ROWS_TO_LOOP; |
---|
221 | gint i, j; |
---|
222 | out_desc = g_string_sized_new(256); |
---|
223 | |
---|
224 | n_cols = atk_table_get_n_columns(ATK_TABLE(obj)); |
---|
225 | n_rows = atk_table_get_n_rows(ATK_TABLE(obj)); |
---|
226 | |
---|
227 | g_print ("Number of columns is %d\n", n_cols); |
---|
228 | g_print ("Number of rows is %d\n", n_rows); |
---|
229 | |
---|
230 | /* Loop NUM_ROWS_TO_LOOP rows if possible */ |
---|
231 | if (n_rows < NUM_ROWS_TO_LOOP) |
---|
232 | rows_to_loop = n_rows; |
---|
233 | |
---|
234 | g_print ("\n"); |
---|
235 | |
---|
236 | /* Caption */ |
---|
237 | |
---|
238 | out_obj = atk_table_get_caption(ATK_TABLE(obj)); |
---|
239 | if (out_obj != NULL) |
---|
240 | { |
---|
241 | out_string = atk_object_get_name (out_obj); |
---|
242 | if (out_string) |
---|
243 | g_print("Caption Name is <%s>\n", out_string); |
---|
244 | else |
---|
245 | g_print("Caption has no name\n"); |
---|
246 | } |
---|
247 | else |
---|
248 | g_print("No caption\n"); |
---|
249 | |
---|
250 | /* Column descriptions and headers */ |
---|
251 | |
---|
252 | g_print ("\n"); |
---|
253 | for (i=0; i < n_cols; i++) |
---|
254 | { |
---|
255 | /* check default */ |
---|
256 | out_string = atk_table_get_column_description(ATK_TABLE(obj), i); |
---|
257 | if (out_string != NULL) |
---|
258 | g_print("%d: Column description is <%s>\n", i, out_string); |
---|
259 | else |
---|
260 | g_print("%d: Column description is <NULL>\n", i); |
---|
261 | |
---|
262 | /* check setting a new value */ |
---|
263 | |
---|
264 | g_string_sprintf(out_desc, "new column description %d", i); |
---|
265 | |
---|
266 | if (out_string == NULL || strcmp (out_string, out_desc->str) != 0) |
---|
267 | { |
---|
268 | g_print("%d, Setting the column description to <%s>\n", |
---|
269 | i, out_desc->str); |
---|
270 | atk_table_set_column_description(ATK_TABLE(obj), i, out_desc->str); |
---|
271 | out_string = atk_table_get_column_description(ATK_TABLE(obj), i); |
---|
272 | if (out_string != NULL) |
---|
273 | g_print("%d: Column description is <%s>\n", i, out_string); |
---|
274 | else |
---|
275 | g_print("%d: Column description is <NULL>\n", i); |
---|
276 | } |
---|
277 | |
---|
278 | /* Column header */ |
---|
279 | header_obj = atk_table_get_column_header(ATK_TABLE(obj), i); |
---|
280 | _display_header_info("Column", header_obj, i); |
---|
281 | } |
---|
282 | |
---|
283 | /* Row description */ |
---|
284 | |
---|
285 | g_print ("\n"); |
---|
286 | |
---|
287 | for (i=0; i < rows_to_loop; i++) |
---|
288 | { |
---|
289 | out_string = atk_table_get_row_description(ATK_TABLE(obj), i); |
---|
290 | if (out_string != NULL) |
---|
291 | g_print("%d: Row description is <%s>\n", i, out_string); |
---|
292 | else |
---|
293 | g_print("%d: Row description is <NULL>\n", i); |
---|
294 | |
---|
295 | g_string_sprintf(out_desc, "new row description %d", i); |
---|
296 | |
---|
297 | if (out_string == NULL || strcmp (out_string, out_desc->str) != 0) |
---|
298 | { |
---|
299 | g_print("%d: Setting the row description to <%s>\n", |
---|
300 | i, out_desc->str); |
---|
301 | atk_table_set_row_description(ATK_TABLE(obj), i, out_desc->str); |
---|
302 | |
---|
303 | out_string = atk_table_get_row_description(ATK_TABLE(obj), i); |
---|
304 | if (out_string != NULL) |
---|
305 | g_print("%d: Row description is <%s>\n", i, out_string); |
---|
306 | else |
---|
307 | g_print("%d: Row description is <NULL>\n", i); |
---|
308 | } |
---|
309 | |
---|
310 | header_obj = atk_table_get_row_header(ATK_TABLE(obj), i); |
---|
311 | _display_header_info("Row", header_obj, i); |
---|
312 | |
---|
313 | for (j=0; j <n_cols; j++) |
---|
314 | { |
---|
315 | gint index = atk_table_get_index_at(ATK_TABLE(obj), i, j); |
---|
316 | gint row, column; |
---|
317 | |
---|
318 | column = atk_table_get_column_at_index (ATK_TABLE (obj), index); |
---|
319 | g_return_if_fail (column == j); |
---|
320 | |
---|
321 | row = atk_table_get_row_at_index (ATK_TABLE (obj), index); |
---|
322 | g_return_if_fail (row == i); |
---|
323 | |
---|
324 | if(atk_selection_is_child_selected(ATK_SELECTION(obj), index)) |
---|
325 | g_print("atk_selection_is_child_selected,index = %d returns TRUE\n", index); |
---|
326 | /* Generic cell tests */ |
---|
327 | /* Just test setting column headers once. */ |
---|
328 | |
---|
329 | if (!tested_set_headers) |
---|
330 | { |
---|
331 | tested_set_headers = TRUE; |
---|
332 | |
---|
333 | /* Hardcode to 1,1 for now */ |
---|
334 | g_print( |
---|
335 | "Testing set_column_header for column %d, to table\n", |
---|
336 | (n_cols - 1)); |
---|
337 | atk_table_set_column_header(ATK_TABLE(obj), (n_cols - 1), obj); |
---|
338 | |
---|
339 | g_print("Testing set_row_header for row %d, to table\n", n_rows); |
---|
340 | atk_table_set_row_header(ATK_TABLE(obj), n_rows, obj); |
---|
341 | } |
---|
342 | } |
---|
343 | } |
---|
344 | |
---|
345 | /* row/column extents */ |
---|
346 | |
---|
347 | g_print("\n"); |
---|
348 | g_print("Row extents at 1,1 is %d\n", |
---|
349 | atk_table_get_row_extent_at(ATK_TABLE(obj), 1, 1)); |
---|
350 | g_print("Column extents at 1,1 is %d\n", |
---|
351 | atk_table_get_column_extent_at(ATK_TABLE(obj), 1, 1)); |
---|
352 | } |
---|
353 | |
---|
354 | static |
---|
355 | void ref_accessible_child_runtest(AtkObject *obj, gint child) |
---|
356 | { |
---|
357 | AtkObject *child_obj; |
---|
358 | /* ref_child */ |
---|
359 | g_print ("Accessing child %d\n", child); |
---|
360 | child_obj = atk_object_ref_accessible_child (obj, child); |
---|
361 | _property_signal_connect(child_obj); |
---|
362 | if (child_obj != NULL) |
---|
363 | _process_child(child_obj); |
---|
364 | } |
---|
365 | |
---|
366 | static |
---|
367 | void ref_selection_runtest (AtkObject *obj, gint index) |
---|
368 | { |
---|
369 | AtkObject *child_obj; |
---|
370 | |
---|
371 | /* use atk_selection_ref_selection just once to check it works */ |
---|
372 | child_obj = atk_selection_ref_selection(ATK_SELECTION(obj), index); |
---|
373 | if (child_obj) |
---|
374 | { |
---|
375 | g_print("child_obj gotten from atk_selection_ref_selection\n"); |
---|
376 | g_object_unref (child_obj); |
---|
377 | } |
---|
378 | else |
---|
379 | g_print("NULL returned by atk_selection_ref_selection\n"); |
---|
380 | |
---|
381 | _selection_tests(obj); |
---|
382 | } |
---|
383 | |
---|
384 | static |
---|
385 | void ref_at_runtest(AtkObject *obj, gint row, gint col) |
---|
386 | { |
---|
387 | AtkObject *child_obj; |
---|
388 | /* ref_at */ |
---|
389 | |
---|
390 | g_print("Testing ref_at row %d column %d\n", row, col); |
---|
391 | |
---|
392 | child_obj = atk_table_ref_at(ATK_TABLE(obj), row, col); |
---|
393 | _property_signal_connect(child_obj); |
---|
394 | |
---|
395 | g_print("Row is %d, col is %d\n", row, col); |
---|
396 | |
---|
397 | _process_child(child_obj); |
---|
398 | if (child_obj) |
---|
399 | g_object_unref (child_obj); |
---|
400 | } |
---|
401 | |
---|
402 | /** |
---|
403 | * process_child |
---|
404 | **/ |
---|
405 | static void |
---|
406 | _process_child(AtkObject *child_obj) |
---|
407 | { |
---|
408 | if (child_obj != NULL) |
---|
409 | { |
---|
410 | if (ATK_IS_TEXT(child_obj)) |
---|
411 | { |
---|
412 | add_handlers(child_obj); |
---|
413 | setup_gui(child_obj, runtest); |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | g_print("Interface is not text!\n"); |
---|
418 | } |
---|
419 | /* |
---|
420 | if (ATK_IS_ACTION(child_obj)) |
---|
421 | { |
---|
422 | gint i, j; |
---|
423 | gchar *action_name; |
---|
424 | gchar *action_description; |
---|
425 | gchar *action_keybinding; |
---|
426 | AtkAction *action = ATK_ACTION(child_obj); |
---|
427 | |
---|
428 | i = atk_action_get_n_actions (action); |
---|
429 | g_print ("Supports AtkAction with %d actions.\n", i); |
---|
430 | for (j = 0; j < i; j++) |
---|
431 | { |
---|
432 | g_print ("Action %d:\n", j); |
---|
433 | action_name = atk_action_get_name (action, j); |
---|
434 | if (action_name) |
---|
435 | g_print (" Name = %s\n", action_name); |
---|
436 | action_description = atk_action_get_description (action, j); |
---|
437 | if (action_description) |
---|
438 | g_print (" Description = %s\n", action_description); |
---|
439 | action_keybinding = atk_action_get_keybinding (action, j); |
---|
440 | if (action_keybinding) |
---|
441 | g_print (" Keybinding = %s\n", action_keybinding); |
---|
442 | action_description = "new description"; |
---|
443 | g_print (" Setting description to %s\n", action_description); |
---|
444 | atk_action_set_description (action, j, action_description); |
---|
445 | action_description = atk_action_get_description (action, j); |
---|
446 | if (action_description) |
---|
447 | g_print (" New description is now %s\n", action_description); |
---|
448 | } |
---|
449 | } |
---|
450 | */ |
---|
451 | } |
---|
452 | else |
---|
453 | { |
---|
454 | g_print("Child is NULL!\n"); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | /** |
---|
459 | * Combined tests on AtkTable and AtkSelection on individual rows rather than |
---|
460 | * all of them |
---|
461 | **/ |
---|
462 | static void |
---|
463 | _selection_tests(AtkObject *obj) |
---|
464 | { |
---|
465 | gint n_rows = 0; |
---|
466 | gint n_cols = 0; |
---|
467 | gint selection_count = 0; |
---|
468 | gint i = 0; |
---|
469 | gint *selected = NULL; |
---|
470 | AtkTable *table; |
---|
471 | |
---|
472 | table = ATK_TABLE (obj); |
---|
473 | |
---|
474 | n_rows = atk_table_get_selected_rows(table, &selected); |
---|
475 | for (i = 0; i < n_rows; i++) |
---|
476 | { |
---|
477 | g_print("atk_table_get_selected_row returns : %d\n", |
---|
478 | selected[i]); |
---|
479 | if (!atk_table_is_row_selected (table, selected[i])) |
---|
480 | g_print("atk_table_is_row_selected returns false for selected row %d\n", |
---|
481 | selected[i]); |
---|
482 | } |
---|
483 | g_free (selected); |
---|
484 | |
---|
485 | selected = NULL; |
---|
486 | n_cols = atk_table_get_selected_columns(table, &selected); |
---|
487 | for (i = 0; i < n_cols; i++) |
---|
488 | g_print("atk_table_get_selected_columns returns : %d\n", selected[i]); |
---|
489 | g_free (selected); |
---|
490 | |
---|
491 | selection_count = atk_selection_get_selection_count(ATK_SELECTION(obj)); |
---|
492 | g_print("atk_selection_get_selection_count returns %d\n", selection_count); |
---|
493 | |
---|
494 | if (atk_table_is_row_selected(table, 2)) |
---|
495 | { |
---|
496 | g_print("atk_table_is_row_selected (table, 2) returns TRUE\n"); |
---|
497 | atk_selection_clear_selection (ATK_SELECTION (obj)); |
---|
498 | if (atk_table_add_row_selection(table, 4)) |
---|
499 | g_print("atk_table_add_row_selection: selected row 4\n"); |
---|
500 | if (!atk_table_is_row_selected (table, 4)) |
---|
501 | g_print("atk_table_is_row_selected returns false for row 2\n"); |
---|
502 | if (atk_table_is_row_selected (table, 2)) |
---|
503 | g_print("atk_table_is_row_selected gives false positive for row 2\n"); |
---|
504 | } |
---|
505 | |
---|
506 | if (atk_table_is_row_selected(table, 3)) |
---|
507 | { |
---|
508 | if (atk_table_remove_row_selection(table, 3)) |
---|
509 | g_print("atk_table_remove_row_selection unselected row 3\n"); |
---|
510 | } |
---|
511 | |
---|
512 | if (atk_table_is_selected(table, 5, 4)) |
---|
513 | { |
---|
514 | atk_selection_clear_selection(ATK_SELECTION(obj)); |
---|
515 | g_print("atk_selection_clear_selection: just cleared all selected\n"); |
---|
516 | } |
---|
517 | |
---|
518 | if (atk_table_is_column_selected(table, 2)) |
---|
519 | { |
---|
520 | g_print("atk_table_is_column_selected(obj, 2) returns TRUE\n"); |
---|
521 | if (atk_table_add_column_selection(table, 4)) |
---|
522 | g_print("atk_table_add_column_selection: selected column 4\n"); |
---|
523 | g_print("atk_table_is_column_selected(obj, 2) returns TRUE\n"); |
---|
524 | } |
---|
525 | |
---|
526 | if (atk_table_is_column_selected(table, 3)) |
---|
527 | { |
---|
528 | if (atk_table_remove_column_selection(table, 3)) |
---|
529 | g_print("atk_table_remove_column_selection: unselected column 3\n"); |
---|
530 | } |
---|
531 | } |
---|
532 | |
---|
533 | static void |
---|
534 | _create_event_watcher (void) |
---|
535 | { |
---|
536 | atk_add_focus_tracker (_check_table); |
---|
537 | } |
---|
538 | |
---|
539 | int |
---|
540 | gtk_module_init(gint argc, char* argv[]) |
---|
541 | { |
---|
542 | g_print("TestTable Module loaded\n"); |
---|
543 | |
---|
544 | _create_event_watcher(); |
---|
545 | |
---|
546 | return 0; |
---|
547 | } |
---|
548 | |
---|
549 | static void |
---|
550 | _notify_table_row_inserted (GObject *obj, gint start_offset, gint length) |
---|
551 | { |
---|
552 | g_print ("SIGNAL - Row inserted at position %d, num of rows inserted %d!\n", |
---|
553 | start_offset, length); |
---|
554 | } |
---|
555 | |
---|
556 | static void |
---|
557 | _notify_table_column_inserted (GObject *obj, gint start_offset, gint length) |
---|
558 | { |
---|
559 | g_print ("SIGNAL - Column inserted at position %d, num of columns inserted %d!\n", |
---|
560 | start_offset, length); |
---|
561 | } |
---|
562 | |
---|
563 | static void |
---|
564 | _notify_table_row_deleted (GObject *obj, gint start_offset, gint length) |
---|
565 | { |
---|
566 | g_print ("SIGNAL - Row deleted at position %d, num of rows deleted %d!\n", |
---|
567 | start_offset, length); |
---|
568 | } |
---|
569 | |
---|
570 | static void |
---|
571 | _notify_table_column_deleted (GObject *obj, gint start_offset, gint length) |
---|
572 | { |
---|
573 | g_print ("SIGNAL - Column deleted at position %d, num of columns deleted %d!\n", |
---|
574 | start_offset, length); |
---|
575 | } |
---|
576 | |
---|
577 | static void |
---|
578 | _notify_table_row_reordered (GObject *obj) |
---|
579 | { |
---|
580 | g_print ("SIGNAL - Row reordered!\n"); |
---|
581 | } |
---|
582 | |
---|
583 | static void |
---|
584 | _notify_table_column_reordered (GObject *obj) |
---|
585 | { |
---|
586 | g_print ("SIGNAL - Column reordered!\n"); |
---|
587 | } |
---|
588 | |
---|
589 | static void _notify_table_child_added (GObject *obj, |
---|
590 | gint index, AtkObject *child) |
---|
591 | { |
---|
592 | g_print ("SIGNAL - Child added - index %d\n", index); |
---|
593 | } |
---|
594 | |
---|
595 | static void _notify_table_child_removed (GObject *obj, |
---|
596 | gint index, AtkObject *child) |
---|
597 | { |
---|
598 | g_print ("SIGNAL - Child removed - index %d\n", index); |
---|
599 | } |
---|
600 | |
---|
601 | static void |
---|
602 | _display_header_info(gchar *type, AtkObject *header_obj, gint header_num) |
---|
603 | { |
---|
604 | if (header_obj != NULL) |
---|
605 | { |
---|
606 | AtkRole role; |
---|
607 | role = atk_object_get_role(header_obj); |
---|
608 | |
---|
609 | if (role == ATK_ROLE_PUSH_BUTTON) |
---|
610 | { |
---|
611 | g_print ("%d: %s header is a push button!\n", header_num, type); |
---|
612 | } |
---|
613 | else if (role == ATK_ROLE_LABEL) |
---|
614 | { |
---|
615 | g_print ("%d: %s header is a label!\n", header_num, type); |
---|
616 | } |
---|
617 | else if (ATK_IS_TEXT(header_obj)) |
---|
618 | { |
---|
619 | gchar *header_text; |
---|
620 | |
---|
621 | header_text = atk_text_get_text (ATK_TEXT (header_obj), 0, 3); |
---|
622 | if (header_text != NULL) |
---|
623 | { |
---|
624 | g_print("%d: %s header is a text value <%s>\n", header_num, |
---|
625 | type, header_text); |
---|
626 | } |
---|
627 | else |
---|
628 | { |
---|
629 | g_print("%d: %s header is a text value <NULL>\n", header_num, |
---|
630 | type); |
---|
631 | } |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | g_print ("%d: %s header is of type %s!\n", header_num, |
---|
636 | type, atk_role_get_name (role)); |
---|
637 | } |
---|
638 | } |
---|
639 | else |
---|
640 | { |
---|
641 | g_print ("%d: %s header object is NULL!\n", header_num, type); |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | static void _property_signal_connect (AtkObject *obj) |
---|
646 | { |
---|
647 | if (g_properties && obj != NULL) |
---|
648 | { |
---|
649 | g_signal_connect_closure_by_id (obj, |
---|
650 | g_signal_lookup ("property_change", G_OBJECT_TYPE (obj)), |
---|
651 | 0, |
---|
652 | g_cclosure_new (G_CALLBACK (_property_change_handler), |
---|
653 | NULL, NULL), |
---|
654 | FALSE); |
---|
655 | } |
---|
656 | } |
---|
657 | |
---|
658 | static void |
---|
659 | _property_change_handler (AtkObject *obj, |
---|
660 | AtkPropertyValues *values) |
---|
661 | { |
---|
662 | gchar *obj_text; |
---|
663 | const gchar *name; |
---|
664 | |
---|
665 | if (g_table != NULL) |
---|
666 | { |
---|
667 | gint index = atk_object_get_index_in_parent(obj); |
---|
668 | |
---|
669 | if (index >= 0) |
---|
670 | g_print("Index is %d, row is %d, col is %d\n", index, |
---|
671 | atk_table_get_row_at_index(g_table, index), |
---|
672 | atk_table_get_column_at_index(g_table, index)); |
---|
673 | else |
---|
674 | g_print ("index: %d for %s\n", index, g_type_name (G_OBJECT_TYPE (obj))); |
---|
675 | } |
---|
676 | |
---|
677 | if (ATK_IS_TEXT(obj)) |
---|
678 | { |
---|
679 | obj_text = atk_text_get_text (ATK_TEXT (obj), 0, 15); |
---|
680 | if (obj_text == NULL) |
---|
681 | g_print(" Cell text is <NULL>\n"); |
---|
682 | else |
---|
683 | g_print(" Cell text is <%s>\n", obj_text); |
---|
684 | } |
---|
685 | |
---|
686 | g_print(" PropertyName <%s>\n", |
---|
687 | values->property_name ? values->property_name: "NULL"); |
---|
688 | g_print(" - "); |
---|
689 | |
---|
690 | if (&values->old_value != NULL && G_IS_VALUE (&values->old_value)) |
---|
691 | { |
---|
692 | GType old_type = G_VALUE_TYPE (&values->old_value); |
---|
693 | |
---|
694 | switch (old_type) |
---|
695 | { |
---|
696 | case G_TYPE_INT: |
---|
697 | g_print("value was <%d>\n", g_value_get_int (&values->old_value)); |
---|
698 | break; |
---|
699 | case G_TYPE_STRING: |
---|
700 | name = g_value_get_string (&values->old_value); |
---|
701 | if (name != NULL) |
---|
702 | g_print ("value was <%s>\n", name); |
---|
703 | else |
---|
704 | g_print ("value was <NULL>\n"); |
---|
705 | break; |
---|
706 | default: |
---|
707 | g_print("value was <unknown type>\n"); |
---|
708 | break; |
---|
709 | } |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | g_print("value was <not a value>\n"); |
---|
714 | } |
---|
715 | g_print(" - "); |
---|
716 | if (&values->new_value != NULL && G_IS_VALUE (&values->new_value)) |
---|
717 | { |
---|
718 | GType new_type = G_VALUE_TYPE (&values->new_value); |
---|
719 | |
---|
720 | switch (new_type) |
---|
721 | { |
---|
722 | case G_TYPE_INT: |
---|
723 | g_print("value is <%d>\n", g_value_get_int (&values->new_value)); |
---|
724 | break; |
---|
725 | case G_TYPE_STRING: |
---|
726 | name = g_value_get_string (&values->new_value); |
---|
727 | if (name != NULL) |
---|
728 | g_print ("value is <%s>\n", name); |
---|
729 | else |
---|
730 | g_print ("value is <NULL>\n"); |
---|
731 | break; |
---|
732 | default: |
---|
733 | g_print("value is <unknown type>\n"); |
---|
734 | break; |
---|
735 | } |
---|
736 | } |
---|
737 | else |
---|
738 | { |
---|
739 | g_print("value is <not a value>\n"); |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | static |
---|
744 | void test_choice_gui(AtkObject **obj) |
---|
745 | { |
---|
746 | GtkWidget *window; |
---|
747 | GtkWidget *vbox; |
---|
748 | GtkWidget *hbox; |
---|
749 | GtkWidget *child_label; |
---|
750 | GtkWidget *row_label; |
---|
751 | GtkWidget *col_label; |
---|
752 | GtkWidget *index_label; |
---|
753 | GtkWidget *hseparator; |
---|
754 | GtkWidget *hbuttonbox; |
---|
755 | GtkWidget *button; |
---|
756 | |
---|
757 | |
---|
758 | tc = (TestChoice *) g_malloc (sizeof(TestChoice)); |
---|
759 | |
---|
760 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
761 | gtk_window_set_title(GTK_WINDOW(window), "Test to run"); |
---|
762 | |
---|
763 | g_signal_connect(GTK_OBJECT(window), "destroy", |
---|
764 | GTK_SIGNAL_FUNC(destroy), &window); |
---|
765 | |
---|
766 | vbox = gtk_vbox_new(TRUE, 0); |
---|
767 | gtk_box_set_spacing(GTK_BOX(vbox), 10); |
---|
768 | |
---|
769 | |
---|
770 | hbox = gtk_hbox_new(FALSE, 0); |
---|
771 | gtk_box_set_spacing(GTK_BOX(hbox), 10); |
---|
772 | tc->tb_ref_selection = gtk_toggle_button_new_with_label("ref_selection"); |
---|
773 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->tb_ref_selection); |
---|
774 | index_label = gtk_label_new("index: "); |
---|
775 | gtk_box_pack_start_defaults(GTK_BOX(hbox), index_label); |
---|
776 | tc->index_entry = gtk_entry_new(); |
---|
777 | gtk_entry_set_text(GTK_ENTRY(tc->index_entry), "1"); |
---|
778 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->index_entry); |
---|
779 | gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
---|
780 | |
---|
781 | hbox = gtk_hbox_new(FALSE, 0); |
---|
782 | gtk_box_set_spacing(GTK_BOX(hbox), 10); |
---|
783 | tc->tb_ref_at = gtk_toggle_button_new_with_label("ref_at"); |
---|
784 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->tb_ref_at); |
---|
785 | row_label = gtk_label_new("row:"); |
---|
786 | gtk_box_pack_start_defaults(GTK_BOX(hbox), row_label); |
---|
787 | tc->row_entry = gtk_entry_new(); |
---|
788 | gtk_entry_set_text(GTK_ENTRY(tc->row_entry), "1"); |
---|
789 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->row_entry); |
---|
790 | col_label = gtk_label_new("column:"); |
---|
791 | gtk_box_pack_start_defaults(GTK_BOX(hbox), col_label); |
---|
792 | tc->col_entry = gtk_entry_new(); |
---|
793 | gtk_entry_set_text(GTK_ENTRY(tc->col_entry), "1"); |
---|
794 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->col_entry); |
---|
795 | gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
---|
796 | |
---|
797 | hbox = gtk_hbox_new(FALSE, 0); |
---|
798 | gtk_box_set_spacing(GTK_BOX(hbox), 10); |
---|
799 | tc->tb_ref_accessible_child = gtk_toggle_button_new_with_label("ref_accessible_child"); |
---|
800 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->tb_ref_accessible_child); |
---|
801 | child_label = gtk_label_new("Child no:"); |
---|
802 | gtk_box_pack_start_defaults(GTK_BOX(hbox), child_label); |
---|
803 | tc->child_entry = gtk_entry_new(); |
---|
804 | gtk_entry_set_text(GTK_ENTRY(tc->child_entry), "1"); |
---|
805 | gtk_box_pack_start_defaults(GTK_BOX(hbox), tc->child_entry); |
---|
806 | gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
---|
807 | |
---|
808 | tc->tb_others = gtk_toggle_button_new_with_label("others"); |
---|
809 | gtk_box_pack_start_defaults(GTK_BOX(vbox), tc->tb_others); |
---|
810 | |
---|
811 | hseparator = gtk_hseparator_new(); |
---|
812 | gtk_box_pack_start_defaults(GTK_BOX(vbox), hseparator); |
---|
813 | |
---|
814 | button = gtk_button_new_with_mnemonic("_Run Test"); |
---|
815 | |
---|
816 | hbuttonbox = gtk_hbutton_box_new(); |
---|
817 | gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox), |
---|
818 | GTK_BUTTONBOX_SPREAD); |
---|
819 | gtk_box_pack_end_defaults(GTK_BOX(hbuttonbox), GTK_WIDGET(button)); |
---|
820 | gtk_box_pack_end_defaults(GTK_BOX(vbox), hbuttonbox); |
---|
821 | g_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(choicecb), obj); |
---|
822 | |
---|
823 | gtk_container_add(GTK_CONTAINER(window), vbox); |
---|
824 | gtk_widget_show(vbox); |
---|
825 | gtk_widget_show(window); |
---|
826 | gtk_widget_show_all(GTK_WIDGET(window)); |
---|
827 | |
---|
828 | g_visibleGUI = 1; |
---|
829 | } |
---|
830 | |
---|
831 | void static |
---|
832 | nogui_runtest (AtkObject *obj) |
---|
833 | { |
---|
834 | g_print ("Running non-GUI tests...\n"); |
---|
835 | other_runtest (obj); |
---|
836 | nogui_ref_at_runtest (obj); |
---|
837 | } |
---|
838 | |
---|
839 | static void |
---|
840 | nogui_ref_at_runtest (AtkObject *obj) |
---|
841 | { |
---|
842 | AtkObject *child_obj; |
---|
843 | gint i, j; |
---|
844 | gint n_cols; |
---|
845 | gint rows_to_loop = 5; |
---|
846 | |
---|
847 | n_cols = atk_table_get_n_columns (ATK_TABLE(obj)); |
---|
848 | |
---|
849 | if (atk_table_get_n_rows(ATK_TABLE(obj)) < rows_to_loop) |
---|
850 | rows_to_loop = atk_table_get_n_rows (ATK_TABLE(obj)); |
---|
851 | |
---|
852 | for (i=0; i < rows_to_loop; i++) |
---|
853 | { |
---|
854 | /* Just the first rows_to_loop rows */ |
---|
855 | for (j=0; j < n_cols; j++) |
---|
856 | { |
---|
857 | gint index = atk_table_get_index_at(ATK_TABLE(obj), i, j); |
---|
858 | if(atk_selection_is_child_selected(ATK_SELECTION(obj), index)) |
---|
859 | g_print("atk_selection_is_child_selected,index = %d returns TRUE\n", index); |
---|
860 | |
---|
861 | g_print("Testing ref_at row %d column %d\n", i, j); |
---|
862 | |
---|
863 | if (i == 3 && j == 0) |
---|
864 | { |
---|
865 | g_print("child_obj gotten from atk_selection_ref_selection\n"); |
---|
866 | |
---|
867 | /* use atk_selection_ref_selection just once to check it works */ |
---|
868 | child_obj = atk_selection_ref_selection(ATK_SELECTION(obj), index ); |
---|
869 | } |
---|
870 | else |
---|
871 | { |
---|
872 | child_obj = atk_table_ref_at(ATK_TABLE(obj), i, j); |
---|
873 | } |
---|
874 | |
---|
875 | _property_signal_connect(child_obj); |
---|
876 | |
---|
877 | g_print("Index is %d, row is %d, col is %d\n", index, |
---|
878 | atk_table_get_row_at_index(ATK_TABLE(obj), index), |
---|
879 | atk_table_get_column_at_index(ATK_TABLE(obj), index)); |
---|
880 | |
---|
881 | nogui_process_child (child_obj); |
---|
882 | |
---|
883 | /* Generic cell tests */ |
---|
884 | /* Just test setting column headers once. */ |
---|
885 | |
---|
886 | if (!tested_set_headers) |
---|
887 | { |
---|
888 | tested_set_headers = TRUE; |
---|
889 | |
---|
890 | g_print("Testing set_column_header for column %d, to cell value %d,%d\n", |
---|
891 | j, i, j); |
---|
892 | atk_table_set_column_header(ATK_TABLE(obj), j, child_obj); |
---|
893 | |
---|
894 | g_print("Testing set_row_header for row %d, to cell value %d,%d\n", |
---|
895 | i, i, j); |
---|
896 | atk_table_set_row_header(ATK_TABLE(obj), i, child_obj); |
---|
897 | } |
---|
898 | if (child_obj) |
---|
899 | g_object_unref (child_obj); |
---|
900 | } |
---|
901 | } |
---|
902 | } |
---|
903 | |
---|
904 | static void |
---|
905 | nogui_process_child (AtkObject *obj) |
---|
906 | { |
---|
907 | gchar default_val[5] = "NULL"; |
---|
908 | |
---|
909 | if (ATK_IS_TEXT(obj)) |
---|
910 | { |
---|
911 | gchar *current_text; |
---|
912 | current_text = atk_text_get_text (ATK_TEXT(obj), 0, -1); |
---|
913 | g_print ("Child supports text interface.\nCurrent text is %s\n", current_text); |
---|
914 | } |
---|
915 | |
---|
916 | if (ATK_IS_ACTION(obj)) |
---|
917 | { |
---|
918 | AtkAction *action = ATK_ACTION(obj); |
---|
919 | gint n_actions, i; |
---|
920 | G_CONST_RETURN gchar *name, *description; |
---|
921 | |
---|
922 | n_actions = atk_action_get_n_actions (action); |
---|
923 | g_print ("Child supports %d actions.\n", n_actions); |
---|
924 | for (i = 0; i < n_actions; i++) |
---|
925 | { |
---|
926 | name = atk_action_get_name (action, i); |
---|
927 | description = atk_action_get_description (action, i); |
---|
928 | |
---|
929 | if (name == NULL) |
---|
930 | name = default_val; |
---|
931 | if (description == NULL) |
---|
932 | description = default_val; |
---|
933 | |
---|
934 | g_print (" %d: name = <%s>\n", i, name); |
---|
935 | g_print (" description = <%s>\n", description); |
---|
936 | } |
---|
937 | } |
---|
938 | } |
---|
939 | |
---|