tests for the functionality.
https://rt.cpan.org/Ticket/Display.html?id=21770
RETVAL
undef_int
-i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
+i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text_sv, align, aa, vlayout, utf8)
Imager::Font::FT2 font
Imager::ImgRaw im
int tx
int channel
double cheight
double cwidth
- char *text
+ SV *text_sv
int align
int aa
int vlayout
int utf8
+ PREINIT:
+ char const *text;
+ STRLEN len;
CODE:
#ifdef SvUTF8
if (SvUTF8(ST(7)))
utf8 = 1;
#endif
+ text = SvPV(text_sv, len);
RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
- strlen(text), align, aa, vlayout, 1);
+ len, align, aa, vlayout, 1);
OUTPUT:
RETVAL
lib/Imager/Inline.pod Using Imager with Inline::C
lib/Imager/Matrix2d.pm
lib/Imager/Regops.pm
+lib/Imager/Test.pm
lib/Imager/Transform.pm
lib/Imager/Transformations.pod
lib/Imager/Tutorial.pod
installdirs: site
recommends:
Parse::RecDescent: 0
+build_requires:
+ Test::More: 0.47
license: perl
dynamic_config: 1
distribution_type: module
use Config;
use File::Spec;
use Getopt::Long;
-use vars qw(%Recommends);
+use vars qw(%Recommends %BuildRequires);
use ExtUtils::Manifest qw(maniread);
use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS);
$Recommends{Imager} =
{ 'Parse::RecDescent' => 0 };
+$BuildRequires{Imager} =
+ { 'Test::More' => 0.47 };
my %opts=(
'NAME' => 'Imager',
'OBJECT' => join(' ', @objs, $F_OBJECT),
clean => { FILES=>'testout meta.tmp rubthru.c scale.c' },
PM => gen_PM(),
+ PREREQ_PM => $BuildRequires{Imager},
);
# eval to prevent warnings about versions with _ in them
$meta .= " $module: $version\n";
}
}
+ if (keys %{$BuildRequires{$opts->{NAME}}}) {
+ $meta .= "build_requires:\n";
+ while (my ($module, $version) = each %{$BuildRequires{$opts->{NAME}}}) {
+ $meta .= " $module: $version\n";
+ }
+ }
$meta .= <<YAML;
license: perl
dynamic_config: 1
--- /dev/null
+package Imager::Test;
+use strict;
+use Test::Builder;
+require Exporter;
+use vars qw(@ISA @EXPORT_OK);
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(diff_text_with_nul);
+
+sub diff_text_with_nul {
+ my ($desc, $text1, $text2, @params) = @_;
+
+ my $builder = Test::Builder->new;
+
+ print "# $desc\n";
+ my $imbase = Imager->new(xsize => 100, ysize => 100);
+ my $imcopy = Imager->new(xsize => 100, ysize => 100);
+
+ $builder->ok($imbase->string(x => 5, 'y' => 50, size => 20,
+ string => $text1,
+ @params), "$desc - draw text1");
+ $builder->ok($imcopy->string(x => 5, 'y' => 50, size => 20,
+ string => $text2,
+ @params), "$desc - draw text2");
+ $builder->isnt_num(Imager::i_img_diff($imbase->{IMG}, $imcopy->{IMG}), 0,
+ "$desc - check result different");
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Imager::Test - common functions used in testing Imager
+
+=head1 SYNOPSIS
+
+ use Imager::Test 'diff_text_with_nul';
+ diff_text_with_nul($test_name, $text1, $text2, @string_options);
+
+=head1 DESCRIPTION
+
+This is a repository of functions used in testing Imager.
+
+Some functions will only be useful in testing Imager itself, while
+others should be useful in testing modules that use Imager.
+
+No functions are exported by default.
+
+=head1 FUNCTIONS
+
+=over
+
+=item diff_text_with_nul($test_name, $text1, $text2, @optios)
+
+Creates 2 test images and writes $text1 to the first image and $text2
+to the second image with the string() method. Each call adds 3 ok/not
+ok to the output of the test script.
+
+Extra options that should be supplied include the font and either a
+color or channel parameter.
+
+This was explicitly created for regression tests on #21770.
+
+=back
+
+=head1 AUTHOR
+
+Tony Cook <tony@develop-help.com>
+
+=cut
# (It may become useful if the test is moved to ./t subdirectory.)
use strict;
use lib 't';
-use Test::More tests => 77;
+use Test::More tests => 90;
BEGIN { use_ok(Imager => ':all') }
+use Imager::Test qw(diff_text_with_nul);
#$Imager::DEBUG=1;
SKIP:
{
if (!(i_has_format("t1")) ) {
- skip("t1lib unavailable or disabled", 76);
+ skip("t1lib unavailable or disabled", 88);
}
elsif (! -f $fontname_pfb) {
- skip("cannot find fontfile for type 1 test $fontname_pfb", 76);
+ skip("cannot find fontfile for type 1 test $fontname_pfb", 89);
}
elsif (! -f $fontname_afm) {
- skip("cannot find fontfile for type 1 test $fontname_afm", 76);
+ skip("cannot find fontfile for type 1 test $fontname_afm", 89);
}
print "# has t1\n";
is($bbox_utf8->advance_width, $bbox_tran->advance_width,
"advance widths should match");
}
+ { # string output cut off at NUL ('\0')
+ # https://rt.cpan.org/Ticket/Display.html?id=21770 cont'd
+ my $font = Imager::Font->new(file => 'fontfiles/dcr10.pfb', type => 't1');
+ ok($font, "loaded dcr10.pfb");
+
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, color => '#FFFFFF');
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, channel => 1);
+
+ # UTF8 encoded \xBF
+ my $pound = pack("C*", 0xC2, 0xBF);
+ diff_text_with_nul("utf8 pound\0pound vs pound", "$pound\0$pound", $pound,
+ font => $font, color => '#FFFFFF', utf8 => 1);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$pound\0$pound", $pound,
+ font => $font, channel => 1, utf8 => 1);
+
+ }
}
#malloc_state();
#!perl -w
use strict;
use lib 't';
-use Test::More tests => 72;
+use Test::More tests => 85;
BEGIN { use_ok(Imager => ':all') }
require "t/testtools.pl";
+use Imager::Test qw(diff_text_with_nul);
init_log("testout/t35ttfont.log",2);
SKIP:
{
- skip("freetype 1.x unavailable or disabled", 71)
+ skip("freetype 1.x unavailable or disabled", 84)
unless i_has_format("tt");
print "# has tt\n";
if (!ok(-f $fontname, "check test font file exists")) {
print "# cannot find fontfile for truetype test $fontname\n";
- skip('Cannot load test font', 70);
+ skip('Cannot load test font', 83);
}
i_init_fonts();
"outputting just a space was crashing");
}
+ { # string output cut off at NUL ('\0')
+ # https://rt.cpan.org/Ticket/Display.html?id=21770 cont'd
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'tt');
+ ok($font, "loaded imugly");
+
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, color => '#FFFFFF');
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, channel => 1);
+
+ # UTF8 encoded \x{2010}
+ my $dash = pack("C*", 0xE2, 0x80, 0x90);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, color => '#FFFFFF', utf8 => 1);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, channel => 1, utf8 => 1);
+ }
+
ok(1, "end of code");
}
#!perl -w
use strict;
use lib 't';
-use Test::More tests => 165;
+use Test::More tests => 178;
++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
BEGIN { use_ok(Imager => ':all') }
+use Imager::Test qw(diff_text_with_nul);
+
init_log("testout/t38ft2font.log",2);
my @base_color = (64, 255, 64);
SKIP:
{
- i_has_format("ft2") or skip("no freetype2 library found", 164);
+ i_has_format("ft2") or skip("no freetype2 library found", 177);
print "# has ft2\n";
my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
- -f $fontname or skip("cannot find fontfile $fontname", 164);
+ -f $fontname or skip("cannot find fontfile $fontname", 177);
my $bgcolor=i_color_new(255,0,0,0);
}
{ # cannot output "0"
+ # https://rt.cpan.org/Ticket/Display.html?id=21770
my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
ok($font, "loaded imugly");
my $imbase = Imager->new(xsize => 100, ysize => 100);
ok(Imager::i_img_diff($im->{IMG}, $imbase->{IMG}),
"make sure we actually drew it");
}
+ { # string output cut off at NUL ('\0')
+ # https://rt.cpan.org/Ticket/Display.html?id=21770 cont'd
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ ok($font, "loaded imugly");
+
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, color => '#FFFFFF');
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, channel => 1);
+
+ # UTF8 encoded \x{2010}
+ my $dash = pack("C*", 0xE2, 0x80, 0x90);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, color => '#FFFFFF', utf8 => 1);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, channel => 1, utf8 => 1);
+ }
}
sub align_test {