]> Pileus Git - ~andy/gtk/blob - gtk/tests/cellarea.c
Disable configuration-dependent keymap tests for now
[~andy/gtk] / gtk / tests / cellarea.c
1 /*
2  * Copyright (C) 2011 Red Hat, Inc.
3  * Author: Matthias Clasen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <gtk/gtk.h>
20 #include <gdk/gdkkeysyms.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <math.h>
24
25 /* tests related to handling of the cell-area property in
26  * GtkCellLayout implementations
27  */
28
29 /* test that we have a cell area after new() */
30 static void
31 test_iconview_new (void)
32 {
33   GtkWidget *view;
34   GtkCellArea *area;
35
36   view = gtk_icon_view_new ();
37
38   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
39   g_assert (GTK_IS_CELL_AREA_BOX (area));
40   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == gtk_icon_view_get_item_orientation (GTK_ICON_VIEW (view)));
41
42   g_object_ref_sink (view);
43   g_object_unref (view);
44 }
45
46 /* test that new_with_area() keeps the provided area */
47 static void
48 test_iconview_new_with_area (void)
49 {
50   GtkWidget *view;
51   GtkCellArea *area;
52
53   area = gtk_cell_area_box_new ();
54   view = gtk_icon_view_new_with_area (area);
55   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
56
57   g_object_ref_sink (view);
58   g_object_unref (view);
59 }
60
61 /* test that g_object_new keeps the provided area */
62 static void
63 test_iconview_object_new (void)
64 {
65   GtkWidget *view;
66   GtkCellArea *area;
67
68   area = gtk_cell_area_box_new ();
69   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
70   view = g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
71   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
72   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == gtk_icon_view_get_item_orientation (GTK_ICON_VIEW (view)));
73
74   g_object_ref_sink (view);
75   g_object_unref (view);
76 }
77
78 typedef GtkIconView MyIconView;
79 typedef GtkIconViewClass MyIconViewClass;
80
81 G_DEFINE_TYPE (MyIconView, my_icon_view, GTK_TYPE_ICON_VIEW)
82
83 static void
84 my_icon_view_class_init (MyIconViewClass *klass)
85 {
86 }
87
88 static gint subclass_init;
89
90 static void
91 my_icon_view_init (MyIconView *view)
92 {
93   GtkCellArea *area;
94
95   if (subclass_init == 0)
96     {
97       /* do nothing to area */
98     }
99   else if (subclass_init == 1)
100     {
101       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
102       g_assert (GTK_IS_CELL_AREA_BOX (area));
103       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
104       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
105     }
106 }
107
108 /* test that an iconview subclass has an area */
109 static void
110 test_iconview_subclass0 (void)
111 {
112   GtkWidget *view;
113   GtkCellArea *area;
114
115   subclass_init = 0;
116
117   view = g_object_new (my_icon_view_get_type (), NULL);
118   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
119   g_assert (GTK_IS_CELL_AREA_BOX (area));
120   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
121
122   g_object_ref_sink (view);
123   g_object_unref (view);
124 }
125
126 /* test that an iconview subclass keeps the provided area */
127 static void
128 test_iconview_subclass1 (void)
129 {
130   GtkWidget *view;
131   GtkCellArea *area;
132
133   subclass_init = 0;
134
135   area = gtk_cell_area_box_new ();
136   view = g_object_new (my_icon_view_get_type (), "cell-area", area, NULL);
137   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
138   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
139
140   g_object_ref_sink (view);
141   g_object_unref (view);
142 }
143
144 /* test we can access the area in subclass init */
145 static void
146 test_iconview_subclass2 (void)
147 {
148   GtkWidget *view;
149   GtkCellArea *area;
150
151   subclass_init = 1;
152
153   view = g_object_new (my_icon_view_get_type (), NULL);
154   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
155   g_assert (GTK_IS_CELL_AREA_BOX (area));
156   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
157
158   g_object_ref_sink (view);
159   g_object_unref (view);
160 }
161
162 /* test we get a warning if an area is provided, but ignored */
163 static void
164 test_iconview_subclass3 (void)
165 {
166   subclass_init = 1;
167
168   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
169     {
170       GtkWidget *view;
171       GtkCellArea *area;
172
173       area = gtk_cell_area_box_new ();
174       view = g_object_new (my_icon_view_get_type (), "cell-area", area, NULL);
175       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
176       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
177
178       g_object_ref_sink (view);
179       g_object_unref (view);
180
181       exit (0);
182     }
183   g_test_trap_assert_failed ();
184   g_test_trap_assert_stderr ("*ignoring construct property*");
185 }
186
187 /* test that we have a cell area after new() */
188 static void
189 test_combobox_new (void)
190 {
191   GtkWidget *view;
192   GtkCellArea *area;
193
194   view = gtk_combo_box_new ();
195
196   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
197   g_assert (GTK_IS_CELL_AREA_BOX (area));
198
199   g_object_ref_sink (view);
200   g_object_unref (view);
201 }
202
203 /* test that new_with_area() keeps the provided area */
204 static void
205 test_combobox_new_with_area (void)
206 {
207   GtkWidget *view;
208   GtkCellArea *area;
209
210   area = gtk_cell_area_box_new ();
211   view = gtk_combo_box_new_with_area (area);
212   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
213
214   g_object_ref_sink (view);
215   g_object_unref (view);
216 }
217
218 /* test that g_object_new keeps the provided area */
219 static void
220 test_combobox_object_new (void)
221 {
222   GtkWidget *view;
223   GtkCellArea *area;
224
225   area = gtk_cell_area_box_new ();
226   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
227   view = g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", area, NULL);
228   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
229
230   g_object_ref_sink (view);
231   g_object_unref (view);
232 }
233
234 typedef GtkComboBox MyComboBox;
235 typedef GtkComboBoxClass MyComboBoxClass;
236
237 G_DEFINE_TYPE (MyComboBox, my_combo_box, GTK_TYPE_COMBO_BOX)
238
239 static void
240 my_combo_box_class_init (MyComboBoxClass *klass)
241 {
242 }
243
244 static void
245 my_combo_box_init (MyComboBox *view)
246 {
247   GtkCellArea *area;
248
249   if (subclass_init == 0)
250     {
251       /* do nothing to area */
252     }
253   else if (subclass_init == 1)
254     {
255       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
256       g_assert (GTK_IS_CELL_AREA_BOX (area));
257       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
258       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
259     }
260 }
261
262 /* test that a combobox subclass has an area */
263 static void
264 test_combobox_subclass0 (void)
265 {
266   GtkWidget *view;
267   GtkCellArea *area;
268
269   subclass_init = 0;
270
271   view = g_object_new (my_combo_box_get_type (), NULL);
272   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
273   g_assert (GTK_IS_CELL_AREA_BOX (area));
274   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
275
276   g_object_ref_sink (view);
277   g_object_unref (view);
278 }
279
280 /* test that a combobox subclass keeps the provided area */
281 static void
282 test_combobox_subclass1 (void)
283 {
284   GtkWidget *view;
285   GtkCellArea *area;
286
287   subclass_init = 0;
288
289   area = gtk_cell_area_box_new ();
290   view = g_object_new (my_combo_box_get_type (), "cell-area", area, NULL);
291   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
292   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
293
294   g_object_ref_sink (view);
295   g_object_unref (view);
296 }
297
298 /* test we can access the area in subclass init */
299 static void
300 test_combobox_subclass2 (void)
301 {
302   GtkWidget *view;
303   GtkCellArea *area;
304
305   subclass_init = 1;
306
307   view = g_object_new (my_combo_box_get_type (), NULL);
308   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
309   g_assert (GTK_IS_CELL_AREA_BOX (area));
310   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
311
312   g_object_ref_sink (view);
313   g_object_unref (view);
314 }
315
316 /* test we get a warning if an area is provided, but ignored */
317 static void
318 test_combobox_subclass3 (void)
319 {
320   subclass_init = 1;
321
322   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
323     {
324       GtkWidget *view;
325       GtkCellArea *area;
326
327       area = gtk_cell_area_box_new ();
328       view = g_object_new (my_combo_box_get_type (), "cell-area", area, NULL);
329       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
330       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
331
332       g_object_ref_sink (view);
333       g_object_unref (view);
334
335       exit (0);
336     }
337   g_test_trap_assert_failed ();
338   g_test_trap_assert_stderr ("*ignoring construct property*");
339 }
340
341 /* test that we have a cell area after new() */
342 static void
343 test_cellview_new (void)
344 {
345   GtkWidget *view;
346   GtkCellArea *area;
347
348   view = gtk_cell_view_new ();
349
350   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
351   g_assert (GTK_IS_CELL_AREA_BOX (area));
352
353   g_object_ref_sink (view);
354   g_object_unref (view);
355 }
356
357 /* test that new_with_context() keeps the provided area */
358 static void
359 test_cellview_new_with_context (void)
360 {
361   GtkWidget *view;
362   GtkCellArea *area;
363   GtkCellAreaContext *context;
364
365   area = gtk_cell_area_box_new ();
366   context = gtk_cell_area_create_context (area);
367   view = gtk_cell_view_new_with_context (area, context);
368   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
369
370   g_object_ref_sink (view);
371   g_object_unref (view);
372 }
373
374 /* test that g_object_new keeps the provided area */
375 static void
376 test_cellview_object_new (void)
377 {
378   GtkWidget *view;
379   GtkCellArea *area;
380
381   area = gtk_cell_area_box_new ();
382   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
383   view = g_object_new (GTK_TYPE_CELL_VIEW, "cell-area", area, NULL);
384   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
385
386   g_object_ref_sink (view);
387   g_object_unref (view);
388 }
389
390 typedef GtkCellView MyCellView;
391 typedef GtkCellViewClass MyCellViewClass;
392
393 G_DEFINE_TYPE (MyCellView, my_cell_view, GTK_TYPE_CELL_VIEW)
394
395 static void
396 my_cell_view_class_init (MyCellViewClass *klass)
397 {
398 }
399
400 static void
401 my_cell_view_init (MyCellView *view)
402 {
403   GtkCellArea *area;
404
405   if (subclass_init == 0)
406     {
407       /* do nothing to area */
408     }
409   else if (subclass_init == 1)
410     {
411       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
412       g_assert (GTK_IS_CELL_AREA_BOX (area));
413       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
414       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
415     }
416 }
417
418 /* test that a cellview subclass has an area */
419 static void
420 test_cellview_subclass0 (void)
421 {
422   GtkWidget *view;
423   GtkCellArea *area;
424
425   subclass_init = 0;
426
427   view = g_object_new (my_cell_view_get_type (), NULL);
428   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
429   g_assert (GTK_IS_CELL_AREA_BOX (area));
430   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
431
432   g_object_ref_sink (view);
433   g_object_unref (view);
434 }
435
436 /* test that a cellview subclass keeps the provided area */
437 static void
438 test_cellview_subclass1 (void)
439 {
440   GtkWidget *view;
441   GtkCellArea *area;
442
443   subclass_init = 0;
444
445   area = gtk_cell_area_box_new ();
446   view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
447   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
448   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
449
450   g_object_ref_sink (view);
451   g_object_unref (view);
452 }
453
454 /* test we can access the area in subclass init */
455 static void
456 test_cellview_subclass2 (void)
457 {
458   GtkWidget *view;
459   GtkCellArea *area;
460
461   subclass_init = 1;
462
463   view = g_object_new (my_cell_view_get_type (), NULL);
464   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
465   g_assert (GTK_IS_CELL_AREA_BOX (area));
466   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
467
468   g_object_ref_sink (view);
469   g_object_unref (view);
470 }
471
472 /* test we get a warning if an area is provided, but ignored */
473 static void
474 test_cellview_subclass3 (void)
475 {
476   subclass_init = 1;
477
478   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
479     {
480       GtkWidget *view;
481       GtkCellArea *area;
482
483       area = gtk_cell_area_box_new ();
484       view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
485       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
486       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
487
488       g_object_ref_sink (view);
489       g_object_unref (view);
490
491       exit (0);
492     }
493   g_test_trap_assert_failed ();
494   g_test_trap_assert_stderr ("*ignoring construct property*");
495 }
496
497 /* test that we have a cell area after new() */
498 static void
499 test_column_new (void)
500 {
501   GtkTreeViewColumn *col;
502   GtkCellArea *area;
503
504   col = gtk_tree_view_column_new ();
505
506   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
507   g_assert (GTK_IS_CELL_AREA_BOX (area));
508
509   g_object_ref_sink (col);
510   g_object_unref (col);
511 }
512
513 /* test that new_with_area() keeps the provided area */
514 static void
515 test_column_new_with_area (void)
516 {
517   GtkTreeViewColumn *col;
518   GtkCellArea *area;
519
520   area = gtk_cell_area_box_new ();
521   col = gtk_tree_view_column_new_with_area (area);
522   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
523
524   g_object_ref_sink (col);
525   g_object_unref (col);
526 }
527
528 /* test that g_object_new keeps the provided area */
529 static void
530 test_column_object_new (void)
531 {
532   GtkTreeViewColumn *col;
533   GtkCellArea *area;
534
535   area = gtk_cell_area_box_new ();
536   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
537   col = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, "cell-area", area, NULL);
538   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
539
540   g_object_ref_sink (col);
541   g_object_unref (col);
542 }
543
544 typedef GtkTreeViewColumn MyTreeViewColumn;
545 typedef GtkTreeViewColumnClass MyTreeViewColumnClass;
546
547 G_DEFINE_TYPE (MyTreeViewColumn, my_tree_view_column, GTK_TYPE_TREE_VIEW_COLUMN)
548
549 static void
550 my_tree_view_column_class_init (MyTreeViewColumnClass *klass)
551 {
552 }
553
554 static void
555 my_tree_view_column_init (MyTreeViewColumn *col)
556 {
557   GtkCellArea *area;
558
559   if (subclass_init == 0)
560     {
561       /* do nothing to area */
562     }
563   else if (subclass_init == 1)
564     {
565       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
566       g_assert (GTK_IS_CELL_AREA_BOX (area));
567       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
568       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
569     }
570 }
571
572 /* test that a column subclass has an area */
573 static void
574 test_column_subclass0 (void)
575 {
576   GtkTreeViewColumn *col;
577   GtkCellArea *area;
578
579   subclass_init = 0;
580
581   col = g_object_new (my_tree_view_column_get_type (), NULL);
582   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
583   g_assert (GTK_IS_CELL_AREA_BOX (area));
584   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
585
586   g_object_ref_sink (col);
587   g_object_unref (col);
588 }
589
590 /* test that a column subclass keeps the provided area */
591 static void
592 test_column_subclass1 (void)
593 {
594   GtkTreeViewColumn *col;
595   GtkCellArea *area;
596
597   subclass_init = 0;
598
599   area = gtk_cell_area_box_new ();
600   col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
601   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
602   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
603
604   g_object_ref_sink (col);
605   g_object_unref (col);
606 }
607
608 /* test we can access the area in subclass init */
609 static void
610 test_column_subclass2 (void)
611 {
612   GtkTreeViewColumn *col;
613   GtkCellArea *area;
614
615   subclass_init = 1;
616
617   col = g_object_new (my_tree_view_column_get_type (), NULL);
618   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
619   g_assert (GTK_IS_CELL_AREA_BOX (area));
620   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
621
622   g_object_ref_sink (col);
623   g_object_unref (col);
624 }
625
626 /* test we get a warning if an area is provided, but ignored */
627 static void
628 test_column_subclass3 (void)
629 {
630   subclass_init = 1;
631
632   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
633     {
634       GtkTreeViewColumn *col;
635       GtkCellArea *area;
636
637       area = gtk_cell_area_box_new ();
638       col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
639       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
640       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
641
642       g_object_ref_sink (col);
643       g_object_unref (col);
644
645       exit (0);
646     }
647   g_test_trap_assert_failed ();
648   g_test_trap_assert_stderr ("*ignoring construct property*");
649 }
650
651 /* test that we have a cell area after new() */
652 static void
653 test_completion_new (void)
654 {
655   GtkEntryCompletion *c;
656   GtkCellArea *area;
657
658   c = gtk_entry_completion_new ();
659
660   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
661   g_assert (GTK_IS_CELL_AREA_BOX (area));
662
663   g_object_ref_sink (c);
664   g_object_unref (c);
665 }
666
667 /* test that new_with_area() keeps the provided area */
668 static void
669 test_completion_new_with_area (void)
670 {
671   GtkEntryCompletion *c;
672   GtkCellArea *area;
673
674   area = gtk_cell_area_box_new ();
675   c = gtk_entry_completion_new_with_area (area);
676   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
677
678   g_object_ref_sink (c);
679   g_object_unref (c);
680 }
681
682 /* test that g_object_new keeps the provided area */
683 static void
684 test_completion_object_new (void)
685 {
686   GtkEntryCompletion *c;
687   GtkCellArea *area;
688
689   area = gtk_cell_area_box_new ();
690   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
691   c = g_object_new (GTK_TYPE_ENTRY_COMPLETION, "cell-area", area, NULL);
692   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
693
694   g_object_ref_sink (c);
695   g_object_unref (c);
696 }
697
698 typedef GtkEntryCompletion MyEntryCompletion;
699 typedef GtkEntryCompletionClass MyEntryCompletionClass;
700
701 G_DEFINE_TYPE (MyEntryCompletion, my_entry_completion, GTK_TYPE_ENTRY_COMPLETION)
702
703 static void
704 my_entry_completion_class_init (MyEntryCompletionClass *klass)
705 {
706 }
707
708 static void
709 my_entry_completion_init (MyEntryCompletion *c)
710 {
711   GtkCellArea *area;
712
713   if (subclass_init == 0)
714     {
715       /* do nothing to area */
716     }
717   else if (subclass_init == 1)
718     {
719       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
720       g_assert (GTK_IS_CELL_AREA_BOX (area));
721       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
722       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
723     }
724 }
725
726 /* test that a completion subclass has an area */
727 static void
728 test_completion_subclass0 (void)
729 {
730   GtkEntryCompletion *c;
731   GtkCellArea *area;
732
733   subclass_init = 0;
734
735   c = g_object_new (my_entry_completion_get_type (), NULL);
736   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
737   g_assert (GTK_IS_CELL_AREA_BOX (area));
738   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
739
740   g_object_ref_sink (c);
741   g_object_unref (c);
742 }
743
744 /* test that a completion subclass keeps the provided area */
745 static void
746 test_completion_subclass1 (void)
747 {
748   GtkEntryCompletion *c;
749   GtkCellArea *area;
750
751   subclass_init = 0;
752
753   area = gtk_cell_area_box_new ();
754   c = g_object_new (my_entry_completion_get_type (), "cell-area", area, NULL);
755   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)));
756   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
757
758   g_object_ref_sink (c);
759   g_object_unref (c);
760 }
761
762 /* test we can access the area in subclass init */
763 static void
764 test_completion_subclass2 (void)
765 {
766   GtkEntryCompletion *c;
767   GtkCellArea *area;
768
769   subclass_init = 1;
770
771   c = g_object_new (my_entry_completion_get_type (), NULL);
772   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
773   g_assert (GTK_IS_CELL_AREA_BOX (area));
774   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
775
776   g_object_ref_sink (c);
777   g_object_unref (c);
778 }
779
780 /* test we get a warning if an area is provided, but ignored */
781 static void
782 test_completion_subclass3 (void)
783 {
784   subclass_init = 1;
785
786   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
787     {
788       GtkEntryCompletion *c;
789       GtkCellArea *area;
790
791       area = gtk_cell_area_box_new ();
792       c = g_object_new (my_entry_completion_get_type (), "cell-area", area, NULL);
793       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)));
794       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
795
796       g_object_ref_sink (c);
797       g_object_unref (c);
798
799       exit (0);
800     }
801   g_test_trap_assert_failed ();
802   g_test_trap_assert_stderr ("*ignoring construct property*");
803 }
804
805 int
806 main (int argc, char *argv[])
807 {
808   gtk_test_init (&argc, &argv);
809   g_test_bug_base ("http://bugzilla.gnome.org/");
810   gtk_test_register_all_types();
811
812   g_test_add_func ("/tests/iconview-new", test_iconview_new);
813   g_test_add_func ("/tests/iconview-new-with-area", test_iconview_new_with_area);
814   g_test_add_func ("/tests/iconview-object-new", test_iconview_object_new);
815   g_test_add_func ("/tests/iconview-subclass0", test_iconview_subclass0);
816   g_test_add_func ("/tests/iconview-subclass1", test_iconview_subclass1);
817   g_test_add_func ("/tests/iconview-subclass2", test_iconview_subclass2);
818   g_test_add_func ("/tests/iconview-subclass3", test_iconview_subclass3);
819
820   g_test_add_func ("/tests/combobox-new", test_combobox_new);
821   g_test_add_func ("/tests/combobox-new-with-area", test_combobox_new_with_area);
822   g_test_add_func ("/tests/combobox-object-new", test_combobox_object_new);
823   g_test_add_func ("/tests/combobox-subclass0", test_combobox_subclass0);
824   g_test_add_func ("/tests/combobox-subclass1", test_combobox_subclass1);
825   g_test_add_func ("/tests/combobox-subclass2", test_combobox_subclass2);
826   g_test_add_func ("/tests/combobox-subclass3", test_combobox_subclass3);
827
828   g_test_add_func ("/tests/cellview-new", test_cellview_new);
829   g_test_add_func ("/tests/cellview-new-with-context", test_cellview_new_with_context);
830   g_test_add_func ("/tests/cellview-object-new", test_cellview_object_new);
831   g_test_add_func ("/tests/cellview-subclass0", test_cellview_subclass0);
832   g_test_add_func ("/tests/cellview-subclass1", test_cellview_subclass1);
833   g_test_add_func ("/tests/cellview-subclass2", test_cellview_subclass2);
834   g_test_add_func ("/tests/cellview-subclass3", test_cellview_subclass3);
835
836   g_test_add_func ("/tests/column-new", test_column_new);
837   g_test_add_func ("/tests/column-new-with-area", test_column_new_with_area);
838   g_test_add_func ("/tests/column-object-new", test_column_object_new);
839   g_test_add_func ("/tests/column-subclass0", test_column_subclass0);
840   g_test_add_func ("/tests/column-subclass1", test_column_subclass1);
841   g_test_add_func ("/tests/column-subclass2", test_column_subclass2);
842   g_test_add_func ("/tests/column-subclass3", test_column_subclass3);
843
844   g_test_add_func ("/tests/completion-new", test_completion_new);
845   g_test_add_func ("/tests/completion-new-with-area", test_completion_new_with_area);
846   g_test_add_func ("/tests/completion-object-new", test_completion_object_new);
847   g_test_add_func ("/tests/completion-subclass0", test_completion_subclass0);
848   g_test_add_func ("/tests/completion-subclass1", test_completion_subclass1);
849   g_test_add_func ("/tests/completion-subclass2", test_completion_subclass2);
850   g_test_add_func ("/tests/completion-subclass3", test_completion_subclass3);
851
852   return g_test_run();
853 }