Debian Codegraph @

testsuite/gtk/cellarea.c

raw
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 static void
165 test_iconview_subclass3_subprocess (void)
166 {
167 GtkWidget *view;
168 GtkCellArea *area;
169
170 subclass_init = 1;
171
172 area = gtk_cell_area_box_new ();
173 view = g_object_new (my_icon_view_get_type (), "cell-area", area, NULL);
174 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
175 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
176 g_object_ref_sink (view);
177 g_object_unref (view);
178 }
179
180 /* test we get a warning if an area is provided, but ignored */
181 static void
182 test_iconview_subclass3 (void)
183 {
184 g_test_trap_subprocess ("/tests/iconview-subclass3/subprocess", 0, 0);
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 static void
321 test_combobox_subclass3_subprocess (void)
322 {
323 GtkWidget *view;
324 GtkCellArea *area;
325
326 subclass_init = 1;
327
328 area = gtk_cell_area_box_new ();
329 view = g_object_new (my_combo_box_get_type (), "cell-area", area, NULL);
330 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
331 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
332
333 g_object_ref_sink (view);
334 g_object_unref (view);
335 }
336
337 /* test we get a warning if an area is provided, but ignored */
338 static void
339 test_combobox_subclass3 (void)
340 {
341 g_test_trap_subprocess ("/tests/combobox-subclass3/subprocess", 0, 0);
342 g_test_trap_assert_failed ();
343 g_test_trap_assert_stderr ("*ignoring construct property*");
344 }
345
346 /* test that we have a cell area after new() */
347 static void
348 test_cellview_new (void)
349 {
350 GtkWidget *view;
351 GtkCellArea *area;
352
353 view = gtk_cell_view_new ();
354
355 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
356 g_assert (GTK_IS_CELL_AREA_BOX (area));
357
358 g_object_ref_sink (view);
359 g_object_unref (view);
360 }
361
362 /* test that new_with_context() keeps the provided area */
363 static void
364 test_cellview_new_with_context (void)
365 {
366 GtkWidget *view;
367 GtkCellArea *area;
368 GtkCellAreaContext *context;
369
370 area = gtk_cell_area_box_new ();
371 context = gtk_cell_area_create_context (area);
372 view = gtk_cell_view_new_with_context (area, context);
373 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
374
375 g_object_ref_sink (view);
376 g_object_unref (view);
377 }
378
379 /* test that g_object_new keeps the provided area */
380 static void
381 test_cellview_object_new (void)
382 {
383 GtkWidget *view;
384 GtkCellArea *area;
385
386 area = gtk_cell_area_box_new ();
387 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
388 view = g_object_new (GTK_TYPE_CELL_VIEW, "cell-area", area, NULL);
389 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)) == area);
390
391 g_object_ref_sink (view);
392 g_object_unref (view);
393 }
394
395 typedef GtkCellView MyCellView;
396 typedef GtkCellViewClass MyCellViewClass;
397
398 GType my_cell_view_get_type (void);
399
400 G_DEFINE_TYPE (MyCellView, my_cell_view, GTK_TYPE_CELL_VIEW)
401
402 static void
403 my_cell_view_class_init (MyCellViewClass *klass)
404 {
405 }
406
407 static void
408 my_cell_view_init (MyCellView *view)
409 {
410 GtkCellArea *area;
411
412 if (subclass_init == 0)
413 {
414 /* do nothing to area */
415 }
416 else if (subclass_init == 1)
417 {
418 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
419 g_assert (GTK_IS_CELL_AREA_BOX (area));
420 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
421 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
422 }
423 }
424
425 /* test that a cellview subclass has an area */
426 static void
427 test_cellview_subclass0 (void)
428 {
429 GtkWidget *view;
430 GtkCellArea *area;
431
432 subclass_init = 0;
433
434 view = g_object_new (my_cell_view_get_type (), NULL);
435 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
436 g_assert (GTK_IS_CELL_AREA_BOX (area));
437 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
438
439 g_object_ref_sink (view);
440 g_object_unref (view);
441 }
442
443 /* test that a cellview subclass keeps the provided area */
444 static void
445 test_cellview_subclass1 (void)
446 {
447 GtkWidget *view;
448 GtkCellArea *area;
449
450 subclass_init = 0;
451
452 area = gtk_cell_area_box_new ();
453 view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
454 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
455 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
456
457 g_object_ref_sink (view);
458 g_object_unref (view);
459 }
460
461 /* test we can access the area in subclass init */
462 static void
463 test_cellview_subclass2 (void)
464 {
465 GtkWidget *view;
466 GtkCellArea *area;
467
468 subclass_init = 1;
469
470 view = g_object_new (my_cell_view_get_type (), NULL);
471 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view));
472 g_assert (GTK_IS_CELL_AREA_BOX (area));
473 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
474
475 g_object_ref_sink (view);
476 g_object_unref (view);
477 }
478
479 static void
480 test_cellview_subclass3_subprocess (void)
481 {
482 GtkWidget *view;
483 GtkCellArea *area;
484
485 subclass_init = 1;
486
487 area = gtk_cell_area_box_new ();
488 view = g_object_new (my_cell_view_get_type (), "cell-area", area, NULL);
489 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (view)));
490 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
491
492 g_object_ref_sink (view);
493 g_object_unref (view);
494 }
495
496 /* test we get a warning if an area is provided, but ignored */
497 static void
498 test_cellview_subclass3 (void)
499 {
500 g_test_trap_subprocess ("/tests/cellview-subclass3/subprocess", 0, 0);
501 g_test_trap_assert_failed ();
502 g_test_trap_assert_stderr ("*ignoring construct property*");
503 }
504
505 /* test that we have a cell area after new() */
506 static void
507 test_column_new (void)
508 {
509 GtkTreeViewColumn *col;
510 GtkCellArea *area;
511
512 col = gtk_tree_view_column_new ();
513
514 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
515 g_assert (GTK_IS_CELL_AREA_BOX (area));
516
517 g_object_ref_sink (col);
518 g_object_unref (col);
519 }
520
521 /* test that new_with_area() keeps the provided area */
522 static void
523 test_column_new_with_area (void)
524 {
525 GtkTreeViewColumn *col;
526 GtkCellArea *area;
527
528 area = gtk_cell_area_box_new ();
529 col = gtk_tree_view_column_new_with_area (area);
530 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
531
532 g_object_ref_sink (col);
533 g_object_unref (col);
534 }
535
536 /* test that g_object_new keeps the provided area */
537 static void
538 test_column_object_new (void)
539 {
540 GtkTreeViewColumn *col;
541 GtkCellArea *area;
542
543 area = gtk_cell_area_box_new ();
544 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
545 col = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, "cell-area", area, NULL);
546 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)) == area);
547
548 g_object_ref_sink (col);
549 g_object_unref (col);
550 }
551
552 typedef GtkTreeViewColumn MyTreeViewColumn;
553 typedef GtkTreeViewColumnClass MyTreeViewColumnClass;
554
555 GType my_tree_view_column_get_type (void);
556
557 G_DEFINE_TYPE (MyTreeViewColumn, my_tree_view_column, GTK_TYPE_TREE_VIEW_COLUMN)
558
559 static void
560 my_tree_view_column_class_init (MyTreeViewColumnClass *klass)
561 {
562 }
563
564 static void
565 my_tree_view_column_init (MyTreeViewColumn *col)
566 {
567 GtkCellArea *area;
568
569 if (subclass_init == 0)
570 {
571 /* do nothing to area */
572 }
573 else if (subclass_init == 1)
574 {
575 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
576 g_assert (GTK_IS_CELL_AREA_BOX (area));
577 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
578 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
579 }
580 }
581
582 /* test that a column subclass has an area */
583 static void
584 test_column_subclass0 (void)
585 {
586 GtkTreeViewColumn *col;
587 GtkCellArea *area;
588
589 subclass_init = 0;
590
591 col = g_object_new (my_tree_view_column_get_type (), NULL);
592 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
593 g_assert (GTK_IS_CELL_AREA_BOX (area));
594 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
595
596 g_object_ref_sink (col);
597 g_object_unref (col);
598 }
599
600 /* test that a column subclass keeps the provided area */
601 static void
602 test_column_subclass1 (void)
603 {
604 GtkTreeViewColumn *col;
605 GtkCellArea *area;
606
607 subclass_init = 0;
608
609 area = gtk_cell_area_box_new ();
610 col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
611 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
612 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
613
614 g_object_ref_sink (col);
615 g_object_unref (col);
616 }
617
618 /* test we can access the area in subclass init */
619 static void
620 test_column_subclass2 (void)
621 {
622 GtkTreeViewColumn *col;
623 GtkCellArea *area;
624
625 subclass_init = 1;
626
627 col = g_object_new (my_tree_view_column_get_type (), NULL);
628 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col));
629 g_assert (GTK_IS_CELL_AREA_BOX (area));
630 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
631
632 g_object_ref_sink (col);
633 g_object_unref (col);
634 }
635
636 static void
637 test_column_subclass3_subprocess (void)
638 {
639 GtkTreeViewColumn *col;
640 GtkCellArea *area;
641
642 subclass_init = 1;
643
644 area = gtk_cell_area_box_new ();
645 col = g_object_new (my_tree_view_column_get_type (), "cell-area", area, NULL);
646 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (col)));
647 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
648
649 g_object_ref_sink (col);
650 g_object_unref (col);
651 }
652
653 /* test we get a warning if an area is provided, but ignored */
654 static void
655 test_column_subclass3 (void)
656 {
657 g_test_trap_subprocess ("/tests/column-subclass3/subprocess", 0, 0);
658 g_test_trap_assert_failed ();
659 g_test_trap_assert_stderr ("*ignoring construct property*");
660 }
661
662 /* test that we have a cell area after new() */
663 static void
664 test_completion_new (void)
665 {
666 GtkEntryCompletion *c;
667 GtkCellArea *area;
668
669 c = gtk_entry_completion_new ();
670
671 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
672 g_assert (GTK_IS_CELL_AREA_BOX (area));
673
674 g_object_ref_sink (c);
675 g_object_unref (c);
676 }
677
678 /* test that new_with_area() keeps the provided area */
679 static void
680 test_completion_new_with_area (void)
681 {
682 GtkEntryCompletion *c;
683 GtkCellArea *area;
684
685 area = gtk_cell_area_box_new ();
686 c = gtk_entry_completion_new_with_area (area);
687 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
688
689 g_object_ref_sink (c);
690 g_object_unref (c);
691 }
692
693 /* test that g_object_new keeps the provided area */
694 static void
695 test_completion_object_new (void)
696 {
697 GtkEntryCompletion *c;
698 GtkCellArea *area;
699
700 area = gtk_cell_area_box_new ();
701 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
702 c = g_object_new (GTK_TYPE_ENTRY_COMPLETION, "cell-area", area, NULL);
703 g_assert (gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)) == area);
704
705 g_object_ref_sink (c);
706 g_object_unref (c);
707 }
708
709 typedef GtkEntryCompletion MyEntryCompletion;
710 typedef GtkEntryCompletionClass MyEntryCompletionClass;
711
712 GType my_entry_completion_get_type (void);
713
714 G_DEFINE_TYPE (MyEntryCompletion, my_entry_completion, GTK_TYPE_ENTRY_COMPLETION)
715
716 static void
717 my_entry_completion_class_init (MyEntryCompletionClass *klass)
718 {
719 }
720
721 static void
722 my_entry_completion_init (MyEntryCompletion *c)
723 {
724 GtkCellArea *area;
725
726 if (subclass_init == 0)
727 {
728 /* do nothing to area */
729 }
730 else if (subclass_init == 1)
731 {
732 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
733 g_assert (GTK_IS_CELL_AREA_BOX (area));
734 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
735 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
736 }
737 }
738
739 /* test that a completion subclass has an area */
740 static void
741 test_completion_subclass0 (void)
742 {
743 GtkEntryCompletion *c;
744 GtkCellArea *area;
745
746 subclass_init = 0;
747
748 c = g_object_new (my_entry_completion_get_type (), NULL);
749 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
750 g_assert (GTK_IS_CELL_AREA_BOX (area));
751 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
752
753 g_object_ref_sink (c);
754 g_object_unref (c);
755 }
756
757 /* test that a completion subclass keeps the provided area */
758 static void
759 test_completion_subclass1 (void)
760 {
761 GtkEntryCompletion *c;
762 GtkCellArea *area;
763
764 subclass_init = 0;
765
766 area = gtk_cell_area_box_new ();
767 c = g_object_new (my_entry_completion_get_type (), "cell-area", area, NULL);
768 g_assert (area == gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c)));
769 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_HORIZONTAL);
770
771 g_object_ref_sink (c);
772 g_object_unref (c);
773 }
774
775 /* test we can access the area in subclass init */
776 static void
777 test_completion_subclass2 (void)
778 {
779 GtkEntryCompletion *c;
780 GtkCellArea *area;
781
782 subclass_init = 1;
783
784 c = g_object_new (my_entry_completion_get_type (), NULL);
785 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (c));
786 g_assert (GTK_IS_CELL_AREA_BOX (area));
787 g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (area)) == GTK_ORIENTATION_VERTICAL);
788
789 g_object_ref_sink (c);
790 g_object_unref (c);
791 }
792
793 static void
794 test_completion_subclass3_subprocess (void)
795 {
796 GtkEntryCompletion *c;
797 GtkCellArea *area;
798
799 subclass_init = 1;
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
810 /* test we get a warning if an area is provided, but ignored */
811 static void
812 test_completion_subclass3 (void)
813 {
814 g_test_trap_subprocess ("/tests/completion-subclass3/subprocess", 0, 0);
815 g_test_trap_assert_failed ();
816 g_test_trap_assert_stderr ("*ignoring construct property*");
817 }
818
819 int
820 main (int argc, char *argv[])
821 {
822 gtk_test_init (&argc, &argv);
823 g_test_bug_base ("http://bugzilla.gnome.org/");
824 gtk_test_register_all_types();
825
826 g_test_add_func ("/tests/iconview-new", test_iconview_new);
827 g_test_add_func ("/tests/iconview-new-with-area", test_iconview_new_with_area);
828 g_test_add_func ("/tests/iconview-object-new", test_iconview_object_new);
829 g_test_add_func ("/tests/iconview-subclass0", test_iconview_subclass0);
830 g_test_add_func ("/tests/iconview-subclass1", test_iconview_subclass1);
831 g_test_add_func ("/tests/iconview-subclass2", test_iconview_subclass2);
832 g_test_add_func ("/tests/iconview-subclass3", test_iconview_subclass3);
833 g_test_add_func ("/tests/iconview-subclass3/subprocess", test_iconview_subclass3_subprocess);
834
835 g_test_add_func ("/tests/combobox-new", test_combobox_new);
836 g_test_add_func ("/tests/combobox-new-with-area", test_combobox_new_with_area);
837 g_test_add_func ("/tests/combobox-object-new", test_combobox_object_new);
838 g_test_add_func ("/tests/combobox-subclass0", test_combobox_subclass0);
839 g_test_add_func ("/tests/combobox-subclass1", test_combobox_subclass1);
840 g_test_add_func ("/tests/combobox-subclass2", test_combobox_subclass2);
841 g_test_add_func ("/tests/combobox-subclass3", test_combobox_subclass3);
842 g_test_add_func ("/tests/combobox-subclass3/subprocess", test_combobox_subclass3_subprocess);
843
844 g_test_add_func ("/tests/cellview-new", test_cellview_new);
845 g_test_add_func ("/tests/cellview-new-with-context", test_cellview_new_with_context);
846 g_test_add_func ("/tests/cellview-object-new", test_cellview_object_new);
847 g_test_add_func ("/tests/cellview-subclass0", test_cellview_subclass0);
848 g_test_add_func ("/tests/cellview-subclass1", test_cellview_subclass1);
849 g_test_add_func ("/tests/cellview-subclass2", test_cellview_subclass2);
850 g_test_add_func ("/tests/cellview-subclass3", test_cellview_subclass3);
851 g_test_add_func ("/tests/cellview-subclass3/subprocess", test_cellview_subclass3_subprocess);
852
853 g_test_add_func ("/tests/column-new", test_column_new);
854 g_test_add_func ("/tests/column-new-with-area", test_column_new_with_area);
855 g_test_add_func ("/tests/column-object-new", test_column_object_new);
856 g_test_add_func ("/tests/column-subclass0", test_column_subclass0);
857 g_test_add_func ("/tests/column-subclass1", test_column_subclass1);
858 g_test_add_func ("/tests/column-subclass2", test_column_subclass2);
859 g_test_add_func ("/tests/column-subclass3", test_column_subclass3);
860 g_test_add_func ("/tests/column-subclass3/subprocess", test_column_subclass3_subprocess);
861
862 g_test_add_func ("/tests/completion-new", test_completion_new);
863 g_test_add_func ("/tests/completion-new-with-area", test_completion_new_with_area);
864 g_test_add_func ("/tests/completion-object-new", test_completion_object_new);
865 g_test_add_func ("/tests/completion-subclass0", test_completion_subclass0);
866 g_test_add_func ("/tests/completion-subclass1", test_completion_subclass1);
867 g_test_add_func ("/tests/completion-subclass2", test_completion_subclass2);
868 g_test_add_func ("/tests/completion-subclass3", test_completion_subclass3);
869 g_test_add_func ("/tests/completion-subclass3/subprocess", test_completion_subclass3_subprocess);
870
871 return g_test_run();
872 }