girepository: add default search paths tests for relocations

This commit is contained in:
Andoni Morales Alastruey 2024-05-28 17:33:17 +02:00
parent 9d0988ca62
commit c93c4d41e8

View File

@ -22,6 +22,23 @@
#include "glib.h" #include "glib.h"
#include "girepository.h" #include "girepository.h"
static char *
test_repository_search_paths_get_expected_libdir_path (void)
{
#if defined(G_PLATFORM_WIN32)
const char *tests_build_dir = g_getenv ("G_TEST_BUILDDIR");
char *expected_rel_path = g_build_filename (tests_build_dir, "lib", "girepository-1.0", NULL);
#elif defined(__APPLE__)
const char *tests_build_dir = g_getenv ("G_TEST_BUILDDIR");
char *expected_rel_path = g_build_filename (tests_build_dir, "..", "girepository-1.0", NULL);
#else /* !G_PLATFORM_WIN32 && !__APPLE__ */
char *expected_rel_path = g_build_filename (GOBJECT_INTROSPECTION_LIBDIR, "girepository-1.0", NULL);
#endif
char *expected_path = g_canonicalize_filename (expected_rel_path, NULL);
g_clear_pointer (&expected_rel_path, g_free);
return expected_path;
}
static void static void
test_repository_search_paths_default (void) test_repository_search_paths_default (void)
{ {
@ -37,11 +54,9 @@ test_repository_search_paths_default (void)
g_assert_cmpstr (search_paths[0], ==, g_get_tmp_dir ()); g_assert_cmpstr (search_paths[0], ==, g_get_tmp_dir ());
#ifndef G_PLATFORM_WIN32 char *expected_path = test_repository_search_paths_get_expected_libdir_path ();
char *expected_path = g_build_filename (GOBJECT_INTROSPECTION_LIBDIR, "girepository-1.0", NULL);
g_assert_cmpstr (search_paths[1], ==, expected_path); g_assert_cmpstr (search_paths[1], ==, expected_path);
g_clear_pointer (&expected_path, g_free); g_clear_pointer (&expected_path, g_free);
#endif
g_clear_object (&repository); g_clear_object (&repository);
} }
@ -63,11 +78,9 @@ test_repository_search_paths_prepend (void)
g_assert_cmpstr (search_paths[0], ==, g_test_get_dir (G_TEST_BUILT)); g_assert_cmpstr (search_paths[0], ==, g_test_get_dir (G_TEST_BUILT));
g_assert_cmpstr (search_paths[1], ==, g_get_tmp_dir ()); g_assert_cmpstr (search_paths[1], ==, g_get_tmp_dir ());
#ifndef G_PLATFORM_WIN32 char *expected_path = test_repository_search_paths_get_expected_libdir_path ();
char *expected_path = g_build_filename (GOBJECT_INTROSPECTION_LIBDIR, "girepository-1.0", NULL);
g_assert_cmpstr (search_paths[2], ==, expected_path); g_assert_cmpstr (search_paths[2], ==, expected_path);
g_clear_pointer (&expected_path, g_free); g_clear_pointer (&expected_path, g_free);
#endif
gi_repository_prepend_search_path (repository, g_test_get_dir (G_TEST_DIST)); gi_repository_prepend_search_path (repository, g_test_get_dir (G_TEST_DIST));
search_paths = gi_repository_get_search_path (repository, &n_search_paths); search_paths = gi_repository_get_search_path (repository, &n_search_paths);
@ -78,11 +91,9 @@ test_repository_search_paths_prepend (void)
g_assert_cmpstr (search_paths[1], ==, g_test_get_dir (G_TEST_BUILT)); g_assert_cmpstr (search_paths[1], ==, g_test_get_dir (G_TEST_BUILT));
g_assert_cmpstr (search_paths[2], ==, g_get_tmp_dir ()); g_assert_cmpstr (search_paths[2], ==, g_get_tmp_dir ());
#ifndef G_PLATFORM_WIN32 expected_path = test_repository_search_paths_get_expected_libdir_path ();
expected_path = g_build_filename (GOBJECT_INTROSPECTION_LIBDIR, "girepository-1.0", NULL);
g_assert_cmpstr (search_paths[3], ==, expected_path); g_assert_cmpstr (search_paths[3], ==, expected_path);
g_clear_pointer (&expected_path, g_free); g_clear_pointer (&expected_path, g_free);
#endif
g_clear_object (&repository); g_clear_object (&repository);
} }