]> sipb.mit.edu Git - ikiwiki.git/blob - t/img.t
2a4f9510c24d80b2682c9737de054d51b3d3e52b
[ikiwiki.git] / t / img.t
1 #!/usr/bin/perl
2 #
3 # unit test that creates test images (png, svg, multi-page pdf), runs ikiwiki
4 # on them, checks the resulting images for plausibility based on their image
5 # sizes, and checks if they vanish when not required in the build process any
6 # more
7 #
8 # if you have trouble here, be aware that there are three debian packages that
9 # can provide Image::Magick: perlmagick, libimage-magick-perl and
10 # graphicsmagick-libmagick-dev-compat
11 #
12 package IkiWiki;
13
14 use warnings;
15 use strict;
16 use Test::More;
17
18 BEGIN { use_ok("IkiWiki"); }
19 BEGIN { use_ok("Image::Magick"); }
20
21 ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
22
23 ok(! system("cp t/img/redsquare.png t/tmp/in/redsquare.png"));
24 writefile("emptysquare.svg", "t/tmp/in", '<svg width="10" height="10"/>');
25 # using different image sizes for different pages, so the pagenumber selection can be tested easily
26 ok(! system("cp t/img/twopages.pdf t/tmp/in/twopages.pdf"));
27
28 writefile("imgconversions.mdwn", "t/tmp/in", <<EOF
29 [[!img redsquare.png]]
30 [[!img redsquare.png size=10x]]
31 [[!img emptysquare.svg size=10x]]
32 [[!img twopages.pdf size=12x]]
33 [[!img twopages.pdf size=16x pagenumber=1]]
34 EOF
35 );
36
37 ok(! system("make -s ikiwiki.out"));
38
39 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin img t/tmp/in t/tmp/out -verbose";
40
41 ok(! system($command));
42
43 sub size($) {
44         my $filename = shift;
45         my $im = Image::Magick->new();
46         $im->Read($filename);
47         my $w = $im->Get("width");
48         my $h = $im->Get("height");
49         return "${w}x${h}";
50 }
51
52 my $outpath = "t/tmp/out/imgconversions";
53 is(size("$outpath/10x-redsquare.png"), "10x10");
54 SKIP: {
55         # FIXME this is a workaround for libimage-magick-perl which has issues with svg
56         skip "skip svg test due to imagemagick 8:6.8.8.9 bug (6.7 works, so does graphicsmagick)", 1 if $INC{"Image/Magick/Q16.pm"};
57         is(size("$outpath/10x-emptysquare.png"), "10x10");
58 }
59 is(size("$outpath/12x-twopages.png"), "12x12");
60 is(size("$outpath/16x-p1-twopages.png"), "16x2");
61
62 # now let's remove them again
63
64 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
65
66 ok(! system("$command --refresh"));
67
68 ok(! -e "$outpath/10x-simple.png");
69 ok(! -e "$outpath/10x-simple-svg.png");
70 ok(! -e "$outpath/10x-simple-pdf.png");
71 ok(! -e "$outpath/10x-p1-simple-pdf.png");
72
73 # cleanup
74 ok(! system("rm -rf t/tmp"));
75 done_testing;
76
77 1;