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
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
18 BEGIN { use_ok("IkiWiki"); }
19 BEGIN { use_ok("Image::Magick"); }
21 my $installed = $ENV{INSTALLED_TESTS};
25 @command = qw(ikiwiki);
28 ok(! system("make -s ikiwiki.out"));
29 @command = qw(perl -I. ./ikiwiki.out
30 --underlaydir=underlays/basewiki
31 --set underlaydirbase=underlays
32 --templatedir=templates);
35 push @command, qw(--set usedirs=0 --plugin img t/tmp/in t/tmp/out --verbose);
37 my $magick = new Image::Magick;
38 my $SVGS_WORK = defined $magick->QueryFormat("svg");
40 $magick->Read("t/img/twopages.pdf");
41 my $PDFS_WORK = defined $magick->Get("width");
43 ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
45 ok(! system("cp t/img/redsquare.png t/tmp/in/redsquare.png"));
46 # colons in filenames are a corner case for img
47 ok(! system("cp t/img/redsquare.png t/tmp/in/hello:world.png"));
48 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c.png"));
49 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d.png"));
50 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d:e:f:g:h:i:j.png"));
53 writefile("bluesquare.svg", "t/tmp/in",
54 '<svg width="30" height="30"><rect x="0" y="0" width="30" height="30" fill="blue"/></svg>');
57 # using different image sizes for different pages, so the pagenumber selection can be tested easily
58 ok(! system("cp t/img/twopages.pdf t/tmp/in/twopages.pdf"));
60 my $maybe_svg_img = "";
62 $maybe_svg_img = "[[!img bluesquare.svg size=10x]]";
65 my $maybe_pdf_img = "";
67 $maybe_pdf_img = <<EOF;
68 [[!img twopages.pdf size=12x]]
69 [[!img twopages.pdf size=16x pagenumber=1]]
73 writefile("imgconversions.mdwn", "t/tmp/in", <<EOF
74 [[!img redsquare.png]]
75 [[!img redsquare.png size=10x]]
76 [[!img redsquare.png size=30x50]] expecting 30x30
77 [[!img hello:world.png size=x8]] expecting 8x8
78 [[!img a:b:c.png size=x4]]
79 [[!img a:b:c:d:e:f:g:h:i:j.png size=x6]]
84 ok(utime(333333333, 333333333, "t/tmp/in/imgconversions.mdwn"));
86 ok(! system(@command));
90 my $im = Image::Magick->new();
91 my $r = $im->Read(":$filename");
92 return "no image" if $r;
93 my $w = $im->Get("width");
94 my $h = $im->Get("height");
98 my $outpath = "t/tmp/out/imgconversions";
99 my $outhtml = readfile("$outpath.html");
101 is(size("$outpath/10x-redsquare.png"), "10x10");
102 ok(! -e "$outpath/30x-redsquare.png");
103 ok($outhtml =~ /width="30" height="30".*expecting 30x30/);
106 skip "SVG support not installed (try libmagickcore-extra)", 1
108 # if this fails, you need libmagickcore-6.q16-2-extra installed
109 is(size("$outpath/10x-bluesquare.png"), "10x10");
113 skip "PDF support not installed (try ghostscript)", 2
115 is(size("$outpath/12x-twopages.png"), "12x12");
116 is(size("$outpath/16x-p1-twopages.png"), "16x2");
119 ok($outhtml =~ /width="8" height="8".*expecting 8x8/);
120 is(size("$outpath/x8-hello:world.png"), "8x8");
121 is(size("$outpath/x4-a:b:c.png"), "4x4");
122 is(size("$outpath/x6-a:b:c:d:e:f:g:h:i:j.png"), "6x6");
124 # now let's remove them again
126 if (1) { # for easier testing
127 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
129 ok(! system(@command, "--refresh"));
131 ok(! -e "$outpath/10x-redsquare.png");
132 ok(! -e "$outpath/10x-bluesquare.png");
133 ok(! -e "$outpath/12x-twopages.png");
134 ok(! -e "$outpath/16x-p1-twopages.png");
135 ok(! -e "$outpath/x8-hello:world.png");
136 ok(! -e "$outpath/x4-a:b:c.png");
137 ok(! -e "$outpath/x6-a:b:c:d:e:f:g:h:i:j.png");
140 ok(! system("rm -rf t/tmp"));