e76e39bd8c384f8354600d8c7b073a57f3012482
[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 BUILDTESTDIR=${builddir-"$MyPWD"}
30
31 FONTDIR="$MyPWD"/fonts
32 CACHEDIR="$MyPWD"/cache.dir
33 EXPECTED=${EXPECTED-"out.expected"}
34
35 ECHO=true
36
37 FCLIST=../fc-list/fc-list$EXEEXT
38 FCCACHE=../fc-cache/fc-cache$EXEEXT
39
40 which bwrap > /dev/null 2>&1
41 if [ $? -eq 0 ]; then
42     BWRAP=`which bwrap`
43 fi
44
45 FONT1=$TESTDIR/4x6.pcf
46 FONT2=$TESTDIR/8x16.pcf
47
48 check () {
49   $FCLIST - family pixelsize | sort > out
50   echo "=" >> out
51   $FCLIST - family pixelsize | sort >> out
52   echo "=" >> out
53   $FCLIST - family pixelsize | sort >> out
54   tr -d '\015' <out >out.tmp; mv out.tmp out
55   if cmp out $BUILDTESTDIR/$EXPECTED > /dev/null ; then : ; else
56     echo "*** Test failed: $TEST"
57     echo "*** output is in 'out', expected output in '$EXPECTED'"
58     exit 1
59   fi
60   rm -f out
61 }
62
63 prep() {
64   rm -rf $CACHEDIR
65   rm -rf $FONTDIR
66   mkdir $FONTDIR
67 }
68
69 dotest () {
70   TEST=$1
71   test x$VERBOSE = x || echo Running: $TEST
72 }
73
74 sed "s!@FONTDIR@!$FONTDIR!
75 s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
76
77 FONTCONFIG_FILE="$MyPWD"/fonts.conf
78 export FONTCONFIG_FILE
79
80 dotest "Basic check"
81 prep
82 cp $FONT1 $FONT2 $FONTDIR
83 check
84
85 dotest "With a subdir"
86 prep
87 cp $FONT1 $FONT2 $FONTDIR
88 $FCCACHE $FONTDIR
89 check
90
91 dotest "Subdir with a cache file"
92 prep
93 mkdir $FONTDIR/a
94 cp $FONT1 $FONT2 $FONTDIR/a
95 $FCCACHE $FONTDIR/a
96 check
97
98 dotest "Complicated directory structure"
99 prep
100 mkdir $FONTDIR/a
101 mkdir $FONTDIR/a/a
102 mkdir $FONTDIR/b
103 mkdir $FONTDIR/b/a
104 cp $FONT1 $FONTDIR/a
105 cp $FONT2 $FONTDIR/b/a
106 check
107
108 dotest "Subdir with an out-of-date cache file"
109 prep
110 mkdir $FONTDIR/a
111 $FCCACHE $FONTDIR/a
112 sleep 1
113 cp $FONT1 $FONT2 $FONTDIR/a
114 check
115
116 dotest "Dir with an out-of-date cache file"
117 prep
118 cp $FONT1 $FONTDIR
119 $FCCACHE $FONTDIR
120 sleep 1
121 mkdir $FONTDIR/a
122 cp $FONT2 $FONTDIR/a
123 check
124
125 dotest "Re-creating .uuid"
126 prep
127 cp $FONT1 $FONTDIR
128 $FCCACHE $FONTDIR
129 cat $FONTDIR/.uuid > out1
130 $FCCACHE -f $FONTDIR
131 cat $FONTDIR/.uuid > out2
132 if cmp out1 out2 > /dev/null ; then : ; else
133   echo "*** Test failed: $TEST"
134   echo "*** .uuid was modified unexpectedly"
135   exit 1
136 fi
137 $FCCACHE -r $FONTDIR
138 cat $FONTDIR/.uuid > out2
139 if cmp out1 out2 > /dev/null ; then
140   echo "*** Test failed: $TEST"
141   echo "*** .uuid wasn't modified"
142   exit 1
143 fi
144 rm -f out1 out2
145
146 dotest "Consistency between .uuid and cache name"
147 prep
148 cp $FONT1 $FONTDIR
149 $FCCACHE $FONTDIR
150 cat $FONTDIR/.uuid
151 $FCCACHE -r $FONTDIR
152 uuid=`cat $FONTDIR/.uuid`
153 ls $CACHEDIR/$uuid*
154 if [ $? != 0 ]; then
155   echo "*** Test failed: $TEST"
156   echo "No cache for $uuid"
157   ls $CACHEDIR
158   exit 1
159 fi
160 n=`ls -1 $CACHEDIR/*cache-* | wc -l`
161 if [ $n != 1 ]; then
162   echo "*** Test failed: $TEST"
163   echo "Unexpected cache was created"
164   ls $CACHEDIR
165   exit 1
166 fi
167
168 dotest "Keep mtime of the font directory"
169 prep
170 cp $FONT1 $FONTDIR
171 touch -d @0 $FONTDIR
172 stat $FONTDIR | grep Modify > out1
173 $FCCACHE $FONTDIR
174 stat $FONTDIR | grep Modify > out2
175 if cmp out1 out2 > /dev/null ; then : ; else
176     echo "*** Test failed: $TEST"
177     echo "mtime was modified"
178     exit 1
179 fi
180
181 if [ x"$BWRAP" != "x" ]; then
182 dotest "Basic functionality with the bind-mounted cache dir"
183 prep
184 cp $FONT1 $FONT2 $FONTDIR
185 $FCCACHE $FONTDIR
186 sleep 1
187 ls -l $CACHEDIR > out1
188 TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
189 sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
190 s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
191 $BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-match/fc-match$EXEEXT -f "%{file}\n" ":foundry=Misc" > xxx
192 $BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/test/test-bz106618$EXEEXT | sort > flist1
193 $BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev find $TESTTMPDIR/fonts/ -type f -name '*.pcf' | sort > flist2
194 ls -l $CACHEDIR > out2
195 if cmp out1 out2 > /dev/null ; then : ; else
196   echo "*** Test failed: $TEST"
197   echo "cache was updated."
198   exit 1
199 fi
200 if [ x`cat xxx` != "x$TESTTMPDIR/fonts/4x6.pcf" ]; then
201   echo "*** Test failed: $TEST"
202   echo "file property doesn't point to the new place: $TESTTMPDIR/fonts/4x6.pcf"
203   exit 1
204 fi
205 if cmp flist1 flist2 > /dev/null ; then : ; else
206   echo "*** Test failed: $TEST"
207   echo "file properties doesn't point to the new places"
208   echo "Expected result:"
209   cat flist2
210   echo "Actual result:"
211   cat flist1
212   exit 1
213 fi
214 rm -rf $TESTTMPDIR out1 out2 xxx flist1 flist2 bind-fonts.conf
215 fi
216
217 dotest "sysroot option"
218 prep
219 mkdir -p $MyPWD/sysroot/$FONTDIR
220 mkdir -p $MyPWD/sysroot/$CACHEDIR
221 cp $FONT1 $MyPWD/sysroot/$FONTDIR
222 cp $MyPWD/fonts.conf $MyPWD/sysroot/$MyPWD/fonts.conf
223 $FCCACHE -y $MyPWD/sysroot
224 stat $MyPWD/sysroot/$FONTDIR/.uuid
225 if test $? != 0; then
226   echo "*** Test failed: $TEST"
227   exit 1
228 fi
229
230 dotest "creating uuid-based cache file on sysroot"
231 uuid=`cat $MyPWD/sysroot/$FONTDIR/.uuid`
232 ls $MyPWD/sysroot/$CACHEDIR/$uuid*
233 if [ $? != 0 ]; then
234   echo "*** Test failed: $TEST"
235   echo "No cache for $uuid"
236   ls $MyPWD/sysroot/$CACHEDIR
237   exit 1
238 fi
239
240 rm -rf $MyPWD/sysroot
241
242 dotest "deleting .uuid file on empty dir"
243 prep
244 cp $FONT1 $FONT2 $FONTDIR
245 $FCCACHE $FONTDIR
246 sleep 1
247 rm -f $FONTDIR/*pcf
248 $FCCACHE $FONTDIR
249 rmdir $FONTDIR > /dev/null 2>&1
250 if [ $? != 0 ]; then
251   echo "*** Test failed: $TEST"
252   echo "$FONTDIR isn't empty"
253   ls -al $FONTDIR
254   exit 1
255 fi
256
257 rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out