]> Pileus Git - ~andy/gtk/blob - gtk/tests/cellarea.c
Unit test a corner case of gtk_tree_model_filter_rows_reordered()
[~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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <gtk/gtk.h>
22 #include <gdk/gdkkeysyms.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <math.h>
26
27 /* tests related to handling of the cell-area property in
28  * GtkCellLayout implementations
29  */
30
31 /* test that we have a cell area after new() */
32 static void
33 test_iconview_new (void)
34 {
35   GtkWidget *view;
36   GtkCellArea *area;
37
38   view = gtk_icon_view_new ();
39
40   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
41   g_assert (GTK_IS_CELL_AREA_BOX (area));
42   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == gtk_icon_view_get_item_orientation (GTK_ICON_VIEW (view)));
43
44   g_object_ref_sink (view);
45   g_object_unref (view);
46 }
47
48 /* test that new_with_area() keeps the provided area */
49 static void
50 test_iconview_new_with_area (void)
51 {
52   GtkWidget *view;
53   GtkCellArea *area;
54
55   area = gtk_cell_area_box_new ();
56   view = gtk_icon_view_new_with_area (area);
57   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
58
59   g_object_ref_sink (view);
60   g_object_unref (view);
61 }
62
63 /* test that g_object_new keeps the provided area */
64 static void
65 test_iconview_object_new (void)
66 {
67   GtkWidget *view;
68   GtkCellArea *area;
69
70   area = gtk_cell_area_box_new ();
71   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
72   view = g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
73   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
74   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == gtk_icon_view_get_item_orientation (GTK_ICON_VIEW (view)));
75
76   g_object_ref_sink (view);
77   g_object_unref (view);
78 }
79
80 typedef GtkIconView MyIconView;
81 typedef GtkIconViewClass MyIconViewClass;
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 G_DEFINE_TYPE (MyComboBox, my_combo_box, GTK_TYPE_COMBO_BOX)
240
241 static void
242 my_combo_box_class_init (MyComboBoxClass *klass)
243 {
244 }
245
246 static void
247 my_combo_box_init (MyComboBox *view)
248 {
249   GtkCellArea *area;
250
251   if (subclass_init == 0)
252     {
253       /* do nothing to area */
254     }
255   else if (subclass_init == 1)
256     {
257       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
258       g_assert (GTK_IS_CELL_AREA_BOX (area));
259       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
260       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
261     }
262 }
263
264 /* test that a combobox subclass has an area */
265 static void
266 test_combobox_subclass0 (void)
267 {
268   GtkWidget *view;
269   GtkCellArea *area;
270
271   subclass_init = 0;
272
273   view = g_object_new (my_combo_box_get_type (), NULL);
274   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
275   g_assert (GTK_IS_CELL_AREA_BOX (area));
276   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
277
278   g_object_ref_sink (view);
279   g_object_unref (view);
280 }
281
282 /* test that a combobox subclass keeps the provided area */
283 static void
284 test_combobox_subclass1 (void)
285 {
286   GtkWidget *view;
287   GtkCellArea *area;
288
289   subclass_init = 0;
290
291   area = gtk_cell_area_box_new ();
292   view = g_object_new (my_combo_box_get_type (), "cell-area", area, NULL);
293   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
294   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
295
296   g_object_ref_sink (view);
297   g_object_unref (view);
298 }
299
300 /* test we can access the area in subclass init */
301 static void
302 test_combobox_subclass2 (void)
303 {
304   GtkWidget *view;
305   GtkCellArea *area;
306
307   subclass_init = 1;
308
309   view = g_object_new (my_combo_box_get_type (), NULL);
310   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
311   g_assert (GTK_IS_CELL_AREA_BOX (area));
312   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
313
314   g_object_ref_sink (view);
315   g_object_unref (view);
316 }
317
318 /* test we get a warning if an area is provided, but ignored */
319 static void
320 test_combobox_subclass3 (void)
321 {
322   subclass_init = 1;
323
324   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
325     {
326       GtkWidget *view;
327       GtkCellArea *area;
328
329       area = gtk_cell_area_box_new ();
330       view = g_object_new (my_combo_box_get_type (), "cell-area", area, NULL);
331       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
332       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
333
334       g_object_ref_sink (view);
335       g_object_unref (view);
336
337       exit (0);
338     }
339   g_test_trap_assert_failed ();
340   g_test_trap_assert_stderr ("*ignoring construct property*");
341 }
342
343 /* test that we have a cell area after new() */
344 static void
345 test_cellview_new (void)
346 {
347   GtkWidget *view;
348   GtkCellArea *area;
349
350   view = gtk_cell_view_new ();
351
352   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
353   g_assert (GTK_IS_CELL_AREA_BOX (area));
354
355   g_object_ref_sink (view);
356   g_object_unref (view);
357 }
358
359 /* test that new_with_context() keeps the provided area */
360 static void
361 test_cellview_new_with_context (void)
362 {
363   GtkWidget *view;
364   GtkCellArea *area;
365   GtkCellAreaContext *context;
366
367   area = gtk_cell_area_box_new ();
368   context = gtk_cell_area_create_context (area);
369   view = gtk_cell_view_new_with_context (area, context);
370   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
371
372   g_object_ref_sink (view);
373   g_object_unref (view);
374 }
375
376 /* test that g_object_new keeps the provided area */
377 static void
378 test_cellview_object_new (void)
379 {
380   GtkWidget *view;
381   GtkCellArea *area;
382
383   area = gtk_cell_area_box_new ();
384   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
385   view = g_object_new (GTK_TYPE_CELL_VIEW, "cell-area", area, NULL);
386   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
387
388   g_object_ref_sink (view);
389   g_object_unref (view);
390 }
391
392 typedef GtkCellView MyCellView;
393 typedef GtkCellViewClass MyCellViewClass;
394
395 G_DEFINE_TYPE (MyCellView, my_cell_view, GTK_TYPE_CELL_VIEW)
396
397 static void
398 my_cell_view_class_init (MyCellViewClass *klass)
399 {
400 }
401
402 static void
403 my_cell_view_init (MyCellView *view)
404 {
405   GtkCellArea *area;
406
407   if (subclass_init == 0)
408     {
409       /* do nothing to area */
410     }
411   else if (subclass_init == 1)
412     {
413       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
414       g_assert (GTK_IS_CELL_AREA_BOX (area));
415       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
416       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
417     }
418 }
419
420 /* test that a cellview subclass has an area */
421 static void
422 test_cellview_subclass0 (void)
423 {
424   GtkWidget *view;
425   GtkCellArea *area;
426
427   subclass_init = 0;
428
429   view = g_object_new (my_cell_view_get_type (), NULL);
430   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
431   g_assert (GTK_IS_CELL_AREA_BOX (area));
432   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
433
434   g_object_ref_sink (view);
435   g_object_unref (view);
436 }
437
438 /* test that a cellview subclass keeps the provided area */
439 static void
440 test_cellview_subclass1 (void)
441 {
442   GtkWidget *view;
443   GtkCellArea *area;
444
445   subclass_init = 0;
446
447   area = gtk_cell_area_box_new ();
448   view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
449   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
450   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
451
452   g_object_ref_sink (view);
453   g_object_unref (view);
454 }
455
456 /* test we can access the area in subclass init */
457 static void
458 test_cellview_subclass2 (void)
459 {
460   GtkWidget *view;
461   GtkCellArea *area;
462
463   subclass_init = 1;
464
465   view = g_object_new (my_cell_view_get_type (), NULL);
466   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
467   g_assert (GTK_IS_CELL_AREA_BOX (area));
468   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
469
470   g_object_ref_sink (view);
471   g_object_unref (view);
472 }
473
474 /* test we get a warning if an area is provided, but ignored */
475 static void
476 test_cellview_subclass3 (void)
477 {
478   subclass_init = 1;
479
480   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
481     {
482       GtkWidget *view;
483       GtkCellArea *area;
484
485       area = gtk_cell_area_box_new ();
486       view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
487       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
488       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
489
490       g_object_ref_sink (view);
491       g_object_unref (view);
492
493       exit (0);
494     }
495   g_test_trap_assert_failed ();
496   g_test_trap_assert_stderr ("*ignoring construct property*");
497 }
498
499 /* test that we have a cell area after new() */
500 static void
501 test_column_new (void)
502 {
503   GtkTreeViewColumn *col;
504   GtkCellArea *area;
505
506   col = gtk_tree_view_column_new ();
507
508   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
509   g_assert (GTK_IS_CELL_AREA_BOX (area));
510
511   g_object_ref_sink (col);
512   g_object_unref (col);
513 }
514
515 /* test that new_with_area() keeps the provided area */
516 static void
517 test_column_new_with_area (void)
518 {
519   GtkTreeViewColumn *col;
520   GtkCellArea *area;
521
522   area = gtk_cell_area_box_new ();
523   col = gtk_tree_view_column_new_with_area (area);
524   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
525
526   g_object_ref_sink (col);
527   g_object_unref (col);
528 }
529
530 /* test that g_object_new keeps the provided area */
531 static void
532 test_column_object_new (void)
533 {
534   GtkTreeViewColumn *col;
535   GtkCellArea *area;
536
537   area = gtk_cell_area_box_new ();
538   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
539   col = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, "cell-area", area, NULL);
540   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
541
542   g_object_ref_sink (col);
543   g_object_unref (col);
544 }
545
546 typedef GtkTreeViewColumn MyTreeViewColumn;
547 typedef GtkTreeViewColumnClass MyTreeViewColumnClass;
548
549 G_DEFINE_TYPE (MyTreeViewColumn, my_tree_view_column, GTK_TYPE_TREE_VIEW_COLUMN)
550
551 static void
552 my_tree_view_column_class_init (MyTreeViewColumnClass *klass)
553 {
554 }
555
556 static void
557 my_tree_view_column_init (MyTreeViewColumn *col)
558 {
559   GtkCellArea *area;
560
561   if (subclass_init == 0)
562     {
563       /* do nothing to area */
564     }
565   else if (subclass_init == 1)
566     {
567       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
568       g_assert (GTK_IS_CELL_AREA_BOX (area));
569       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
570       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
571     }
572 }
573
574 /* test that a column subclass has an area */
575 static void
576 test_column_subclass0 (void)
577 {
578   GtkTreeViewColumn *col;
579   GtkCellArea *area;
580
581   subclass_init = 0;
582
583   col = g_object_new (my_tree_view_column_get_type (), NULL);
584   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
585   g_assert (GTK_IS_CELL_AREA_BOX (area));
586   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
587
588   g_object_ref_sink (col);
589   g_object_unref (col);
590 }
591
592 /* test that a column subclass keeps the provided area */
593 static void
594 test_column_subclass1 (void)
595 {
596   GtkTreeViewColumn *col;
597   GtkCellArea *area;
598
599   subclass_init = 0;
600
601   area = gtk_cell_area_box_new ();
602   col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
603   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
604   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
605
606   g_object_ref_sink (col);
607   g_object_unref (col);
608 }
609
610 /* test we can access the area in subclass init */
611 static void
612 test_column_subclass2 (void)
613 {
614   GtkTreeViewColumn *col;
615   GtkCellArea *area;
616
617   subclass_init = 1;
618
619   col = g_object_new (my_tree_view_column_get_type (), NULL);
620   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
621   g_assert (GTK_IS_CELL_AREA_BOX (area));
622   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
623
624   g_object_ref_sink (col);
625   g_object_unref (col);
626 }
627
628 /* test we get a warning if an area is provided, but ignored */
629 static void
630 test_column_subclass3 (void)
631 {
632   subclass_init = 1;
633
634   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
635     {
636       GtkTreeViewColumn *col;
637       GtkCellArea *area;
638
639       area = gtk_cell_area_box_new ();
640       col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
641       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
642       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
643
644       g_object_ref_sink (col);
645       g_object_unref (col);
646
647       exit (0);
648     }
649   g_test_trap_assert_failed ();
650   g_test_trap_assert_stderr ("*ignoring construct property*");
651 }
652
653 /* test that we have a cell area after new() */
654 static void
655 test_completion_new (void)
656 {
657   GtkEntryCompletion *c;
658   GtkCellArea *area;
659
660   c = gtk_entry_completion_new ();
661
662   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
663   g_assert (GTK_IS_CELL_AREA_BOX (area));
664
665   g_object_ref_sink (c);
666   g_object_unref (c);
667 }
668
669 /* test that new_with_area() keeps the provided area */
670 static void
671 test_completion_new_with_area (void)
672 {
673   GtkEntryCompletion *c;
674   GtkCellArea *area;
675
676   area = gtk_cell_area_box_new ();
677   c = gtk_entry_completion_new_with_area (area);
678   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
679
680   g_object_ref_sink (c);
681   g_object_unref (c);
682 }
683
684 /* test that g_object_new keeps the provided area */
685 static void
686 test_completion_object_new (void)
687 {
688   GtkEntryCompletion *c;
689   GtkCellArea *area;
690
691   area = gtk_cell_area_box_new ();
692   gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
693   c = g_object_new (GTK_TYPE_ENTRY_COMPLETION, "cell-area", area, NULL);
694   g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
695
696   g_object_ref_sink (c);
697   g_object_unref (c);
698 }
699
700 typedef GtkEntryCompletion MyEntryCompletion;
701 typedef GtkEntryCompletionClass MyEntryCompletionClass;
702
703 G_DEFINE_TYPE (MyEntryCompletion, my_entry_completion, GTK_TYPE_ENTRY_COMPLETION)
704
705 static void
706 my_entry_completion_class_init (MyEntryCompletionClass *klass)
707 {
708 }
709
710 static void
711 my_entry_completion_init (MyEntryCompletion *c)
712 {
713   GtkCellArea *area;
714
715   if (subclass_init == 0)
716     {
717       /* do nothing to area */
718     }
719   else if (subclass_init == 1)
720     {
721       area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
722       g_assert (GTK_IS_CELL_AREA_BOX (area));
723       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
724       gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
725     }
726 }
727
728 /* test that a completion subclass has an area */
729 static void
730 test_completion_subclass0 (void)
731 {
732   GtkEntryCompletion *c;
733   GtkCellArea *area;
734
735   subclass_init = 0;
736
737   c = g_object_new (my_entry_completion_get_type (), NULL);
738   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
739   g_assert (GTK_IS_CELL_AREA_BOX (area));
740   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
741
742   g_object_ref_sink (c);
743   g_object_unref (c);
744 }
745
746 /* test that a completion subclass keeps the provided area */
747 static void
748 test_completion_subclass1 (void)
749 {
750   GtkEntryCompletion *c;
751   GtkCellArea *area;
752
753   subclass_init = 0;
754
755   area = gtk_cell_area_box_new ();
756   c = g_object_new (my_entry_completion_get_type (), "cell-area", area, NULL);
757   g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)));
758   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
759
760   g_object_ref_sink (c);
761   g_object_unref (c);
762 }
763
764 /* test we can access the area in subclass init */
765 static void
766 test_completion_subclass2 (void)
767 {
768   GtkEntryCompletion *c;
769   GtkCellArea *area;
770
771   subclass_init = 1;
772
773   c = g_object_new (my_entry_completion_get_type (), NULL);
774   area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
775   g_assert (GTK_IS_CELL_AREA_BOX (area));
776   g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
777
778   g_object_ref_sink (c);
779   g_object_unref (c);
780 }
781
782 /* test we get a warning if an area is provided, but ignored */
783 static void
784 test_completion_subclass3 (void)
785 {
786   subclass_init = 1;
787
788   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
789     {
790       GtkEntryCompletion *c;
791       GtkCellArea *area;
792
793       area = gtk_cell_area_box_new ();
794       c = g_object_new (my_entry_completion_get_type (), "cell-area", area, NULL);
795       g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)));
796       g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
797
798       g_object_ref_sink (c);
799       g_object_unref (c);
800
801       exit (0);
802     }
803   g_test_trap_assert_failed ();
804   g_test_trap_assert_stderr ("*ignoring construct property*");
805 }
806
807 int
808 main (int argc, char *argv[])
809 {
810   gtk_test_init (&argc, &argv);
811   g_test_bug_base ("http://bugzilla.gnome.org/");
812   gtk_test_register_all_types();
813
814   g_test_add_func ("/tests/iconview-new", test_iconview_new);
815   g_test_add_func ("/tests/iconview-new-with-area", test_iconview_new_with_area);
816   g_test_add_func ("/tests/iconview-object-new", test_iconview_object_new);
817   g_test_add_func ("/tests/iconview-subclass0", test_iconview_subclass0);
818   g_test_add_func ("/tests/iconview-subclass1", test_iconview_subclass1);
819   g_test_add_func ("/tests/iconview-subclass2", test_iconview_subclass2);
820   g_test_add_func ("/tests/iconview-subclass3", test_iconview_subclass3);
821
822   g_test_add_func ("/tests/combobox-new", test_combobox_new);
823   g_test_add_func ("/tests/combobox-new-with-area", test_combobox_new_with_area);
824   g_test_add_func ("/tests/combobox-object-new", test_combobox_object_new);
825   g_test_add_func ("/tests/combobox-subclass0", test_combobox_subclass0);
826   g_test_add_func ("/tests/combobox-subclass1", test_combobox_subclass1);
827   g_test_add_func ("/tests/combobox-subclass2", test_combobox_subclass2);
828   g_test_add_func ("/tests/combobox-subclass3", test_combobox_subclass3);
829
830   g_test_add_func ("/tests/cellview-new", test_cellview_new);
831   g_test_add_func ("/tests/cellview-new-with-context", test_cellview_new_with_context);
832   g_test_add_func ("/tests/cellview-object-new", test_cellview_object_new);
833   g_test_add_func ("/tests/cellview-subclass0", test_cellview_subclass0);
834   g_test_add_func ("/tests/cellview-subclass1", test_cellview_subclass1);
835   g_test_add_func ("/tests/cellview-subclass2", test_cellview_subclass2);
836   g_test_add_func ("/tests/cellview-subclass3", test_cellview_subclass3);
837
838   g_test_add_func ("/tests/column-new", test_column_new);
839   g_test_add_func ("/tests/column-new-with-area", test_column_new_with_area);
840   g_test_add_func ("/tests/column-object-new", test_column_object_new);
841   g_test_add_func ("/tests/column-subclass0", test_column_subclass0);
842   g_test_add_func ("/tests/column-subclass1", test_column_subclass1);
843   g_test_add_func ("/tests/column-subclass2", test_column_subclass2);
844   g_test_add_func ("/tests/column-subclass3", test_column_subclass3);
845
846   g_test_add_func ("/tests/completion-new", test_completion_new);
847   g_test_add_func ("/tests/completion-new-with-area", test_completion_new_with_area);
848   g_test_add_func ("/tests/completion-object-new", test_completion_object_new);
849   g_test_add_func ("/tests/completion-subclass0", test_completion_subclass0);
850   g_test_add_func ("/tests/completion-subclass1", test_completion_subclass1);
851   g_test_add_func ("/tests/completion-subclass2", test_completion_subclass2);
852   g_test_add_func ("/tests/completion-subclass3", test_completion_subclass3);
853
854   return g_test_run();
855 }