File: GtkIconView.t

package info (click to toggle)
libgtk2-perl 1%3A1.140-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,808 kB
  • ctags: 609
  • sloc: perl: 14,245; ansic: 118; makefile: 70
file content (222 lines) | stat: -rw-r--r-- 5,848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkIconView.t,v 1.13 2006/01/18 19:04:10 kaffeetisch Exp $
#

#########################
# GtkIconView Tests
# 	- rm
#########################

#########################

use strict;
use warnings;

use Gtk2::TestHelper tests => 53,
    at_least_version => [2, 6, 0, "GtkIconView is new in 2.6"],
    ;

use constant TEXT => 0;
use constant PIXBUF => 1;
use constant BOOLEAN => 2;

my $win = Gtk2::Window->new;
#my $swin = Gtk2::ScrolledWindow->new;
#$win->add ($swin);

my $model = create_store ();

isa_ok (my $iview = Gtk2::IconView->new, 'Gtk2::IconView',
	'Gtk2::IconView->new');
ginterfaces_ok($iview);

is ($iview->get_model, undef, '$iview->get_model, undef');
$iview->set_model ($model);
is ($iview->get_model, $model, '$iview->set|get_model');

isa_ok ($iview = Gtk2::IconView->new_with_model ($model), 'Gtk2::IconView',
	'Gtk2::IconView->new');
#$swin->add ($iview);
is ($iview->get_model, $model, '$iview->get_model, new_with_model');

fill_store ($model, get_pixbufs ($win));

is ($iview->get_text_column, -1, '$iview->get_text_column, undef');
$iview->set_text_column (TEXT);
is ($iview->get_text_column, TEXT, '$iview->set|get_text_column');

is ($iview->get_pixbuf_column, -1, '$iview->get_pixbuf_column, undef');
$iview->set_pixbuf_column (PIXBUF);
is ($iview->get_pixbuf_column, PIXBUF, '$iview->set|get_pixbuf_column');

is ($iview->get_markup_column, -1, '$iview->get_markup_column, undef');
$iview->set_markup_column (TEXT);
is ($iview->get_markup_column, TEXT, '$iview->set|get_markup_column');

foreach (qw/horizontal vertical/)
{
	$iview->set_orientation ($_);
	is ($iview->get_orientation, $_, '$iview->set|get_orienation, '.$_);
}

# extended should be in this list, but it seems to fail
foreach (qw/none single browse multiple/)
{
	$iview->set_selection_mode ($_);
	is ($iview->get_selection_mode, $_,
	    '$iview->set|get_selection_mode '.$_);
}

$iview->set_columns (23);
is ($iview->get_columns, 23);

$iview->set_item_width (23);
is ($iview->get_item_width, 23);

$iview->set_spacing (23),
is ($iview->get_spacing, 23);

$iview->set_row_spacing (23);
is ($iview->get_row_spacing, 23);

$iview->set_column_spacing (23);
is ($iview->get_column_spacing, 23);

$iview->set_margin (23);
is ($iview->get_margin, 23);

#$win->show_all;

