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
|
#
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkImage.t,v 1.7 2005/09/18 15:07:22 kaffeetisch Exp $
#
#########################
# GtkImage Tests
# - rm
#########################
use Data::Dumper;
use Gtk2::TestHelper tests => 45;
# get some things ready to use below ###########################################
# borrowed from xsane-icons.c
my @pixbuf_data =
(
" 20 20 4 1",
" none",
". c #000000",
"+ c #208020",
"a c #ffffff",
" ",
" ................. ",
" .+++++++++++++++. ",
" .+ . +. ",
" .+ ... +. ",
" .+ . . . +. ",
" .+ . +. ",
" .+ . +. ",
" .+ . . . +. ",
" .+ . . . +. ",
" .+.............+. ",
" .+ . . . +. ",
" .+ . . . +. ",
" .+ . +. ",
" .+ . . . +. ",
" .+ ... +. ",
" .+ . +. ",
" .+++++++++++++++. ",
" ................. ",
" ",
);
my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_xpm_data (@pixbuf_data);
my ($pixmap, $mask) = $pixbuf->render_pixmap_and_mask (255);
my $iconset = Gtk2::IconSet->new_from_pixbuf ($pixbuf);
# Plain old new ################################################################
ok (my $img = Gtk2::Image->new, 'Gtk2::Image->new');
ok (eq_array ([$img->get_icon_set], [undef, 'button']), 'get_icon_set empty');
is ($img->get_image, undef, 'get_image empty');
is ($img->get_pixbuf, undef, 'get_pixbuf empty');
is ($img->get_pixmap, undef, 'get_pixmap empty');
ok (eq_array ([$img->get_stock ()], [undef, 'button']), 'get_stock empty');
is ($img->get_animation, undef, 'get_animation empty');
is ($img->get_storage_type, 'empty', 'get_storage_type empty');
# new from stock ###############################################################
ok ($img = Gtk2::Image->new_from_stock ('gtk-cancel', 'menu'),
'Gtk2::Image->new_from_stock');
is ($img->get_storage_type, 'stock', 'new_from_stock get_storage_type');
ok (eq_array ([$img->get_stock ()], ['gtk-cancel', 'menu']),
'new_from_stock get_stock');
# new from icon set ############################################################
ok ($img = Gtk2::Image->new_from_icon_set ($iconset, 'small-toolbar'),
'Gtk2::Image->new_from_icon_set');
my @ret = $img->get_icon_set;
is (scalar (@ret), 2, 'new_from_icon_set get_icon_set num rets');
isa_ok ($ret[0], 'Gtk2::IconSet', 'new_from_icon_set get_icon_set icon_set');
is ($ret[1], 'small-toolbar', 'new_from_icon_set get_icon_set size');
# new from image ###############################################################
ok ($img = Gtk2::Image->new_from_image (undef, undef),
'Gtk2::Image->new_from_pixbuf undef');
is ($img->get_image, undef, 'new_from_image get_image empty');
# TODO: from a valid image
# new from pixbuf ##############################################################
ok ($img = Gtk2::Image->new_from_pixbuf ($pixbuf),
'Gtk2::Image->new_from_pixbuf');
isa_ok ($img->get_pixbuf, 'Gtk2::Gdk::Pixbuf', 'new_from_pixbuf get_pixbuf');
# new from pixmap ##############################################################
ok ($img = Gtk2::Image->new_from_pixmap (undef, undef),
'Gtk2::Image->new_from_pixbuf');
ok ($img = Gtk2::Image->new_from_pixmap ($pixmap, $mask),
'Gtk2::Image->new_from_pixbuf');
@ret = $img->get_pixmap;
is (scalar(@ret), 2, 'new_from_pixmap get_pixmap num rets');
isa_ok ($ret[0], 'Gtk2::Gdk::Pixmap', 'new_from_pixmap get_pixbuf pixmap');
isa_ok ($ret[1], 'Gtk2::Gdk::Bitmap', 'new_from_pixmap get_pixbuf mask');
# set from stock ###############################################################
$img->set_from_stock ('gtk-quit', 'dialog');
is ($img->get_storage_type, 'stock', 'set_from_stock get_storage_type');
ok (eq_array ([$img->get_stock ()], ['gtk-quit', 'dialog']),
'set_from_stock get_stock');
# set from icon set ############################################################
$img->set_from_icon_set ($iconset, 'small-toolbar');
@ret = $img->get_icon_set;
is (scalar (@ret), 2, 'set_from_icon_set get_icon_set num rets');
isa_ok ($ret[0], 'Gtk2::IconSet', 'set_from_icon_set get_icon_set icon_set');
is ($ret[1], 'small-toolbar', 'set_from_icon_set get_icon_set size');
# set from image ###############################################################
$img->set_from_image (undef, undef);
is ($img->get_image, undef, 'set_from_image get_image empty');
# TODO: from a valid image
# set from pixbuf ##############################################################
$img->set_from_pixbuf (undef);
$img->set_from_pixbuf ($pixbuf);
isa_ok ($img->get_pixbuf, 'Gtk2::Gdk::Pixbuf', 'set_from_pixbuf get_pixbuf');
# set from pixmap ##############################################################
$img->set_from_pixmap (undef, undef);
$img->set_from_pixmap ($pixmap, $mask);
@ret = $img->get_pixmap;
is (scalar(@ret), 2, 'set_from_pixmap get_pixmap num rets');
isa_ok ($ret[0], 'Gtk2::Gdk::Pixmap', 'set_from_pixmap get_pixbuf pixmap');
isa_ok ($ret[1], 'Gtk2::Gdk::Bitmap', 'set_from_pixmap get_pixbuf mask');
# These require access to a file, so they may be skipped
my $testfile = './gtk-demo/gnome-foot.png';
SKIP:
{
skip "unable to find test file, $testfile", 1
unless (-R $testfile);
my $animation = Gtk2::Gdk::PixbufAnimation->new_from_file ($testfile);
# new from file ################################################################
ok ($img = Gtk2::Image->new_from_file (undef),
'Gtk2::Image->new_from_file undef');
ok ($img = Gtk2::Image->new_from_file ($testfile),
'Gtk2::Image->new_from_file');
isa_ok ($img->get_pixbuf, 'Gtk2::Gdk::Pixbuf',
'new_from_file get_pixbuf');
# new from animation ###########################################################
ok ($img = Gtk2::Image->new_from_animation ($animation),
'Gtk2::Image->new_from_animation');
isa_ok ($img->get_animation, 'Gtk2::Gdk::PixbufAnimation',
'new_from_animation get_animationf');
# set from file ################################################################
$img->set_from_file (undef);
$img->set_from_file ($testfile);
isa_ok ($img->get_pixbuf, 'Gtk2::Gdk::Pixbuf',
'set_from_file get_pixbuf');
# set from animation ###########################################################
$img->set_from_animation ($animation);
isa_ok ($img->get_animation, 'Gtk2::Gdk::PixbufAnimation',
'set_from_animation get_animationf');
}
SKIP: {
skip 'new stuff in 2.6', 4
unless Gtk2->CHECK_VERSION (2, 6, 0);
$img = Gtk2::Image->new_from_icon_name ('gtk-ok', 'button');
isa_ok ($img, 'Gtk2::Image');
is_deeply ([$img->get_icon_name], ['gtk-ok', 'button']);
$img->set_from_icon_name ('gtk-cancel', 'menu');
is_deeply ([$img->get_icon_name], ['gtk-cancel', 'menu']);
$img->set_pixel_size (23);
is ($img->get_pixel_size, 23);
}
SKIP: {
skip 'new stuff in 2.8', 0
unless Gtk2->CHECK_VERSION (2, 8, 0);
$img->clear;
}
__END__
Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the
full list). See LICENSE for more information.
|