girepository: Move library path functions over from gitypelib.c

This means they’re implemented in the same file as the typelib search
path, so it’s easier to refactor the code.

This adds `gi_repository_get_library_path()` to expose the library path,
both publicly and to internal users in `gitypelib.c`. And unit tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2024-01-23 23:53:59 +00:00
parent 846abed197
commit 5ef1c7e110
4 changed files with 110 additions and 36 deletions

View File

@@ -99,6 +99,39 @@ test_repository_search_paths_prepend (void)
#endif
}
static void
test_repository_library_paths_default (void)
{
const char * const *library_paths;
size_t n_library_paths;
library_paths = gi_repository_get_library_path (&n_library_paths);
g_assert_nonnull (library_paths);
g_assert_cmpuint (g_strv_length ((char **) library_paths), ==, 0);
}
static void
test_repository_library_paths_prepend (void)
{
const char * const *library_paths;
size_t n_library_paths;
gi_repository_prepend_library_path (g_test_get_dir (G_TEST_BUILT));
library_paths = gi_repository_get_library_path (&n_library_paths);
g_assert_nonnull (library_paths);
g_assert_cmpuint (g_strv_length ((char **) library_paths), ==, 1);
g_assert_cmpstr (library_paths[0], ==, g_test_get_dir (G_TEST_BUILT));
gi_repository_prepend_library_path (g_test_get_dir (G_TEST_DIST));
library_paths = gi_repository_get_library_path (&n_library_paths);
g_assert_nonnull (library_paths);
g_assert_cmpuint (g_strv_length ((char **) library_paths), ==, 2);
g_assert_cmpstr (library_paths[0], ==, g_test_get_dir (G_TEST_DIST));
g_assert_cmpstr (library_paths[1], ==, g_test_get_dir (G_TEST_BUILT));
}
int
main (int argc,
char *argv[])
@@ -109,9 +142,11 @@ main (int argc,
g_setenv ("GI_TYPELIB_PATH", g_get_tmp_dir (), TRUE);
g_setenv ("GI_GIR_PATH", g_get_user_cache_dir (), TRUE);
g_test_add_func ("/repository-search-paths/unset", test_repository_search_paths_unset);
g_test_add_func ("/repository-search-paths/default", test_repository_search_paths_default);
g_test_add_func ("/repository-search-paths/prepend", test_repository_search_paths_prepend);
g_test_add_func ("/repository/search-paths/unset", test_repository_search_paths_unset);
g_test_add_func ("/repository/search-paths/default", test_repository_search_paths_default);
g_test_add_func ("/repository/search-paths/prepend", test_repository_search_paths_prepend);
g_test_add_func ("/repository/library-paths/default", test_repository_library_paths_default);
g_test_add_func ("/repository/library-paths/prepend", test_repository_library_paths_prepend);
return g_test_run ();
}