[meson] Add first regression test to FreeType * tests/README.md: documentation explaining how to build and run the tests with the Meson build. * tests/scripts/download-test-fonts.sh: Simple script to download test font files to the 'tests/data/' folder. * meson.build, meson_options.txt, tests/meson.build: Add 'tests' option to enable building and running the test programs, disabled by default. * tests/issue-1063/main.c: Simple regression test to exhibit issue 1063. * .gitignore: Ignore the content of the tests/data/ folder for now.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
diff --git a/.gitignore b/.gitignore
index 6e9fd98..e4f1510 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ include/dlg/
src/dlg/dlg.c
subprojects/*
!subprojects/*.wrap
+/tests/data/*
diff --git a/meson.build b/meson.build
index c5529a6..152024d 100644
--- a/meson.build
+++ b/meson.build
@@ -369,6 +369,9 @@ pkgconfig.generate(ft2_lib,
version: ft2_pkgconfig_version,
)
+if get_option('tests').enabled()
+ subdir('tests')
+endif
# NOTE: Unlike the old `make refdoc` command, this generates the
# documentation under `$BUILD/docs/` since Meson doesn't support modifying
diff --git a/meson_options.txt b/meson_options.txt
index f0fc50a..8747f52 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -35,6 +35,11 @@ option('harfbuzz',
+ ' If available, many glyphs not directly addressable'
+ ' by a font\'s character map will be hinted also.')
+option('tests',
+ type: 'feature',
+ value: 'disabled',
+ description: 'Enable FreeType unit and regression tests.')
+
option('brotli',
type: 'feature',
value: 'auto',
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..f6f8611
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,22 @@
+# Unit and regression tests for the FreeType library
+
+## Quick Start
+
+### Download test fonts
+
+Run the `tests/scripts/download-fonts.sh` script, which will
+download test fonts to the `tests/data/` directory first.
+
+### Build the test programs
+
+The tests are only built with the Meson build system, and
+are disabled by default, enable the 'tests' option to compile
+them, as in:
+
+ meson setup out -Dtests=enabled
+ meson compile -C out
+
+### Run the test programs
+
+ meson test -C out
+
diff --git a/tests/issue-1063/main.c b/tests/issue-1063/main.c
new file mode 100644
index 0000000..eac0264
--- /dev/null
+++ b/tests/issue-1063/main.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+#include <freetype/freetype.h>
+#include <ft2build.h>
+
+int
+main( void )
+{
+ FT_Library library;
+ FT_Face face;
+
+ /* Assumes this is run from out/ build directory though 'meson test -C out' */
+ const char* filepath = "../tests/data/As.I.Lay.Dying.ttf";
+
+ FT_Init_FreeType( &library );
+ FT_New_Face( library, filepath, 0, &face );
+ if ( !face )
+ {
+ fprintf( stderr, "Could not open file: %s\n", filepath );
+ return 1;
+ }
+
+ for ( FT_ULong i = 59; i < 171; i++ )
+ {
+ FT_UInt gid = FT_Get_Char_Index( face, i );
+ FT_Error code = FT_Load_Glyph( face, gid, FT_LOAD_DEFAULT );
+ if ( code )
+ printf( "unknown %d for char %lu, gid %u\n", code, i, gid );
+ }
+
+ return 0;
+}
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..8c5d034
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,7 @@
+test_issue_1063 = executable('issue-1063',
+ files([ 'issue-1063/main.c' ]),
+ dependencies: freetype_dep,
+)
+
+test('issue-1063', test_issue_1063, suite: 'regression')
+
diff --git a/tests/scripts/download-test-fonts.sh b/tests/scripts/download-test-fonts.sh
new file mode 100755
index 0000000..1158f10
--- /dev/null
+++ b/tests/scripts/download-test-fonts.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/bash
+# Download test fonts used by the FreeType regression test programs.
+# These will be copied to $FREETYPE/tests/data/
+# Each font file contains an 8-hexchar prefix corresponding to its md5sum
+
+set -e
+
+export LANG=C
+export LC_ALL=C
+
+PROGDIR=$(dirname "$0")
+PROGNAME=$(basename "$0")
+
+# Download a file from a given URL
+#
+# $1: URL
+# $2: Destination directory
+# $3: If not empty, destination file name. Default is to take
+# the URL's basename.
+#
+download_file () {
+ local URL=$1
+ local DST_DIR=$2
+ local DST_FILE=$3
+ if [[ -z "$DST_FILE" ]]; then
+ DST_FILE=$(basename "$URL")
+ fi
+ echo "URL: $URL"
+ wget -q -O "$DST_DIR/$DST_FILE" "$URL"
+}
+
+# $1: URL
+# $2: Destination directory
+# $3+: Optional file list, otherwise the full archive is extracted to $2
+download_and_extract_zip () {
+ local URL=$1
+ local DST_DIR=$2
+ shift
+ shift
+ TEMP_DST_DIR=$(mktemp -d)
+ TEMP_DST_NAME="a.zip"
+ download_file "$URL" "$TEMP_DST_DIR" "$TEMP_DST_NAME"
+ unzip -qo "$TEMP_DST_DIR/$TEMP_DST_NAME" -d "$DST_DIR" "$@"
+ rm -rf "$TEMP_DST_DIR"
+}
+
+# $1: File path
+# $2: Expected md5sum
+md5sum_check () {
+ local FILE=$1
+ local EXPECTED=$2
+ local HASH=$(md5sum "$FILE" | cut -d" " -f1)
+ if [[ "$EXPECTED" != "$HASH" ]]; then
+ echo "$FILE: Invalid md5sum $HASH expected $EXPECTED"
+ return 1
+ fi
+}
+
+INSTALL_DIR=$(cd $PROGDIR/.. && pwd)/data
+
+mkdir -p "$INSTALL_DIR"
+
+# See https://gitlab.freedesktop.org/freetype/freetype/-/issues/1063
+download_and_extract_zip "https://github.com/python-pillow/Pillow/files/6622147/As.I.Lay.Dying.zip" "$INSTALL_DIR"
+mv "$INSTALL_DIR/As I Lay Dying.ttf" "$INSTALL_DIR/As.I.Lay.Dying.ttf"
+md5sum_check "$INSTALL_DIR/As.I.Lay.Dying.ttf" e153d60e66199660f7cfe99ef4705ad7