run_main sub {
	# this stuff is liable to be flaky, it may require TODO's
	my $path = $iview->get_path_at_pos (50, 50);
	isa_ok ($path, 'Gtk2::TreePath', '$iview->get_path_at_pos (50, 50)');

	is ($iview->path_is_selected ($path), '',
	    '$iview->path_is_selected, no');
	$iview->select_path ($path);
	is ($iview->path_is_selected ($path), 1,
	    '$iview->path_is_selected, yes');
	$iview->unselect_path ($path);
	is ($iview->path_is_selected ($path), '',
	    '$iview->path_is_selected, no');

	$iview->item_activated ($path);

	my @sels = $iview->get_selected_items;
	is (scalar (@sels), 0, '$iview->get_selected_items, count 0');

	$iview->select_all;
	@sels = $iview->get_selected_items;
	is (scalar (@sels), 14, '$iview->get_selected_items, count 14');
	isa_ok ($sels[0], 'Gtk2::TreePath', '$iview->get_selected_items, type');

	$iview->unselect_all;
	@sels = $iview->get_selected_items;
	is (scalar (@sels), 0, '$iview->get_selected_items, count 0');

	$iview->select_path ($path);
	$iview->selected_foreach (sub {
		my ($view, $path, $data) = @_;
		isa_ok ($view, 'Gtk2::IconView');
		isa_ok ($path, 'Gtk2::TreePath');
		isa_ok ($data, 'HASH');
		is ($data->{foo}, 'bar', 'callback data intact');
	}, { foo => 'bar' });
	$iview->select_all;
	my $ncalls = 0;
	$iview->selected_foreach (sub { $ncalls++ });
	my @selected_items = $iview->get_selected_items;
	is ($ncalls, scalar(@selected_items),
	    'called once for each selected child');

	SKIP: {
		skip 'new 2.8 stuff', 16
			unless Gtk2->CHECK_VERSION (2, 8, 0);

		$win->add ($iview);
		$win->show_all;

		my ($path, $cell) = $iview->get_item_at_pos (50, 50);
		isa_ok ($path, "Gtk2::TreePath");
		isa_ok ($cell, "Gtk2::CellRenderer");

		$iview->set_cursor ($path, undef, FALSE);
		my @tmp = $iview->get_cursor;
		is (@tmp, 2);
		isa_ok ($tmp[0], "Gtk2::TreePath");
		is ($tmp[1], undef);

		$iview->set_cursor ($path, $cell, TRUE);
		@tmp = $iview->get_cursor;
		is (@tmp, 2);
		isa_ok ($tmp[0], "Gtk2::TreePath");
		is ($tmp[1], $cell);

		@tmp = $iview->get_visible_range;
		isa_ok ($tmp[0], "Gtk2::TreePath");
		isa_ok ($tmp[1], "Gtk2::TreePath");

		$iview->scroll_to_path ($path, TRUE, 0.5, 0.5);

		$iview->enable_model_drag_source ([qw/shift-mask/], "copy",
		  { target => "STRING", flags => ["same-app", "same-widget"], info => 42 });
		$iview->enable_model_drag_dest ("copy",
		  { target => "STRING", flags => ["same-app", "same-widget"], info => 42 });

		$iview->unset_model_drag_source;
		$iview->unset_model_drag_dest;

		$iview->set_reorderable (TRUE);
		ok ($iview->get_reorderable);

		$iview->set_drag_dest_item ($path, "drop-into");
		@tmp = $iview->get_drag_dest_item;
		isa_ok ($tmp[0], "Gtk2::TreePath");
		is ($tmp[1], "drop-into");

		my ($tmp_path, $pos) = $iview->get_dest_item_at_pos (50, 50);
		isa_ok ($tmp_path, "Gtk2::TreePath");
		like ($pos, qr/drop/);

		isa_ok ($iview->create_drag_icon ($path), "Gtk2::Gdk::Pixmap");
	}
};

sub create_store
{
	my $store = Gtk2::ListStore->new (qw/Glib::String Gtk2::Gdk::Pixbuf
					     Glib::Boolean/);
	return $store;
}

sub get_pixbufs
{
	my $win = shift;

	my @pbs;

	foreach (qw/gtk-ok gtk-cancel gtk-about gtk-quit/)
	{
		push @pbs, $win->render_icon ($_, 'dialog');
	}

	return \@pbs;
}

sub fill_store
{
	my $store = shift;
	my $pbs = shift;

	foreach (qw/one two three four five six seven eight nine uno dos
		    tres quatro cinco/)
	{
		my $iter = $store->append;
		$store->set ($iter,
			     TEXT, "$_",
			     PIXBUF, $pbs->[rand (@$pbs)],
			     BOOLEAN, rand (2),
		     );
	}
}