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
|
use warnings;
use strict;
use Test::More tests => 23;
use Glib qw(TRUE FALSE); # To get TRUE and FALSE
use Gtk3 -init;
BEGIN {
use_ok('Gscan2pdf::Dialog::MultipleMessage');
}
#########################
Gscan2pdf::Translation::set_domain('gscan2pdf');
my $window = Gtk3::Window->new;
ok(
my $dialog = Gscan2pdf::Dialog::MultipleMessage->new(
title => 'title',
'transient-for' => $window
),
'Created dialog'
);
isa_ok( $dialog, 'Gscan2pdf::Dialog::MultipleMessage' );
$dialog->add_row(
page => 1,
process => 'scan',
type => 'error',
text => 'message',
'store-response' => TRUE
);
is( $dialog->{grid_rows}, 2, '1 message' );
$dialog->add_row(
page => 2,
process => 'scan',
type => 'warning',
text => 'message2'
);
is( $dialog->{grid_rows}, 3, '2 messages' );
$dialog->{cb}->set_active(TRUE);
is_deeply( [ $dialog->list_messages_to_ignore('ok') ],
['message'], 'list_messages_to_ignore' );
$dialog->add_row(
page => 1,
process => 'scan',
type => 'error',
text => "my message3\n",
'store-response' => TRUE
);
is( $dialog->{cb}->get_inconsistent, TRUE, 'inconsistent if states different' );
$dialog->{cb}->set_active(FALSE);
$dialog->{cb}->set_active(TRUE);
is_deeply(
[ $dialog->list_messages_to_ignore('ok') ],
[ 'message', 'my message3' ],
'chop trailing whitespace'
);
$dialog = Gscan2pdf::Dialog::MultipleMessage->new(
title => 'title',
'transient-for' => $window
),
$dialog->add_message(
page => 1,
process => 'scan',
type => 'error',
text =>
'[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.',
);
is( $dialog->{grid_rows}, 2, 'add_message single message' );
my $responses = {};
$dialog = Gscan2pdf::Dialog::MultipleMessage->new(
title => 'title',
'transient-for' => $window
),
$dialog->add_message(
page => 1,
process => 'scan',
type => 'error',
'store-response' => TRUE,
responses => $responses,
text => <<'EOS',
[image2 @ 0xc596e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.
EOS
);
is( $dialog->{grid_rows}, 3, 'add_message added 2 messages' );
$dialog->{grid}->get_child_at( 4, 1 )->set_active(TRUE);
is( $dialog->{cb}->get_inconsistent, TRUE, 'inconsistent if states different' );
$dialog->{grid}->get_child_at( 4, 2 )->set_active(TRUE);
$dialog->store_responses( 'ok', $responses );
is( scalar keys %{$responses}, 2, 'stored 2 responses' );
is( $dialog->{cb}->get_inconsistent, FALSE, 'consistent as states same' );
$dialog = Gscan2pdf::Dialog::MultipleMessage->new(
title => 'title',
'transient-for' => $window
),
$dialog->add_message(
page => 1,
process => 'scan',
type => 'error',
'store-response' => TRUE,
responses => $responses,
text => <<'EOS',
[image2 @ 0xc596e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.
EOS
);
is( $dialog->{grid_rows}, 1, 'add_message added no messages' );
is_deeply(
Gscan2pdf::Dialog::MultipleMessage::munge_message(
<<'EOS',
(gimp:26514): GLib-GObject-WARNING : g_object_set_valist: object class 'GeglConfig' has no property named 'cache-size'
(gimp:26514): GEGL-gegl-operation.c-WARNING : Cannot change name of operation class 0xE0FD30 from "gimp:point-layer-mode" to "gimp:dissolve-mode"
EOS
),
[
"(gimp:26514): GLib-GObject-WARNING : g_object_set_valist: object class 'GeglConfig' has no property named 'cache-size'",
'(gimp:26514): GEGL-gegl-operation.c-WARNING : Cannot change name of operation class 0xE0FD30 from "gimp:point-layer-mode" to "gimp:dissolve-mode"'
],
'split gimp messages'
);
is_deeply(
Gscan2pdf::Dialog::MultipleMessage::munge_message(
<<'EOS',
[image2 @ 0xc596e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.
EOS
),
[
'[image2 @ 0xc596e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.',
'[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.'
],
'split unpaper messages'
);
my $expected = <<'EOS';
Exception 400: memory allocation failed
This error is normally due to ImageMagick exceeding its resource limits. These can be extended by editing its policy file, which on my system is found at /etc/ImageMagick-6/policy.xml Please see https://imagemagick.org/script/resources.php for more information
EOS
chomp $expected;
is_deeply(
Gscan2pdf::Dialog::MultipleMessage::munge_message(
'Exception 400: memory allocation failed'),
$expected,
'extend imagemagick Exception 400'
);
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(
'[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.'
),
'[image2 @ %%x] Encoder did not produce proper pts, making some up.',
'Filter out memory address from unpaper warning'
);
$expected = <<'EOS';
[image2 @ %%x] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[image2 @ %%x] Encoder did not produce proper pts, making some up.
EOS
chomp $expected;
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(<<'EOS'),
[image2 @ 0xc596e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[image2 @ 0x1338180] Encoder did not produce proper pts, making some up.
EOS
$expected, 'Filter out double memory address from unpaper warning'
);
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(
'Error processing with tesseract: Detected 440 diacritics'),
'Error processing with tesseract: Detected %%d diacritics',
'Filter out integer from tesseract warning'
);
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(
'Error processing with tesseract: Warning. Invalid resolution 0 dpi. Using 70 instead.'
),
'Error processing with tesseract: Warning. Invalid resolution %%d dpi. Using %%d instead.',
'Filter out 1 and 2 digit integers from tesseract warning'
);
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(
"[image2 @ 0x1338180] Encoder did not produce proper pts, making some up. \n "
),
'[image2 @ %%x] Encoder did not produce proper pts, making some up.',
'Filter out trailing whitespace'
);
is(
Gscan2pdf::Dialog::MultipleMessage::filter_message(
"[image2 @ 0x56054e417040] The specified filename '/tmp/gscan2pdf-ldks/OHSk_wKy5v.pnm' does not contain an image sequence pattern or a pattern is invalid."
),
"[image2 @ %%x] The specified filename '/tmp/%%t.pnm' does not contain an image sequence pattern or a pattern is invalid.",
'Filter out temporary filename from unpaper warning'
);
__END__
|