use SvPV to get the length of text to draw rather than strlen(), add
[imager.git] / lib / Imager / Test.pm
CommitLineData
9a6ab99c
TC
1package Imager::Test;
2use strict;
3use Test::Builder;
4require Exporter;
5use vars qw(@ISA @EXPORT_OK);
6@ISA = qw(Exporter);
7@EXPORT_OK = qw(diff_text_with_nul);
8
9sub diff_text_with_nul {
10 my ($desc, $text1, $text2, @params) = @_;
11
12 my $builder = Test::Builder->new;
13
14 print "# $desc\n";
15 my $imbase = Imager->new(xsize => 100, ysize => 100);
16 my $imcopy = Imager->new(xsize => 100, ysize => 100);
17
18 $builder->ok($imbase->string(x => 5, 'y' => 50, size => 20,
19 string => $text1,
20 @params), "$desc - draw text1");
21 $builder->ok($imcopy->string(x => 5, 'y' => 50, size => 20,
22 string => $text2,
23 @params), "$desc - draw text2");
24 $builder->isnt_num(Imager::i_img_diff($imbase->{IMG}, $imcopy->{IMG}), 0,
25 "$desc - check result different");
26}
27
281;
29
30__END__
31
32=head1 NAME
33
34Imager::Test - common functions used in testing Imager
35
36=head1 SYNOPSIS
37
38 use Imager::Test 'diff_text_with_nul';
39 diff_text_with_nul($test_name, $text1, $text2, @string_options);
40
41=head1 DESCRIPTION
42
43This is a repository of functions used in testing Imager.
44
45Some functions will only be useful in testing Imager itself, while
46others should be useful in testing modules that use Imager.
47
48No functions are exported by default.
49
50=head1 FUNCTIONS
51
52=over
53
54=item diff_text_with_nul($test_name, $text1, $text2, @optios)
55
56Creates 2 test images and writes $text1 to the first image and $text2
57to the second image with the string() method. Each call adds 3 ok/not
58ok to the output of the test script.
59
60Extra options that should be supplied include the font and either a
61color or channel parameter.
62
63This was explicitly created for regression tests on #21770.
64
65=back
66
67=head1 AUTHOR
68
69Tony Cook <tony@develop-help.com>
70
71=cut