run-test.sh 6.77 KB
Newer Older
Keith Packard's avatar
Keith Packard committed
1
#!/bin/sh
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# fontconfig/test/run-test.sh
#
# Copyright © 2000 Keith Packard
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of the author(s) not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission.  The authors make no
# representations about the suitability of this software for any purpose.  It
# is provided "as is" without express or implied warranty.
#
# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
23 24 25 26
case "$OSTYPE" in
    msys ) MyPWD=`pwd -W` ;;  # On Msys/MinGW, returns a MS Windows style path.
    *    ) MyPWD=`pwd`    ;;  # On any other platforms, returns a Unix style path.
esac
27

28
TESTDIR=${srcdir-"$MyPWD"}
29
BUILDTESTDIR=${builddir-"$MyPWD"}
30 31 32

FONTDIR="$MyPWD"/fonts
CACHEDIR="$MyPWD"/cache.dir
33
EXPECTED=${EXPECTED-"out.expected"}
Keith Packard's avatar
Keith Packard committed
34 35 36

ECHO=true

37 38
FCLIST=../fc-list/fc-list$EXEEXT
FCCACHE=../fc-cache/fc-cache$EXEEXT
Keith Packard's avatar
Keith Packard committed
39

40 41 42 43 44
which bwrap > /dev/null 2>&1
if [ $? -eq 0 ]; then
    BWRAP=`which bwrap`
fi

45 46 47
FONT1=$TESTDIR/4x6.pcf
FONT2=$TESTDIR/8x16.pcf

Keith Packard's avatar
Keith Packard committed
48 49 50 51 52 53
check () {
  $FCLIST - family pixelsize | sort > out
  echo "=" >> out
  $FCLIST - family pixelsize | sort >> out
  echo "=" >> out
  $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
Keith Packard's avatar
Keith Packard committed
56
    echo "*** Test failed: $TEST"
57
    echo "*** output is in 'out', expected output in '$EXPECTED'"
58
    exit 1
Keith Packard's avatar
Keith Packard committed
59
  fi
Akira TAGOH's avatar
Akira TAGOH committed
60
  rm -f out
Keith Packard's avatar
Keith Packard committed
61 62 63
}

prep() {
64
  rm -rf $CACHEDIR
Keith Packard's avatar
Keith Packard committed
65 66 67 68 69 70 71 72 73 74
  rm -rf $FONTDIR
  mkdir $FONTDIR
}

dotest () {
  TEST=$1
  test x$VERBOSE = x || echo Running: $TEST
}

sed "s!@FONTDIR@!$FONTDIR!
75
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
Keith Packard's avatar
Keith Packard committed
76

77
FONTCONFIG_FILE="$MyPWD"/fonts.conf
Keith Packard's avatar
Keith Packard committed
78 79 80 81
export FONTCONFIG_FILE

dotest "Basic check"
prep
82
cp $FONT1 $FONT2 $FONTDIR
Keith Packard's avatar
Keith Packard committed
83 84 85 86
check

dotest "With a subdir"
prep
87
cp $FONT1 $FONT2 $FONTDIR
Keith Packard's avatar
Keith Packard committed
88 89 90 91 92 93
$FCCACHE $FONTDIR
check

dotest "Subdir with a cache file"
prep
mkdir $FONTDIR/a
94
cp $FONT1 $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
95 96 97 98 99 100 101 102 103
$FCCACHE $FONTDIR/a
check

dotest "Complicated directory structure"
prep
mkdir $FONTDIR/a
mkdir $FONTDIR/a/a
mkdir $FONTDIR/b
mkdir $FONTDIR/b/a
104 105
cp $FONT1 $FONTDIR/a
cp $FONT2 $FONTDIR/b/a
Keith Packard's avatar
Keith Packard committed
106 107 108 109 110 111 112
check

dotest "Subdir with an out-of-date cache file"
prep
mkdir $FONTDIR/a
$FCCACHE $FONTDIR/a
sleep 1
113
cp $FONT1 $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
114 115 116 117
check

dotest "Dir with an out-of-date cache file"
prep
118
cp $FONT1 $FONTDIR
Keith Packard's avatar
Keith Packard committed
119 120 121
$FCCACHE $FONTDIR
sleep 1
mkdir $FONTDIR/a
122
cp $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
123 124
check

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
dotest "Re-creating .uuid"
prep
cp $FONT1 $FONTDIR
$FCCACHE $FONTDIR
cat $FONTDIR/.uuid > out1
$FCCACHE -f $FONTDIR
cat $FONTDIR/.uuid > out2
if cmp out1 out2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "*** .uuid was modified unexpectedly"
  exit 1
