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