]> git.imager.perl.org - imager.git/blob - lib/Imager/Test.pm
485b0f6e66a60817b7d49b33e392234f39517ebb
[imager.git] / lib / Imager / Test.pm
1 package Imager::Test;
2 use strict;
3 use Test::Builder;
4 require Exporter;
5 use vars qw(@ISA @EXPORT_OK);
6 @ISA = qw(Exporter);
7 @EXPORT_OK = qw(diff_text_with_nul);
8
9 sub 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
28 1;
29
30 __END__
31
32 =head1 NAME
33
34 Imager::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
43 This is a repository of functions used in testing Imager.
44
45 Some functions will only be useful in testing Imager itself, while
46 others should be useful in testing modules that use Imager.
47
48 No 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
56 Creates 2 test images and writes $text1 to the first image and $text2
57 to the second image with the string() method.  Each call adds 3 ok/not
58 ok to the output of the test script.
59
60 Extra options that should be supplied include the font and either a
61 color or channel parameter.
62
63 This was explicitly created for regression tests on #21770.
64
65 =back
66
67 =head1 AUTHOR
68
69 Tony Cook <tony@develop-help.com>
70
71 =cut