Revert "Add a condition to FcCacheOffsetsValid() for detecting empty data of cache"
[platform/upstream/fontconfig.git] / test / run-test.sh
1 #!/bin/sh
2 # fontconfig/test/run-test.sh
3 #
4 # Copyright © 2000 Keith Packard
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and its
7 # documentation for any purpose is hereby granted without fee, provided that
8 # the above copyright notice appear in all copies and that both that
9 # copyright notice and this permission notice appear in supporting
10 # documentation, and that the name of the author(s) not be used in
11 # advertising or publicity pertaining to distribution of the software without
12 # specific, written prior permission.  The authors make no
13 # representations about the suitability of this software for any purpose.  It
14 # is provided "as is" without express or implied warranty.
15 #
16 # THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 # EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 # DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 # PERFORMANCE OF THIS SOFTWARE.
23 case "$OSTYPE" in
24     msys ) MyPWD=`pwd -W` ;;  # On Msys/MinGW, returns a MS Windows style path.
25     *    ) MyPWD=`pwd`    ;;  # On any other platforms, returns a Unix style path.
26 esac
27
28 TESTDIR=${srcdir-"$MyPWD"}
29
30 FONTDIR="$MyPWD"/fonts
31 CACHEDIR="$MyPWD"/cache.dir
32
33 ECHO=true
34
35 FCLIST=../fc-list/fc-list$EXEEXT
36 FCCACHE=../fc-cache/fc-cache$EXEEXT
37
38 FONT1=$TESTDIR/4x6.pcf
39 FONT2=$TESTDIR/8x16.pcf
40
41 check () {
42   $FCLIST - family pixelsize | sort > out
43   echo "=" >> out
44   $FCLIST - family pixelsize | sort >> out
45   echo "=" >> out
46   $FCLIST - family pixelsize | sort >> out
47   tr -d '\015' <out >out.tmp; mv out.tmp out
48   if cmp out $TESTDIR/out.expected > /dev/null ; then : ; else
49     echo "*** Test failed: $TEST"
50     echo "*** output is in 'out', expected output in 'out.expected'"
51     exit 1
52   fi
53   rm out
54 }
55
56 prep() {
57   rm -rf $CACHEDIR
58   rm -rf $FONTDIR
59   mkdir $FONTDIR
60 }
61
62 dotest () {
63   TEST=$1
64   test x$VERBOSE = x || echo Running: $TEST
65 }
66
67 sed "s!@FONTDIR@!$FONTDIR!
68 s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
69
70 FONTCONFIG_FILE="$MyPWD"/fonts.conf
71 export FONTCONFIG_FILE
72
73 dotest "Basic check"
74 prep
75 cp $FONT1 $FONT2 $FONTDIR
76 check
77
78 dotest "With a subdir"
79 prep
80 cp $FONT1 $FONT2 $FONTDIR
81 $FCCACHE $FONTDIR
82 check
83
84 dotest "Subdir with a cache file"
85 prep
86 mkdir $FONTDIR/a
87 cp $FONT1 $FONT2 $FONTDIR/a
88 $FCCACHE $FONTDIR/a
89 check
90
91 dotest "Complicated directory structure"
92 prep
93 mkdir $FONTDIR/a
94 mkdir $FONTDIR/a/a
95 mkdir $FONTDIR/b
96 mkdir $FONTDIR/b/a
97 cp $FONT1 $FONTDIR/a
98 cp $FONT2 $FONTDIR/b/a
99 check
100
101 dotest "Subdir with an out-of-date cache file"
102 prep
103 mkdir $FONTDIR/a
104 $FCCACHE $FONTDIR/a
105 sleep 1
106 cp $FONT1 $FONT2 $FONTDIR/a
107 check
108
109 dotest "Dir with an out-of-date cache file"
110 prep
111 cp $FONT1 $FONTDIR
112 $FCCACHE $FONTDIR
113 sleep 1
114 mkdir $FONTDIR/a
115 cp $FONT2 $FONTDIR/a
116 check
117
118 rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out