Branch data Line data Source code
1 : : /* 2 : : * Copyright 2023 GNOME Foundation, Inc. 3 : : * Copyright 2024 Philip Chimento <philip.chimento@gmail.com> 4 : : * 5 : : * SPDX-License-Identifier: LGPL-2.1-or-later 6 : : * 7 : : * This library is free software; you can redistribute it and/or 8 : : * modify it under the terms of the GNU Lesser General Public 9 : : * License as published by the Free Software Foundation; either 10 : : * version 2.1 of the License, or (at your option) any later version. 11 : : * 12 : : * This library is distributed in the hope that it will be useful, 13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 : : * Lesser General Public License for more details. 16 : : * 17 : : * You should have received a copy of the GNU Lesser General 18 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. 19 : : */ 20 : : 21 : : #include "config.h" 22 : : 23 : : #include "girepository.h" 24 : : #include "glib.h" 25 : : #include "test-common.h" 26 : : 27 : : void 28 : 8 : repository_init (int *argc, 29 : : char **argv[]) 30 : : { 31 : : /* Isolate from the system typelibs and GIRs. */ 32 : 8 : g_setenv ("GI_TYPELIB_PATH", "/dev/null", TRUE); 33 : 8 : g_setenv ("GI_GIR_PATH", "/dev/null", TRUE); 34 : : 35 : 8 : g_test_init (argc, argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); 36 : 8 : } 37 : : 38 : : void 39 : 58 : repository_setup (RepositoryFixture *fx, 40 : : const void *data) 41 : : { 42 : 58 : GITypelib *typelib = NULL; 43 : 58 : GError *local_error = NULL; 44 : 58 : TypelibLoadSpec *load_spec = (TypelibLoadSpec *) data; 45 : : 46 : 58 : fx->repository = gi_repository_new (); 47 : 58 : g_assert_nonnull (fx->repository); 48 : : 49 : 58 : fx->gobject_typelib_dir = g_test_build_filename (G_TEST_BUILT, "..", "introspection", NULL); 50 : 58 : g_test_message ("Using GI_TYPELIB_DIR = %s", fx->gobject_typelib_dir); 51 : 58 : gi_repository_prepend_search_path (fx->repository, fx->gobject_typelib_dir); 52 : : 53 [ + - ]: 58 : if (load_spec) 54 : : { 55 : 58 : typelib = gi_repository_require (fx->repository, load_spec->name, load_spec->version, 0, &local_error); 56 : 58 : g_assert_no_error (local_error); 57 : 58 : g_assert_nonnull (typelib); 58 : : } 59 : 58 : } 60 : : 61 : : void 62 : 58 : repository_teardown (RepositoryFixture *fx, 63 : : const void *unused) 64 : : { 65 : 58 : g_clear_pointer (&fx->gobject_typelib_dir, g_free); 66 : 58 : g_clear_object (&fx->repository); 67 : 58 : }