since: 2.38


g_test_build_filename (
  GTestFileType file_type,
  const gchar* first_path,


Creates the pathname to a data file that is required for a test.

This function is conceptually similar to g_build_filename() except that the first argument has been replaced with a GTestFileType argument.

The data file should either have been distributed with the module containing the test (G_TEST_DIST) or built as part of the build system of that module (G_TEST_BUILT).

In order for this function to work in srcdir != builddir situations, the G_TEST_SRCDIR and G_TEST_BUILDDIR environment variables need to have been defined. As of 2.38, this is done by the included in GLib. Please ensure that your copy is up to date before using this function.

In case neither variable is set, this function will fall back to using the dirname portion of argv[0], possibly removing “.libs”. This allows for casual running of tests directly from the commandline in the srcdir == builddir case and should also support running of installed tests, assuming the data files have been installed in the same relative path as the test binary.

Available since: 2.38

This function is not directly available to language bindings.



Type: GTestFileType

The type of file (built vs. distributed)


Type: const gchar*

The first segment of the pathname.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.


NULL-terminated additional path segments.

Return value

Type: gchar*

The path of the file, to be freed using g_free()

The caller of the function takes ownership of the data, and is responsible for freeing it.
The value is a NUL terminated UTF-8 string.