summaryrefslogtreecommitdiffstats
path: root/contrib/mom/examples/test-mom.sh.in
blob: ebaba2082abf3f5fb895d2675af6958e24ca6d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# 
# This file is part of groff.
# 
# groff is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# groff is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

builddir="@abs_top_builddir@"
have_urw_fonts="@groff_have_urw_fonts@"
examplesdir="$builddir/contrib/mom/examples"
ret=0
list="
  letter.pdf
  mom-pdf.pdf
  mon_premier_doc.pdf
  sample_docs.pdf
  slide-demo.pdf
  typesetting.pdf
  copyright-chapter.pdf
  copyright-default.pdf
  "

if test "$have_urw_fonts" != "yes"; then
    echo "No URW fonts, mom examples cannot be correctly generated"
    exit 77
fi

for cmd in pdfinfo pdfimages
do
    if ! command -v $cmd >/dev/null
    then
        echo "cannot locate '$cmd' command; skipping" >&2
        exit 77 # skip
    fi
done

# $1: pdf file
# $2: expected number of pages
check_number_pages()
{
    echo "Checking number of pages of $1"
    n_pages=`pdfinfo $1  | grep Pages | awk '{ print $2}'`
    if test "$n_pages" != "$2"; then
       echo "  Error: expected $2 pages, found $n_pages pages"
       ret=255
    fi
}

# $1 pdf file
check_has_images()
{
    echo "Checking if $1 has images"
    n_lines=`pdfimages -list $1 | wc -l `
    if test $n_lines -le 2; then
        echo " no images found"
        ret=255
    fi
}

for k in $list; do
    if ! test -f $examplesdir/$k; then
        echo "File $k not found"
        exit 255
    fi
done

check_number_pages "$examplesdir/letter.pdf" 1
check_number_pages "$examplesdir/mom-pdf.pdf" 8
check_number_pages "$examplesdir/mon_premier_doc.pdf" 5
check_number_pages "$examplesdir/sample_docs.pdf" 12
check_number_pages "$examplesdir/slide-demo.pdf" 33
check_number_pages "$examplesdir/typesetting.pdf" 3
check_number_pages "$examplesdir/copyright-chapter.pdf" 5
check_number_pages "$examplesdir/copyright-default.pdf" 5

check_has_images "$examplesdir/typesetting.pdf"
check_has_images "$examplesdir/slide-demo.pdf"

exit $ret