| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Copyright 2018-2025 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is part of groff, the GNU roff typesetting system. |
| 6 |
# |
| 7 |
# groff is free software; you can redistribute it and/or modify it under |
| 8 |
# the terms of the GNU General Public License as published by the Free |
| 9 |
# Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# groff is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
# for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
builddir="@abs_top_builddir@" |
| 21 |
have_urw_fonts="@groff_have_urw_fonts@" |
| 22 |
examplesdir="$builddir/contrib/mom/examples" |
| 23 |
ret=0 |
| 24 |
examples=" |
| 25 |
letter.pdf |
| 26 |
mom-pdf.pdf |
| 27 |
mon_premier_doc.pdf |
| 28 |
sample_docs.pdf |
| 29 |
slide-demo.pdf |
| 30 |
typesetting.pdf |
| 31 |
copyright-chapter.pdf |
| 32 |
copyright-default.pdf |
| 33 |
" |
| 34 |
|
| 35 |
if [ "$have_urw_fonts" != yes ] |
| 36 |
then |
| 37 |
echo "$0: URW fonts needed to generate mom examples; skipping" >&2 |
| 38 |
exit 77 # skip |
| 39 |
fi |
| 40 |
|
| 41 |
for cmd in pdfinfo pdfimages |
| 42 |
do |
| 43 |
if ! command -v $cmd >/dev/null |
| 44 |
then |
| 45 |
echo "$0: cannot locate '$cmd' command; skipping" >&2 |
| 46 |
exit 77 # skip |
| 47 |
fi |
| 48 |
done |
| 49 |
|
| 50 |
# At least two different implementations of pdfimages exist, poppler and |
| 51 |
# xpdfreader.com. The latter uses a slightly different input and output |
| 52 |
# syntax; detect and cope with it. |
| 53 |
image_root= |
| 54 |
if pdfimages -v 2>&1 | grep -q xpdfreader |
| 55 |
then |
| 56 |
image_root=1 |
| 57 |
fi |
| 58 |
|
| 59 |
# $1: PDF file |
| 60 |
# $2: expected number of pages |
| 61 |
check_number_pages() |
| 62 |
{ |
| 63 |
echo "Checking number of pages in $1" |
| 64 |
page_count=$(pdfinfo "$1" | awk '/Pages/ { print $2}') |
| 65 |
if [ "$page_count" != "$2" ] |
| 66 |
then |
| 67 |
echo "...FAILED: expected $2 pages, found $page_count" |
| 68 |
ret=1 |
| 69 |
fi |
| 70 |
} |
| 71 |
|
| 72 |
# $1: PDF file |
| 73 |
# $2: expected number of images |
| 74 |
check_has_images() |
| 75 |
{ |
| 76 |
echo "Checking whether $1 has images" |
| 77 |
image_list=$(pdfimages -list "$1" $image_root) |
| 78 |
echo "$image_list" |
| 79 |
# Strip header out of poppler pdfimages output. |
| 80 |
image_count=$(echo "$image_list" | sed -n '1,/^---/d;p' | wc -l) |
| 81 |
if [ "$image_count" -ne "$2" ] |
| 82 |
then |
| 83 |
echo "...FAILED: expected $2 images, found $image_count" |
| 84 |
ret=1 |
| 85 |
fi |
| 86 |
} |
| 87 |
|
| 88 |
# TODO: Make this a "hard error" (status 99). See, e.g., |
| 89 |
# "font/devpdf/tests/check-default-foundry.sh.in". |
| 90 |
for k in $examples |
| 91 |
do |
| 92 |
if ! [ -f "$examplesdir"/$k ] |
| 93 |
then |
| 94 |
echo "File '$k' not found" |
| 95 |
exit 2 |
| 96 |
fi |
| 97 |
done |
| 98 |
|
| 99 |
check_number_pages "$examplesdir/letter.pdf" 1 |
| 100 |
check_number_pages "$examplesdir/mom-pdf.pdf" 8 |
| 101 |
check_number_pages "$examplesdir/mon_premier_doc.pdf" 5 |
| 102 |
check_number_pages "$examplesdir/sample_docs.pdf" 12 |
| 103 |
check_number_pages "$examplesdir/slide-demo.pdf" 33 |
| 104 |
check_number_pages "$examplesdir/typesetting.pdf" 3 |
| 105 |
check_number_pages "$examplesdir/copyright-chapter.pdf" 5 |
| 106 |
check_number_pages "$examplesdir/copyright-default.pdf" 5 |
| 107 |
|
| 108 |
check_has_images "$examplesdir/typesetting.pdf" 2 |
| 109 |
check_has_images "$examplesdir/slide-demo.pdf" 2 |
| 110 |
|
| 111 |
exit $ret |
| 112 |
|
| 113 |
# vim:set autoindent expandtab shiftwidth=4 tabstop=4 textwidth=72: |