[gimp-perl] PF_ADJUSTMENT default handling now correct. Bug 144564
- From: Kevin Cozens <kcozens src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-perl] PF_ADJUSTMENT default handling now correct. Bug 144564
- Date: Wed, 26 Mar 2014 19:49:26 +0000 (UTC)
commit 343519403f6b4c81d656e9cee0e6e83191df1a17
Author: Ed J <m8r-35s8eo mailinator com>
Date: Sun Mar 16 19:28:57 2014 +0000
PF_ADJUSTMENT default handling now correct. Bug 144564
Gimp/Fu.pm | 19 ++++++--
t/perlplugin.t | 141 +++++++++++++++++++++++---------------------------------
2 files changed, 73 insertions(+), 87 deletions(-)
---
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index a1005b6..9610bd1 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -64,7 +64,7 @@ sub PF_TOGGLE () { Gimp::PDB_END+1 };
sub PF_SLIDER () { Gimp::PDB_END+2 };
sub PF_FONT () { Gimp::PDB_END+3 };
sub PF_SPINNER () { Gimp::PDB_END+4 };
-sub PF_ADJUSTMENT(){ Gimp::PDB_END+5 }; # compatability fix for script-fu _ONLY_
+sub PF_ADJUSTMENT(){ Gimp::PDB_END+5 }; # compatibility fix for script-fu _ONLY_
sub PF_BRUSH () { Gimp::PDB_END+6 };
sub PF_PATTERN () { Gimp::PDB_END+7 };
sub PF_GRADIENT () { Gimp::PDB_END+8 };
@@ -474,11 +474,19 @@ dialog box as a hint. The B<description> will be used as a tooltip.
See the section PARAMETER TYPES for the supported types.
+The default values have an effect when called from a menu in GIMP, and
+when the script is called from the command line. However, they have a
+limited effect when called from Gimp::Net; data types that do not have
+an "invalid" value, like text does, may not be passed as an undefined
+value; this is because while Perl can use C<undef> instead of anything,
+GIMP cannot. For instance, it is possible to pass a C<PF_STRING> as
+undef, which will then be set to the supplied default value, but not
+a C<PF_COLOR>.
+
=item the return values
This is just like the parameter array except that it describes the return
-values. Specify the type and variable name only. This argument is optional
-- if unspecified, assumes return of an image.
+values. Specify the type and variable name only. This argument is optional.
=item the features requirements
@@ -685,7 +693,10 @@ sub register($$$$$$$$$;@) {
# set default arguments
for (0..$#{$params}) {
- $_[$_]=$params->[$_]->[3] unless defined($_[$_]);
+ next if defined $_[$_];
+ my $default = $params->[$_]->[3];
+ $default = $default->[0] if $params->[$_]->[0] == PF_ADJUSTMENT;
+ $_[$_] = $default;
}
for($menupath) {
diff --git a/t/perlplugin.t b/t/perlplugin.t
index 74fbaac..d11c6ac 100644
--- a/t/perlplugin.t
+++ b/t/perlplugin.t
@@ -11,93 +11,68 @@ require 't/gimpsetup.pl';
my $plugin = "$dir/test_perl_filter";
die "write $plugin: $!" unless io($plugin)->print($Config{startperl}.<<'EOF');
+use strict;
use Gimp qw(:auto __ N_);
use Gimp::Fu;
-sub test_dies {
- my ($text) = @_;
- die $text."\n";
-}
-
-sub test_return_text {
- my ($text) = @_;
- return $text;
+sub boilerplate_params {
+ my ($testing, $menuloc) = @_;
+ (
+ ("exercise gimp-perl filter testing $testing") x 2,
+ ("boilerplate id") x 2,
+ "20140310",
+ N_$menuloc,
+ "*",
+ );
}
-sub test_return_colour {
- my ($colour) = @_;
- return $colour;
-}
-
-# returns a value despite such not being declared
-# previously, excess returns were a fatal error, but none were ever returned
-# now not an error
-sub test_perl_filter {
- my ($i, $drawable, $text) = @_;
- my $tl = $i->text_layer_new("hi", "Arial", 8, 3);
- $i->insert_layer($tl, 0, 0);
- $tl->set_name($text);
- return $image;
-}
+# & to dodge annoying prototype preventing use of boilerplate_params!
+®ister(
+ "test_dies",
+ boilerplate_params('exceptions', '<None>'),
+ [ [PF_STRING, "text", "Input text", 'default' ], ],
+ sub { die $_[0]."\n" }
+);
-register "test_dies",
- "exercise gimp-perl filter testing exceptions",
- "exercise gimp-perl filter testing exceptions",
- "boilerplate id",
- "boilerplate id",
- "20140310",
- N_"<None>",
- "*",
- [
- [PF_STRING, "text", "Input text", 'default' ],
- ],
- [],
- \&test_dies;
+®ister(
+ "test_pf_adjustment",
+ boilerplate_params('returning text', '<None>'),
+ [ [PF_ADJUSTMENT, "input", "input", [100, 2, 1000, 1, 10, 0, 1] ], ],
+ [ [PF_INT32, "num", "Output number", ], ],
+ sub { @_ }
+);
-register "test_return_text",
- "exercise gimp-perl filter returning text",
- "exercise gimp-perl filter returning text",
- "boilerplate id",
- "boilerplate id",
- "20140310",
- N_"<None>",
- "*",
- [
- [PF_STRING, "text", "Input text", 'default' ],
- ],
- [
- [PF_STRING, "text", "Output text", ],
- ],
- \&test_return_text;
+®ister(
+ "test_return_text",
+ boilerplate_params('returning text', '<None>'),
+ [ [PF_STRING, "text", "Input text", 'default' ], ],
+ [ [PF_STRING, "text", "Output text", ], ],
+ sub { @_ }
+);
-register "test_return_colour",
- "exercise gimp-perl filter returning color",
- "exercise gimp-perl filter returning color",
- "boilerplate id",
- "boilerplate id",
- "20140310",
- N_"<None>",
- "*",
- [
- [PF_COLOR, "colour", "Input colour", [ 5, 5, 5 ], ],
- ],
- [
- [PF_COLOR, "colour", "Output colour", ],
- ],
- \&test_return_colour;
+®ister(
+ "test_return_colour",
+ boilerplate_params('returning color', '<None>'),
+ [ [PF_COLOR, "colour", "Input colour", [ 5, 5, 5 ], ], ],
+ [ [PF_COLOR, "colour", "Output colour", ], ],
+ sub { @_ }
+);
-register "test_perl_filter",
- "exercise gimp-perl for a filter",
- "exercise gimp-perl for a filter",
- "boilerplate id",
- "boilerplate id",
- "20140310",
- N_"<Image>/Filters",
- "*",
- [
- [PF_STRING, "text", "Text to name layer", "hello"],
- ],
- \&test_perl_filter;
+®ister(
+ "test_perl_filter",
+ boilerplate_params('filter', '<Image>/Filters'),
+ [ [PF_STRING, "text", "Text to name layer", "hello"], ],
+ sub {
+ # returns a value despite such not being declared
+ # previously, excess returns were a fatal error, but none were ever returned
+ # now not an error
+ my ($i, $drawable, $text) = @_;
+ my $tl = $i->text_layer_new("hi", "Arial", 8, 3);
+ $i->insert_layer($tl, 0, 0);
+ $tl->set_name($text);
+ return $i;
+ }
+);
exit main;
EOF
@@ -120,10 +95,10 @@ is(Gimp::Plugin->test_return_text(undef), 'default', 'test default on plugin');
ok((my $c = Gimp::Plugin->test_return_colour([6, 6, 6])), 'return colour');
my $send_text = 'exception';
eval { Gimp::Plugin->test_dies($send_text); };
-my $at = $@;
-chomp $at;
-is($at, $send_text, 'check exception returned correctly');
-
-ok(!$i->delete, 'remove image');
+is($@, "$send_text\n", 'exception returned correctly');
+eval { is(Gimp::Plugin->test_pf_adjustment('text'), 'text', 'adj'); };
+like($@, qr/INT32/, 'pf_adjustment dies on non-INT32');
+is(Gimp::Plugin->test_pf_adjustment(17), 17, 'test adj return');
+is(Gimp::Plugin->test_pf_adjustment(undef), 100, 'test adj default');
done_testing;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]