[tests] Allow arbitrary build directories. * tests/issue-1063/main.c (main): I am building with a build directory that is not directly inside the source tree, so the path `../tests/data/As.I.Lay.Dying.ttf` does not resolve to the test input file. This change passes the test data directory as an environment variable to allow arbitrary build directories. * tests/meson.build: Updated.
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
diff --git a/ChangeLog b/ChangeLog
index 520d3cc..7a3a465 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-07-16 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
+
+ [tests] Allow arbitrary build directories.
+
+ * tests/issue-1063/main.c (main): I am building with a build
+ directory that is not directly inside the source tree, so the path
+ `../tests/data/As.I.Lay.Dying.ttf` does not resolve to the test
+ input file. This change passes the test data directory as an
+ environment variable to allow arbitrary build directories.
+
+ * tests/meson.build: Updated.
+
2021-07-15 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
* tests/issue-1063/main.c (main): Fix uninitialized variable.
diff --git a/tests/issue-1063/main.c b/tests/issue-1063/main.c
index 1bce0fe..cb06be1 100644
--- a/tests/issue-1063/main.c
+++ b/tests/issue-1063/main.c
@@ -1,16 +1,30 @@
+#include <limits.h>
#include <stdio.h>
#include <freetype/freetype.h>
#include <ft2build.h>
+
int
main( void )
{
- FT_Library library;
- FT_Face face = NULL;
+ FT_Library library;
+ FT_Face face = NULL;
+
+ /*
+ * We assume that `FREETYPE_TESTS_DATA_DIR` was set by `meson test`.
+ * Otherwise we default to `../tests/data`.
+ *
+ * TODO (David): Rewrite this to pass the test directory through the
+ * command-line.
+ */
+ const char* testdata_dir = getenv( "FREETYPE_TESTS_DATA_DIR" );
+ char filepath[PATH_MAX];
+
- /* Assumes this is run from out/ build directory though 'meson test -C out' */
- const char* filepath = "../tests/data/As.I.Lay.Dying.ttf";
+ snprintf( filepath, sizeof( filepath ), "%s/%s",
+ testdata_dir ? testdata_dir : "../tests/data",
+ "As.I.Lay.Dying.ttf" );
FT_Init_FreeType( &library );
if ( FT_New_Face( library, filepath, 0, &face ) != 0 )
@@ -19,13 +33,17 @@ main( void )
return 1;
}
- for ( FT_ULong i = 59; i < 171; i++ )
+ 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 );
+ 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;
}
+
+/* EOF */
diff --git a/tests/meson.build b/tests/meson.build
index 8c5d034..527998f 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -3,5 +3,12 @@ test_issue_1063 = executable('issue-1063',
dependencies: freetype_dep,
)
-test('issue-1063', test_issue_1063, suite: 'regression')
+test_env = ['FREETYPE_TESTS_DATA_DIR='
+ + join_paths(meson.current_source_dir(), 'data')]
+test('issue-1063',
+ test_issue_1063,
+ env: test_env,
+ suite: 'regression')
+
+# EOF