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
|
#
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkFileChooser.t,v 1.28 2006/01/16 21:50:28 kaffeetisch Exp $
#
use Gtk2::TestHelper
at_least_version => [2, 4, 0, 'GtkFileChooser is new in 2.4'],
tests => 43,
skip_all => 'Skipping unreliable GtkFileChooser test';
use File::Spec;
use Cwd;
sub update {
Gtk2->main_iteration while Gtk2->events_pending;
}
my $file_chooser = Gtk2::FileChooserWidget->new ('save');
isa_ok ($file_chooser, 'Gtk2::FileChooser');
is ($file_chooser->get_action, 'save', 'mode option from construction');
# Filename manipulation
#
my $filename = 'something that may not exist';
my $cwd = cwd ();
$file_chooser->set_current_name ($filename);
TODO: {
local $TODO = 'GtkFileChooser trouble';
update; is_idle (sub {$file_chooser->get_filename},
undef,
'set current name');
}
$filename = File::Spec->catfile ($cwd, 'gtk2perl.h');
ok ($file_chooser->set_filename ($filename),
'set filename to something that exists');
update; is_idle (sub {$file_chooser->get_filename},
$filename,
'set current name to something that does exist');
ok ($file_chooser->select_filename ($filename));
update; is_idle (sub {$file_chooser->get_filename},
$filename,
'select something');
my @list = $file_chooser->get_filenames;
is (scalar (@list), 1, 'selected one thing');
is ($list[0], $filename, 'selected '.$filename);
$file_chooser->select_all;
@list = $file_chooser->get_filenames;
ok (scalar (@list));
$file_chooser->unselect_all;
$filename = File::Spec->catfile ($cwd, 'nonexistent');
ok (!$file_chooser->set_current_folder ($filename),
'set_current_folder fails when the folder does not exist');
$filename = File::Spec->catfile ($cwd, 't');
ok ($file_chooser->set_current_folder ($filename));
is ($file_chooser->get_current_folder, $filename);
ok ($file_chooser->set_current_folder ($cwd));
is ($file_chooser->get_current_folder, $cwd);
# URI manipulation
#
my $uri = Glib::filename_to_uri (File::Spec->rel2abs ($0), undef);
ok ($file_chooser->set_uri ($uri));
update; is_idle (sub {$file_chooser->get_uri},
$uri,
'uri');
ok ($file_chooser->select_uri ($uri));
update; ok_idle (sub {scalar ($file_chooser->get_uris)},
'selected a uri');
$file_chooser->unselect_uri ($uri);
# need to get the file off the end for these
$uri =~ s{/GtkFileChooser.t$}{};
ok ($file_chooser->set_current_folder_uri ($uri));
is ($file_chooser->get_current_folder_uri, $uri);
# Preview widget
#
my $preview_widget = Gtk2::Frame->new ('whee');
$file_chooser->set_preview_widget ($preview_widget);
is ($file_chooser->get_preview_widget, $preview_widget);
$file_chooser->set_preview_widget_active (TRUE);
ok ($file_chooser->get_preview_widget_active);
$file_chooser->set_preview_widget_active (TRUE);
ok ($file_chooser->get_preview_widget_active);
$file_chooser->set_use_preview_label (TRUE);
is ($file_chooser->get_use_preview_label, TRUE);
$file_chooser->set_current_folder ($cwd);
$filename = File::Spec->catfile ($cwd, 'gtk2perl.h');
ok ($file_chooser->select_filename ($filename));
TODO: {
local $TODO = 'GtkFileChooser trouble';
update; run_main sub {
is ($file_chooser->get_preview_filename, $filename, 'get_preview_filename');
is ($file_chooser->get_preview_uri, 'file://'.$filename, 'get_preview_uri');
};
}
# Extra widget
#
my $extra_widget = Gtk2::Frame->new ('extra widget');
$file_chooser->set_extra_widget ($extra_widget);
is ($file_chooser->get_extra_widget, $extra_widget);
# List of user selectable filters
#
my $filter = Gtk2::FileFilter->new;
$filter->set_name ('fred');
$filter->add_mime_type ('text/plain');
$file_chooser->add_filter ($filter);
@list = $file_chooser->list_filters;
is (scalar (@list), 1, 'list_filters after adding one filter');
$file_chooser->remove_filter ($filter);
@list = $file_chooser->list_filters;
is (scalar (@list), 0, 'list_filters after removing one filter');
# Current filter
#
$file_chooser->set_filter ($filter);
is ($filter, $file_chooser->get_filter);
# Per-application shortcut folders
#
eval {
$file_chooser->add_shortcut_folder ($cwd);
$file_chooser->add_shortcut_folder_uri ("file://$cwd/t");
TODO: {
local $TODO = 'GtkFileChooser trouble';
update; run_main sub {
is_deeply ([$file_chooser->list_shortcut_folders], [$cwd, "$cwd/t"]);
is_deeply ([$file_chooser->list_shortcut_folder_uris], ["file://$cwd", "file://$cwd/t"]);
};
}
$file_chooser->remove_shortcut_folder ($cwd);
$file_chooser->remove_shortcut_folder_uri ("file://$cwd/t");
};
is ($@, '', 'no shortcut error');
# Options
#
$file_chooser->set_local_only (TRUE);
ok ($file_chooser->get_local_only, 'local files only');
$file_chooser->set_local_only (FALSE);
ok (!$file_chooser->get_local_only, 'not only local files');
# apparently it likes to complain about setting this back.
$file_chooser->set_select_multiple (FALSE);
ok (!$file_chooser->get_select_multiple, 'not select multiple');
$file_chooser->set_action ('open');
is ($file_chooser->get_action, 'open', 'change action to open');
$file_chooser->set_select_multiple (TRUE);
ok ($file_chooser->get_select_multiple, 'select multiple');
$file_chooser->set_select_multiple (FALSE);
ok (!$file_chooser->get_select_multiple, 'not select multiple');
SKIP: {
skip('[sg]et_show_hidden are new in 2.6', 1)
unless Gtk2->CHECK_VERSION (2, 6, 0);
$file_chooser->set_show_hidden (TRUE);
is ($file_chooser->get_show_hidden, TRUE);
}
SKIP: {
skip('new 2.8 stuff', 1)
unless Gtk2->CHECK_VERSION (2, 8, 0);
$file_chooser->set_do_overwrite_confirmation (TRUE);
is ($file_chooser->get_do_overwrite_confirmation, TRUE);
}
__END__
Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the
full list). See LICENSE for more information.
|