fi
$FCCACHE -r $FONTDIR
cat $FONTDIR/.uuid > out2
if cmp out1 out2 > /dev/null ; then
  echo "*** Test failed: $TEST"
  echo "*** .uuid wasn't modified"
  exit 1
fi
Akira TAGOH's avatar
Akira TAGOH committed
144
rm -f out1 out2
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

dotest "Consistency between .uuid and cache name"
prep
cp $FONT1 $FONTDIR
$FCCACHE $FONTDIR
cat $FONTDIR/.uuid
$FCCACHE -r $FONTDIR
uuid=`cat $FONTDIR/.uuid`
ls $CACHEDIR/$uuid*
if [ $? != 0 ]; then
  echo "*** Test failed: $TEST"
  echo "No cache for $uuid"
  ls $CACHEDIR
  exit 1
fi
n=`ls -1 $CACHEDIR/*cache-* | wc -l`
if [ $n != 1 ]; then
  echo "*** Test failed: $TEST"
  echo "Unexpected cache was created"
  ls $CACHEDIR
  exit 1
fi

168 169 170 171 172 173 174 175 176 177 178 179 180
dotest "Keep mtime of the font directory"
prep
cp $FONT1 $FONTDIR
touch -d @0 $FONTDIR
stat $FONTDIR | grep Modify > out1
$FCCACHE $FONTDIR
stat $FONTDIR | grep Modify > out2
if cmp out1 out2 > /dev/null ; then : ; else
    echo "*** Test failed: $TEST"
    echo "mtime was modified"
    exit 1
fi

181 182 183 184 185 186 187 188 189 190
if [ x"$BWRAP" != "x" ]; then
dotest "Basic functionality with the bind-mounted cache dir"
prep
cp $FONT1 $FONT2 $FONTDIR
$FCCACHE $FONTDIR
sleep 1
ls -l $CACHEDIR > out1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
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 193
$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
$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 195 196 197 198 199 200 201
ls -l $CACHEDIR > out2
if cmp out1 out2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "cache was updated."
  exit 1
fi
if [ x`cat xxx` != "x$TESTTMPDIR/fonts/4x6.pcf" ]; then
  echo "*** Test failed: $TEST"
202
  echo "file property doesn't point to the new place: $TESTTMPDIR/fonts/4x6.pcf"
203 204
  exit 1
fi
205 206 207 208 209 210 211 212 213 214
if cmp flist1 flist2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "file properties doesn't point to the new places"
  echo "Expected result:"
  cat flist2
  echo "Actual result:"
  cat flist1
  exit 1
fi
rm -rf $TESTTMPDIR out1 out2 xxx flist1 flist2 bind-fonts.conf
215 216
fi

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
dotest "sysroot option"
prep
mkdir -p $MyPWD/sysroot/$FONTDIR
mkdir -p $MyPWD/sysroot/$CACHEDIR
cp $FONT1 $MyPWD/sysroot/$FONTDIR
cp $MyPWD/fonts.conf $MyPWD/sysroot/$MyPWD/fonts.conf
$FCCACHE -y $MyPWD/sysroot
stat $MyPWD/sysroot/$FONTDIR/.uuid
if test $? != 0; then
  echo "*** Test failed: $TEST"
  exit 1
fi

dotest "creating uuid-based cache file on sysroot"
uuid=`cat $MyPWD/sysroot/$FONTDIR/.uuid`
ls $MyPWD/sysroot/$CACHEDIR/$uuid*
if [ $? != 0 ]; then
  echo "*** Test failed: $TEST"
  echo "No cache for $uuid"
  ls $MyPWD/sysroot/$CACHEDIR
  exit 1
fi

rm -rf $MyPWD/sysroot

242 243 244 245 246
dotest "deleting .uuid file on empty dir"
prep
cp $FONT1 $FONT2 $FONTDIR
$FCCACHE $FONTDIR
sleep 1
Akira TAGOH's avatar
Akira TAGOH committed
247
rm -f $FONTDIR/*pcf
248 249 250 251 252 253 254 255 256
$FCCACHE $FONTDIR
rmdir $FONTDIR > /dev/null 2>&1
if [ $? != 0 ]; then
  echo "*** Test failed: $TEST"
  echo "$FONTDIR isn't empty"
  ls -al $FONTDIR
  exit 1
fi

257
rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out