LCOV - code coverage report
Current view: top level - girepository/tests - repository.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 100.0 % 530 530
Test Date: 2025-06-17 11:50:15 Functions: 100.0 % 25 25
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2008-2011 Colin Walters <walters@verbum.org>
       3                 :             :  * Copyright 2011 Laszlo Pandy <lpandy@src.gnome.org>
       4                 :             :  * Copyright 2011 Torsten Schönfeld <kaffeetisch@gmx.de>
       5                 :             :  * Copyright 2011, 2012 Pavel Holejsovsky <pavel.holejsovsky@gmail.com>
       6                 :             :  * Copyright 2013 Martin Pitt <martinpitt@gnome.org>
       7                 :             :  * Copyright 2014 Giovanni Campagna <gcampagna@src.gnome.org>
       8                 :             :  * Copyright 2018 Christoph Reiter
       9                 :             :  * Copyright 2019, 2024 Philip Chimento <philip.chimento@gmail.com>
      10                 :             :  * Copyright 2022 Emmanuele Bassi <ebassi@gnome.org>
      11                 :             :  * Copyright 2023 GNOME Foundation, Inc.
      12                 :             :  *
      13                 :             :  * SPDX-License-Identifier: LGPL-2.1-or-later
      14                 :             :  *
      15                 :             :  * This library is free software; you can redistribute it and/or
      16                 :             :  * modify it under the terms of the GNU Lesser General Public
      17                 :             :  * License as published by the Free Software Foundation; either
      18                 :             :  * version 2.1 of the License, or (at your option) any later version.
      19                 :             :  *
      20                 :             :  * This library is distributed in the hope that it will be useful,
      21                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      22                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      23                 :             :  * Lesser General Public License for more details.
      24                 :             :  *
      25                 :             :  * You should have received a copy of the GNU Lesser General
      26                 :             :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      27                 :             :  *
      28                 :             :  * Author: Philip Withnall <pwithnall@gnome.org>
      29                 :             :  */
      30                 :             : 
      31                 :             : #include "config.h"
      32                 :             : 
      33                 :             : #include "gio.h"
      34                 :             : #include "girepository.h"
      35                 :             : #include "glib.h"
      36                 :             : #include "test-common.h"
      37                 :             : 
      38                 :             : #if defined(G_OS_UNIX) && !defined(__APPLE__)
      39                 :             : #include "gio/gdesktopappinfo.h"
      40                 :             : #elif defined(G_OS_WIN32)
      41                 :             : #include "gio/gwin32inputstream.h"
      42                 :             : #endif
      43                 :             : 
      44                 :             : static void
      45                 :           1 : test_repository_basic (RepositoryFixture *fx,
      46                 :             :                        const void *unused)
      47                 :             : {
      48                 :             :   const char * const * search_paths;
      49                 :           1 :   char **namespaces = NULL;
      50                 :             :   size_t n_namespaces;
      51                 :           1 :   const char *expected_namespaces[] = { "GLib", NULL };
      52                 :             :   char **versions;
      53                 :             :   size_t n_versions;
      54                 :           1 :   const char *prefix = NULL;
      55                 :             : 
      56                 :           1 :   g_test_summary ("Test basic opening of a repository and requiring a typelib");
      57                 :             : 
      58                 :           1 :   versions = gi_repository_enumerate_versions (fx->repository, "SomeInvalidNamespace", &n_versions);
      59                 :           1 :   g_assert_nonnull (versions);
      60                 :           1 :   g_assert_cmpstrv (versions, ((char *[]){NULL}));
      61                 :           1 :   g_assert_cmpuint (n_versions, ==, 0);
      62                 :           1 :   g_clear_pointer (&versions, g_strfreev);
      63                 :             : 
      64                 :           1 :   versions = gi_repository_enumerate_versions (fx->repository, "GLib", NULL);
      65                 :           1 :   g_assert_nonnull (versions);
      66                 :           2 :   g_assert_cmpstrv (versions, ((char *[]){"2.0", NULL}));
      67                 :           1 :   g_clear_pointer (&versions, g_strfreev);
      68                 :             : 
      69                 :           1 :   search_paths = gi_repository_get_search_path (fx->repository, NULL);
      70                 :           1 :   g_assert_nonnull (search_paths);
      71                 :           1 :   g_assert_cmpuint (g_strv_length ((char **) search_paths), >, 0);
      72                 :           1 :   g_assert_cmpstr (search_paths[0], ==, fx->gobject_typelib_dir);
      73                 :             : 
      74                 :           1 :   namespaces = gi_repository_get_loaded_namespaces (fx->repository, &n_namespaces);
      75                 :           2 :   g_assert_cmpstrv (namespaces, expected_namespaces);
      76                 :           1 :   g_assert_cmpuint (n_namespaces, ==, g_strv_length ((char **) expected_namespaces));
      77                 :           1 :   g_strfreev (namespaces);
      78                 :             : 
      79                 :           1 :   prefix = gi_repository_get_c_prefix (fx->repository, "GLib");
      80                 :           1 :   g_assert_nonnull (prefix);
      81                 :           1 :   g_assert_cmpstr (prefix, ==, "G");
      82                 :           1 : }
      83                 :             : 
      84                 :             : static void
      85                 :           1 : test_repository_info (RepositoryFixture *fx,
      86                 :             :                       const void *unused)
      87                 :             : {
      88                 :           1 :   GIBaseInfo *not_found_info = NULL;
      89                 :           1 :   GIObjectInfo *object_info = NULL, *object_info_by_gtype = NULL;
      90                 :           1 :   GISignalInfo *signal_info = NULL;
      91                 :           1 :   GIFunctionInfo *method_info = NULL;
      92                 :             :   GType gtype;
      93                 :             : 
      94                 :           1 :   g_test_summary ("Test retrieving some basic info blobs from a typelib");
      95                 :             : 
      96                 :           1 :   not_found_info = gi_repository_find_by_name (fx->repository, "GObject", "ThisDoesNotExist");
      97                 :           1 :   g_assert_null (not_found_info);
      98                 :             : 
      99                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     100                 :           1 :   g_assert_nonnull (object_info);
     101                 :           1 :   g_assert_true (GI_IS_OBJECT_INFO (object_info));
     102                 :           1 :   g_assert_true (GI_IS_REGISTERED_TYPE_INFO (object_info));
     103                 :           1 :   g_assert_true (GI_IS_BASE_INFO (object_info));
     104                 :             : 
     105                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
     106                 :           1 :   g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, "GObject");
     107                 :             : 
     108                 :           1 :   gtype = gi_registered_type_info_get_g_type (GI_REGISTERED_TYPE_INFO (object_info));
     109                 :           1 :   g_assert_true (g_type_is_a (gtype, G_TYPE_OBJECT));
     110                 :             : 
     111                 :           1 :   object_info_by_gtype = GI_OBJECT_INFO (gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT));
     112                 :           1 :   g_assert_nonnull (object_info);
     113                 :             : 
     114                 :           1 :   signal_info = gi_object_info_find_signal (object_info, "does-not-exist");
     115                 :           1 :   g_assert_null (signal_info);
     116                 :             : 
     117                 :           1 :   signal_info = gi_object_info_find_signal (object_info, "notify");
     118                 :           1 :   g_assert_nonnull (signal_info);
     119                 :           1 :   g_assert_true (GI_IS_SIGNAL_INFO (signal_info));
     120                 :           1 :   g_assert_true (GI_IS_CALLABLE_INFO (signal_info));
     121                 :           1 :   g_assert_true (GI_IS_BASE_INFO (signal_info));
     122                 :             : 
     123                 :           1 :   g_assert_cmpint (gi_signal_info_get_flags (signal_info), ==,
     124                 :             :                    G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS | G_SIGNAL_ACTION);
     125                 :             : 
     126                 :           1 :   g_assert_cmpuint (gi_object_info_get_n_methods (object_info), >, 2);
     127                 :             : 
     128                 :           1 :   method_info = gi_object_info_find_method (object_info, "get_property");
     129                 :           1 :   g_assert_nonnull (method_info);
     130                 :           1 :   g_assert_true (GI_IS_FUNCTION_INFO (method_info));
     131                 :           1 :   g_assert_true (GI_IS_CALLABLE_INFO (method_info));
     132                 :           1 :   g_assert_true (GI_IS_BASE_INFO (method_info));
     133                 :             : 
     134                 :           1 :   g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (method_info)));
     135                 :           1 :   g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (method_info)), ==, 2);
     136                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     137                 :             : 
     138                 :           1 :   method_info = gi_object_info_get_method (object_info,
     139                 :           1 :                                            gi_object_info_get_n_methods (object_info) - 1);
     140                 :           1 :   g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (method_info)));
     141                 :           1 :   g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (method_info)), >, 0);
     142                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     143                 :             : 
     144                 :           1 :   gi_base_info_unref (signal_info);
     145                 :           1 :   gi_base_info_unref (object_info);
     146                 :           1 :   gi_base_info_unref (object_info_by_gtype);
     147                 :           1 : }
     148                 :             : 
     149                 :             : static void
     150                 :           1 : test_repository_dependencies (RepositoryFixture *fx,
     151                 :             :                               const void *unused)
     152                 :             : {
     153                 :           1 :   GError *error = NULL;
     154                 :             :   char **dependencies;
     155                 :             :   size_t n_dependencies;
     156                 :             : 
     157                 :           1 :   g_test_summary ("Test ensures namespace dependencies are correctly exposed");
     158                 :             : 
     159                 :           1 :   dependencies = gi_repository_get_dependencies (fx->repository, "GObject", &n_dependencies);
     160                 :           1 :   g_assert_cmpuint (g_strv_length (dependencies), ==, 1);
     161                 :           1 :   g_assert_cmpuint (n_dependencies, ==, 1);
     162                 :           1 :   g_assert_true (g_strv_contains ((const char **) dependencies, "GLib-2.0"));
     163                 :             : 
     164                 :           1 :   g_clear_error (&error);
     165                 :           1 :   g_clear_pointer (&dependencies, g_strfreev);
     166                 :           1 : }
     167                 :             : 
     168                 :             : static void
     169                 :           1 : test_repository_base_info_clear (RepositoryFixture *fx,
     170                 :             :                                  const void        *unused)
     171                 :             : {
     172                 :           1 :   GITypeInfo zeroed_type_info = { 0, };
     173                 :             :   GITypeInfo idempotent_type_info;
     174                 :           1 :   GIObjectInfo *object_info = NULL;
     175                 :           1 :   GIFunctionInfo *method_info = NULL;
     176                 :           1 :   GIArgInfo *arg_info = NULL;
     177                 :             : 
     178                 :           1 :   g_test_summary ("Test calling gi_base_info_clear() on a zero-filled struct");
     179                 :             : 
     180                 :             :   /* Load a valid #GITypeInfo onto the stack and clear it multiple times to
     181                 :             :    * check gi_base_info_clear() is idempotent after the first call. */
     182                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     183                 :           1 :   g_assert_nonnull (object_info);
     184                 :           1 :   method_info = gi_object_info_find_method (object_info, "get_property");
     185                 :           1 :   g_assert_nonnull (method_info);
     186                 :           1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
     187                 :           1 :   g_assert_nonnull (arg_info);
     188                 :           1 :   gi_arg_info_load_type_info (arg_info, &idempotent_type_info);
     189                 :             : 
     190                 :           1 :   gi_base_info_clear (&idempotent_type_info);
     191                 :           1 :   gi_base_info_clear (&idempotent_type_info);
     192                 :           1 :   gi_base_info_clear (&idempotent_type_info);
     193                 :             : 
     194                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     195                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     196                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     197                 :             : 
     198                 :             :   /* Try clearing a #GITypeInfo which has always been zero-filled on the stack. */
     199                 :           1 :   gi_base_info_clear (&zeroed_type_info);
     200                 :           1 :   gi_base_info_clear (&zeroed_type_info);
     201                 :           1 :   gi_base_info_clear (&zeroed_type_info);
     202                 :           1 : }
     203                 :             : 
     204                 :             : static void
     205                 :           1 : test_repository_arg_info (RepositoryFixture *fx,
     206                 :             :                           const void *unused)
     207                 :             : {
     208                 :           1 :   GIObjectInfo *object_info = NULL;
     209                 :           1 :   GIStructInfo *struct_info = NULL;
     210                 :           1 :   GIFunctionInfo *method_info = NULL;
     211                 :           1 :   GIArgInfo *arg_info = NULL;
     212                 :           1 :   GITypeInfo *type_info = NULL;
     213                 :             :   GITypeInfo type_info_stack;
     214                 :             :   unsigned int idx;
     215                 :             : 
     216                 :           1 :   g_test_summary ("Test retrieving GIArgInfos from a typelib");
     217                 :             : 
     218                 :             :   /* Test all the methods of GIArgInfo. Here we’re looking at the
     219                 :             :    * `const char *property_name` argument of g_object_get_property(). (The
     220                 :             :    * ‘self’ argument is not exposed through gi_callable_info_get_arg().) */
     221                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     222                 :           1 :   g_assert_nonnull (object_info);
     223                 :             : 
     224                 :           1 :   method_info = gi_object_info_find_method (object_info, "get_property");
     225                 :           1 :   g_assert_nonnull (method_info);
     226                 :             : 
     227                 :           1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
     228                 :           1 :   g_assert_nonnull (arg_info);
     229                 :             : 
     230                 :           1 :   g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_IN);
     231                 :           1 :   g_assert_false (gi_arg_info_is_return_value (arg_info));
     232                 :           1 :   g_assert_false (gi_arg_info_is_optional (arg_info));
     233                 :           1 :   g_assert_false (gi_arg_info_is_caller_allocates (arg_info));
     234                 :           1 :   g_assert_false (gi_arg_info_may_be_null (arg_info));
     235                 :           1 :   g_assert_false (gi_arg_info_is_skip (arg_info));
     236                 :           1 :   g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_NOTHING);
     237                 :           1 :   g_assert_cmpint (gi_arg_info_get_scope (arg_info), ==, GI_SCOPE_TYPE_INVALID);
     238                 :           1 :   g_assert_false (gi_arg_info_get_closure_index (arg_info, NULL));
     239                 :           1 :   g_assert_false (gi_arg_info_get_closure_index (arg_info, &idx));
     240                 :           1 :   g_assert_cmpuint (idx, ==, 0);
     241                 :           1 :   g_assert_false (gi_arg_info_get_destroy_index (arg_info, NULL));
     242                 :           1 :   g_assert_false (gi_arg_info_get_destroy_index (arg_info, &idx));
     243                 :           1 :   g_assert_cmpuint (idx, ==, 0);
     244                 :             : 
     245                 :           1 :   type_info = gi_arg_info_get_type_info (arg_info);
     246                 :           1 :   g_assert_nonnull (type_info);
     247                 :           1 :   g_assert_true (gi_type_info_is_pointer (type_info));
     248                 :           1 :   g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UTF8);
     249                 :             : 
     250                 :           1 :   gi_arg_info_load_type_info (arg_info, &type_info_stack);
     251                 :           1 :   g_assert_true (gi_type_info_is_pointer (&type_info_stack) == gi_type_info_is_pointer (type_info));
     252                 :           1 :   g_assert_cmpint (gi_type_info_get_tag (&type_info_stack), ==, gi_type_info_get_tag (type_info));
     253                 :             : 
     254                 :           1 :   gi_base_info_clear (&type_info_stack);
     255                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     256                 :             : 
     257                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     258                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     259                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     260                 :             : 
     261                 :             :   /* Test an (out) argument. Here it’s the `guint *n_properties` from
     262                 :             :    * g_object_class_list_properties(). */
     263                 :           1 :   struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ObjectClass"));
     264                 :           1 :   g_assert_nonnull (struct_info);
     265                 :             : 
     266                 :           1 :   method_info = gi_struct_info_find_method (struct_info, "list_properties");
     267                 :           1 :   g_assert_nonnull (method_info);
     268                 :             : 
     269                 :           1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
     270                 :           1 :   g_assert_nonnull (arg_info);
     271                 :             : 
     272                 :           1 :   g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_OUT);
     273                 :           1 :   g_assert_false (gi_arg_info_is_optional (arg_info));
     274                 :           1 :   g_assert_false (gi_arg_info_is_caller_allocates (arg_info));
     275                 :           1 :   g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_EVERYTHING);
     276                 :             : 
     277                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     278                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     279                 :           1 :   g_clear_pointer (&struct_info, gi_base_info_unref);
     280                 :           1 : }
     281                 :             : 
     282                 :             : static void
     283                 :           1 : test_repository_callable_info (RepositoryFixture *fx,
     284                 :             :                                const void *unused)
     285                 :             : {
     286                 :           1 :   GIObjectInfo *object_info = NULL;
     287                 :           1 :   GIFunctionInfo *method_info = NULL;
     288                 :             :   GICallableInfo *callable_info;
     289                 :           1 :   GITypeInfo *type_info = NULL;
     290                 :             :   GITypeInfo type_info_stack;
     291                 :           1 :   GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
     292                 :             :   const char *name, *value;
     293                 :           1 :   GIArgInfo *arg_info = NULL;
     294                 :             :   GIArgInfo arg_info_stack;
     295                 :             : 
     296                 :           1 :   g_test_summary ("Test retrieving GICallableInfos from a typelib");
     297                 :             : 
     298                 :             :   /* Test all the methods of GICallableInfo. Here we’re looking at
     299                 :             :    * g_object_get_qdata(). */
     300                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     301                 :           1 :   g_assert_nonnull (object_info);
     302                 :             : 
     303                 :           1 :   method_info = gi_object_info_find_method (object_info, "get_qdata");
     304                 :           1 :   g_assert_nonnull (method_info);
     305                 :             : 
     306                 :           1 :   callable_info = GI_CALLABLE_INFO (method_info);
     307                 :             : 
     308                 :           1 :   g_assert_true (gi_callable_info_is_method (callable_info));
     309                 :           1 :   g_assert_false (gi_callable_info_can_throw_gerror (callable_info));
     310                 :             : 
     311                 :           1 :   type_info = gi_callable_info_get_return_type (callable_info);
     312                 :           1 :   g_assert_nonnull (type_info);
     313                 :           1 :   g_assert_true (gi_type_info_is_pointer (type_info));
     314                 :           1 :   g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_VOID);
     315                 :             : 
     316                 :           1 :   gi_callable_info_load_return_type (callable_info, &type_info_stack);
     317                 :           1 :   g_assert_true (gi_type_info_is_pointer (&type_info_stack) == gi_type_info_is_pointer (type_info));
     318                 :           1 :   g_assert_cmpint (gi_type_info_get_tag (&type_info_stack), ==, gi_type_info_get_tag (type_info));
     319                 :             : 
     320                 :           1 :   gi_base_info_clear (&type_info_stack);
     321                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     322                 :             : 
     323                 :             :   /* This method has no attributes */
     324                 :           1 :   g_assert_false (gi_callable_info_iterate_return_attributes (callable_info, &iter, &name, &value));
     325                 :             : 
     326                 :           1 :   g_assert_null (gi_callable_info_get_return_attribute (callable_info, "doesnt-exist"));
     327                 :             : 
     328                 :           1 :   g_assert_false (gi_callable_info_get_caller_owns (callable_info));
     329                 :           1 :   g_assert_true (gi_callable_info_may_return_null (callable_info));
     330                 :           1 :   g_assert_false (gi_callable_info_skip_return (callable_info));
     331                 :             : 
     332                 :           1 :   g_assert_cmpuint (gi_callable_info_get_n_args (callable_info), ==, 1);
     333                 :             : 
     334                 :           1 :   arg_info = gi_callable_info_get_arg (callable_info, 0);
     335                 :           1 :   g_assert_nonnull (arg_info);
     336                 :             : 
     337                 :           1 :   gi_callable_info_load_arg (callable_info, 0, &arg_info_stack);
     338                 :           1 :   g_assert_cmpint (gi_arg_info_get_direction (&arg_info_stack), ==, gi_arg_info_get_direction (arg_info));
     339                 :           1 :   g_assert_true (gi_arg_info_may_be_null (&arg_info_stack) == gi_arg_info_may_be_null (arg_info));
     340                 :             : 
     341                 :           1 :   gi_base_info_clear (&arg_info_stack);
     342                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     343                 :             : 
     344                 :           1 :   g_assert_cmpint (gi_callable_info_get_instance_ownership_transfer (callable_info), ==, GI_TRANSFER_NOTHING);
     345                 :             : 
     346                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     347                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     348                 :           1 : }
     349                 :             : 
     350                 :             : static void
     351                 :           1 : test_repository_callback_info (RepositoryFixture *fx,
     352                 :             :                                const void *unused)
     353                 :             : {
     354                 :           1 :   GICallbackInfo *callback_info = NULL;
     355                 :             : 
     356                 :           1 :   g_test_summary ("Test retrieving GICallbackInfos from a typelib");
     357                 :             : 
     358                 :             :   /* Test all the methods of GICallbackInfo. This is simple, because there are none. */
     359                 :           1 :   callback_info = GI_CALLBACK_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ObjectFinalizeFunc"));
     360                 :           1 :   g_assert_nonnull (callback_info);
     361                 :             : 
     362                 :           1 :   g_clear_pointer (&callback_info, gi_base_info_unref);
     363                 :           1 : }
     364                 :             : 
     365                 :             : static void
     366                 :           1 : test_repository_char_types (RepositoryFixture *fx,
     367                 :             :                             const void *unused)
     368                 :             : {
     369                 :             :   GIStructInfo *gvalue_info;
     370                 :             :   GIFunctionInfo *method_info;
     371                 :             :   GITypeInfo *type_info;
     372                 :             : 
     373                 :           1 :   g_test_summary ("Test that signed and unsigned char GITypeInfo have GITypeTag of INT8 and UINT8 respectively");
     374                 :             : 
     375                 :           1 :   gvalue_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Value"));
     376                 :           1 :   g_assert_nonnull (gvalue_info);
     377                 :             : 
     378                 :             :   /* unsigned char */
     379                 :           1 :   method_info = gi_struct_info_find_method (gvalue_info, "get_uchar");
     380                 :           1 :   g_assert_nonnull (method_info);
     381                 :             : 
     382                 :           1 :   type_info = gi_callable_info_get_return_type (GI_CALLABLE_INFO (method_info));
     383                 :           1 :   g_assert_nonnull (type_info);
     384                 :           1 :   g_assert_cmpuint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UINT8);
     385                 :             : 
     386                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     387                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     388                 :             : 
     389                 :             :   /* signed char */
     390                 :           1 :   method_info = gi_struct_info_find_method (gvalue_info, "get_schar");
     391                 :           1 :   g_assert_nonnull (method_info);
     392                 :             : 
     393                 :           1 :   type_info = gi_callable_info_get_return_type (GI_CALLABLE_INFO (method_info));
     394                 :           1 :   g_assert_nonnull (type_info);
     395                 :           1 :   g_assert_cmpuint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_INT8);
     396                 :             : 
     397                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     398                 :           1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     399                 :           1 :   g_clear_pointer (&gvalue_info, gi_base_info_unref);
     400                 :           1 : }
     401                 :             : 
     402                 :             : static void
     403                 :           1 : test_repository_constructor_return_type (RepositoryFixture *fx,
     404                 :             :                                          const void *unused)
     405                 :             : {
     406                 :           1 :   GIObjectInfo *object_info = NULL;
     407                 :           1 :   GIFunctionInfo *constructor = NULL;
     408                 :           1 :   GITypeInfo *return_type = NULL;
     409                 :           1 :   GIBaseInfo *return_info = NULL;
     410                 :           1 :   const char *class_name = NULL;
     411                 :           1 :   const char *return_name = NULL;
     412                 :             : 
     413                 :           1 :   g_test_summary ("Test the return type of a constructor, g_object_newv()");
     414                 :             : 
     415                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     416                 :           1 :   g_assert_nonnull (object_info);
     417                 :             : 
     418                 :           1 :   class_name = gi_registered_type_info_get_type_name (GI_REGISTERED_TYPE_INFO (object_info));
     419                 :           1 :   g_assert_nonnull (class_name);
     420                 :             : 
     421                 :           1 :   constructor = gi_object_info_find_method (object_info, "newv");
     422                 :           1 :   g_assert_nonnull (constructor);
     423                 :             : 
     424                 :           1 :   return_type = gi_callable_info_get_return_type (GI_CALLABLE_INFO (constructor));
     425                 :           1 :   g_assert_nonnull (return_type);
     426                 :           1 :   g_assert_cmpuint (gi_type_info_get_tag (return_type), ==, GI_TYPE_TAG_INTERFACE);
     427                 :             : 
     428                 :           1 :   return_info = gi_type_info_get_interface (return_type);
     429                 :           1 :   g_assert_nonnull (return_info);
     430                 :             : 
     431                 :           1 :   return_name = gi_registered_type_info_get_type_name (GI_REGISTERED_TYPE_INFO (return_info));
     432                 :           1 :   g_assert_nonnull (return_name);
     433                 :           1 :   g_assert_cmpstr (class_name, ==, return_name);
     434                 :             : 
     435                 :           1 :   g_clear_pointer (&return_info, gi_base_info_unref);
     436                 :           1 :   g_clear_pointer (&return_type, gi_base_info_unref);
     437                 :           1 :   g_clear_pointer (&constructor, gi_base_info_unref);
     438                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     439                 :           1 : }
     440                 :             : 
     441                 :             : static void
     442                 :           1 : test_repository_enum_info_c_identifier (RepositoryFixture *fx,
     443                 :             :                                         const void *unused)
     444                 :             : {
     445                 :           1 :   GIBaseInfo *info = NULL;
     446                 :           1 :   GIValueInfo *value_info = NULL;
     447                 :             :   unsigned n_infos, n_values, ix, jx;
     448                 :           1 :   const char *c_identifier = NULL;
     449                 :             : 
     450                 :           1 :   g_test_summary ("Test that every enum member has a C identifier");
     451                 :             : 
     452                 :           1 :   n_infos = gi_repository_get_n_infos (fx->repository, "GLib");
     453                 :             : 
     454                 :         981 :   for (ix = 0; ix < n_infos; ix++)
     455                 :             :     {
     456                 :         980 :       info = gi_repository_get_info (fx->repository, "GLib", ix);
     457                 :             : 
     458                 :         980 :       if (GI_IS_ENUM_INFO (info))
     459                 :             :         {
     460                 :          61 :           n_values = gi_enum_info_get_n_values (GI_ENUM_INFO (info));
     461                 :         806 :           for (jx = 0; jx < n_values; jx++)
     462                 :             :             {
     463                 :         745 :               value_info = gi_enum_info_get_value (GI_ENUM_INFO (info), jx);
     464                 :         745 :               c_identifier = gi_base_info_get_attribute (GI_BASE_INFO (value_info), "c:identifier");
     465                 :         745 :               g_assert_nonnull (c_identifier);
     466                 :             : 
     467                 :         745 :               g_clear_pointer (&value_info, gi_base_info_unref);
     468                 :             :             }
     469                 :             :         }
     470                 :             : 
     471                 :         980 :       g_clear_pointer (&info, gi_base_info_unref);
     472                 :             :     }
     473                 :           1 : }
     474                 :             : 
     475                 :             : static void
     476                 :           1 : test_repository_enum_info_static_methods (RepositoryFixture *fx,
     477                 :             :                                           const void *unused)
     478                 :             : {
     479                 :           1 :   GIEnumInfo *enum_info = NULL;
     480                 :             :   unsigned n_methods, ix;
     481                 :           1 :   GIFunctionInfo *function_info = NULL;
     482                 :             :   GIFunctionInfoFlags flags;
     483                 :           1 :   const char *symbol = NULL;
     484                 :             : 
     485                 :           1 :   g_test_summary ("Test an enum with methods");
     486                 :             : 
     487                 :           1 :   enum_info = GI_ENUM_INFO (gi_repository_find_by_name (fx->repository, "GLib", "UnicodeScript"));
     488                 :           1 :   g_assert_nonnull (enum_info);
     489                 :             : 
     490                 :           1 :   n_methods = gi_enum_info_get_n_methods (enum_info);
     491                 :           1 :   g_assert_cmpuint (n_methods, >, 0);
     492                 :             : 
     493                 :           3 :   for (ix = 0; ix < n_methods; ix++)
     494                 :             :     {
     495                 :           2 :       function_info = gi_enum_info_get_method (enum_info, ix);
     496                 :           2 :       g_assert_nonnull (function_info);
     497                 :             : 
     498                 :           2 :       flags = gi_function_info_get_flags (function_info);
     499                 :           2 :       g_assert_false (flags & GI_FUNCTION_IS_METHOD); /* must be static */
     500                 :             : 
     501                 :           2 :       symbol = gi_function_info_get_symbol (function_info);
     502                 :           2 :       g_assert_nonnull (symbol);
     503                 :           2 :       g_assert_true (g_str_has_prefix (symbol, "g_unicode_script_"));
     504                 :             : 
     505                 :           2 :       g_clear_pointer (&function_info, gi_base_info_unref);
     506                 :             :     }
     507                 :             : 
     508                 :           1 :   g_clear_pointer (&enum_info, gi_base_info_unref);
     509                 :           1 : }
     510                 :             : 
     511                 :             : static void
     512                 :           1 : test_repository_error_quark (RepositoryFixture *fx,
     513                 :             :                              const void *unused)
     514                 :             : {
     515                 :           1 :   GIEnumInfo *error_info = NULL;
     516                 :             : 
     517                 :           1 :   g_test_summary ("Test finding an error quark by error domain");
     518                 :             : 
     519                 :             :   /* Find a simple error domain. */
     520                 :           1 :   error_info = gi_repository_find_by_error_domain (fx->repository, G_RESOLVER_ERROR);
     521                 :           1 :   g_assert_nonnull (error_info);
     522                 :           1 :   g_assert_true (GI_IS_ENUM_INFO (error_info));
     523                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (error_info)), ==, "ResolverError");
     524                 :             : 
     525                 :           1 :   g_clear_pointer (&error_info, gi_base_info_unref);
     526                 :             : 
     527                 :             :   /* Find again to check the caching. */
     528                 :           1 :   error_info = gi_repository_find_by_error_domain (fx->repository, G_RESOLVER_ERROR);
     529                 :           1 :   g_assert_nonnull (error_info);
     530                 :           1 :   g_assert_true (GI_IS_ENUM_INFO (error_info));
     531                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (error_info)), ==, "ResolverError");
     532                 :             : 
     533                 :           1 :   g_clear_pointer (&error_info, gi_base_info_unref);
     534                 :             : 
     535                 :             :   /* Try and find an unknown error domain. */
     536                 :           1 :   g_assert_null (gi_repository_find_by_error_domain (fx->repository, GI_REPOSITORY_ERROR));
     537                 :             : 
     538                 :             :   /* And check caching for unknown error domains. */
     539                 :           1 :   g_assert_null (gi_repository_find_by_error_domain (fx->repository, GI_REPOSITORY_ERROR));
     540                 :             : 
     541                 :             :   /* It would be good to try and find one which will resolve in both Gio and
     542                 :             :    * GioUnix/GioWin32, but neither of the platform-specific GIRs actually define
     543                 :             :    * any error domains at the moment. */
     544                 :           1 : }
     545                 :             : 
     546                 :             : static void
     547                 :           1 : test_repository_flags_info_c_identifier (RepositoryFixture *fx,
     548                 :             :                                          const void *unused)
     549                 :             : {
     550                 :           1 :   GIBaseInfo *info = NULL;
     551                 :           1 :   GIValueInfo *value_info = NULL;
     552                 :             :   unsigned n_infos, n_values, ix, jx;
     553                 :           1 :   const char *c_identifier = NULL;
     554                 :             : 
     555                 :           1 :   g_test_summary ("Test that every flags member has a C identifier");
     556                 :             : 
     557                 :           1 :   n_infos = gi_repository_get_n_infos (fx->repository, "GLib");
     558                 :             : 
     559                 :         981 :   for (ix = 0; ix < n_infos; ix++)
     560                 :             :     {
     561                 :         980 :       info = gi_repository_get_info (fx->repository, "GLib", ix);
     562                 :             : 
     563                 :         980 :       if (GI_IS_FLAGS_INFO (info))
     564                 :             :         {
     565                 :          22 :           n_values = gi_enum_info_get_n_values (GI_ENUM_INFO (info));
     566                 :         183 :           for (jx = 0; jx < n_values; jx++)
     567                 :             :             {
     568                 :         161 :               value_info = gi_enum_info_get_value (GI_ENUM_INFO (info), jx);
     569                 :         161 :               c_identifier = gi_base_info_get_attribute (GI_BASE_INFO (value_info), "c:identifier");
     570                 :         161 :               g_assert_nonnull (c_identifier);
     571                 :             : 
     572                 :         161 :               g_clear_pointer (&value_info, gi_base_info_unref);
     573                 :             :             }
     574                 :             :         }
     575                 :             : 
     576                 :         980 :       g_clear_pointer (&info, gi_base_info_unref);
     577                 :             :     }
     578                 :           1 : }
     579                 :             : 
     580                 :             : static void
     581                 :           1 : test_repository_fundamental_ref_func (RepositoryFixture *fx,
     582                 :             :                                       const void *unused)
     583                 :             : {
     584                 :             :   GIObjectInfo *info;
     585                 :             : 
     586                 :           1 :   g_test_summary ("Test getting the ref func of a fundamental type");
     587                 :             : 
     588                 :           1 :   info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ParamSpec"));
     589                 :           1 :   g_assert_nonnull (info);
     590                 :             : 
     591                 :           1 :   g_assert_nonnull (gi_object_info_get_ref_function_pointer (info));
     592                 :             : 
     593                 :           1 :   g_clear_pointer (&info, gi_base_info_unref);
     594                 :           1 : }
     595                 :             : 
     596                 :             : static void
     597                 :           1 : test_repository_instance_method_ownership_transfer (RepositoryFixture *fx,
     598                 :             :                                                     const void *unused)
     599                 :             : {
     600                 :           1 :   GIObjectInfo *class_info = NULL;
     601                 :           1 :   GIFunctionInfo *func_info = NULL;
     602                 :             :   GITransfer transfer;
     603                 :             : 
     604                 :           1 :   g_test_summary ("Test two methods of the same object having opposite ownership transfer of the instance parameter");
     605                 :             : 
     606                 :           1 :   class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusMethodInvocation"));
     607                 :           1 :   g_assert_nonnull (class_info);
     608                 :             : 
     609                 :           1 :   func_info = gi_object_info_find_method (class_info, "get_connection");
     610                 :           1 :   g_assert_nonnull (func_info);
     611                 :           1 :   transfer = gi_callable_info_get_instance_ownership_transfer (GI_CALLABLE_INFO (func_info));
     612                 :           1 :   g_assert_cmpint (GI_TRANSFER_NOTHING, ==, transfer);
     613                 :             : 
     614                 :           1 :   g_clear_pointer (&func_info, gi_base_info_unref);
     615                 :             : 
     616                 :           1 :   func_info = gi_object_info_find_method (class_info, "return_error_literal");
     617                 :           1 :   g_assert_nonnull (func_info);
     618                 :           1 :   transfer = gi_callable_info_get_instance_ownership_transfer (GI_CALLABLE_INFO (func_info));
     619                 :           1 :   g_assert_cmpint (GI_TRANSFER_EVERYTHING, ==, transfer);
     620                 :             : 
     621                 :           1 :   g_clear_pointer (&func_info, gi_base_info_unref);
     622                 :           1 :   g_clear_pointer (&class_info, gi_base_info_unref);
     623                 :           1 : }
     624                 :             : 
     625                 :             : static void
     626                 :           1 : test_repository_object_gtype_interfaces (RepositoryFixture *fx,
     627                 :             :                                          const void *unused)
     628                 :             : {
     629                 :             :   GIInterfaceInfo **interfaces;
     630                 :             :   size_t n_interfaces, ix;
     631                 :             :   const char *name;
     632                 :           1 :   gboolean found_initable = FALSE, found_async_initable = FALSE;
     633                 :             : 
     634                 :           1 :   g_test_summary ("Test gi_repository_get_object_gtype_interfaces()");
     635                 :             : 
     636                 :           1 :   gi_repository_get_object_gtype_interfaces (fx->repository, G_TYPE_DBUS_CONNECTION, &n_interfaces, &interfaces);
     637                 :             : 
     638                 :           1 :   g_assert_cmpuint (n_interfaces, ==, 2);
     639                 :             : 
     640                 :           3 :   for (ix = 0; ix < n_interfaces; ix++)
     641                 :             :     {
     642                 :           2 :       name = gi_base_info_get_name (GI_BASE_INFO (*(interfaces + ix)));
     643                 :           2 :       if (strcmp (name, "Initable") == 0)
     644                 :           1 :         found_initable = TRUE;
     645                 :           1 :       else if (strcmp (name, "AsyncInitable") == 0)
     646                 :           1 :         found_async_initable = TRUE;
     647                 :             :     }
     648                 :             : 
     649                 :           1 :   g_assert_true (found_initable);
     650                 :           1 :   g_assert_true (found_async_initable);
     651                 :           1 : }
     652                 :             : 
     653                 :             : static void
     654                 :           1 : test_repository_signal_info_with_array_length_arg (RepositoryFixture *fx,
     655                 :             :                                                    const void *unused)
     656                 :             : {
     657                 :           1 :   GIObjectInfo *gsettings_info = NULL;
     658                 :           1 :   GISignalInfo *sig_info = NULL;
     659                 :           1 :   GIArgInfo *arg_info = NULL;
     660                 :           1 :   GITypeInfo *type_info = NULL;
     661                 :             :   unsigned length_ix;
     662                 :             : 
     663                 :           1 :   g_test_summary ("Test finding the associated array length argument of an array parameter of a signal");
     664                 :             : 
     665                 :           1 :   gsettings_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Settings"));
     666                 :           1 :   g_assert_nonnull (gsettings_info);
     667                 :             : 
     668                 :           1 :   sig_info = gi_object_info_find_signal (gsettings_info, "change-event");
     669                 :           1 :   g_assert_nonnull (sig_info);
     670                 :             : 
     671                 :           1 :   g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (sig_info)), ==, 2);
     672                 :             : 
     673                 :             :   /* verify array argument */
     674                 :           1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (sig_info), 0);
     675                 :           1 :   g_assert_nonnull (arg_info);
     676                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (arg_info)), ==, "keys");
     677                 :             : 
     678                 :           1 :   type_info = gi_arg_info_get_type_info (arg_info);
     679                 :           1 :   g_assert_nonnull (type_info);
     680                 :           1 :   g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_ARRAY);
     681                 :           1 :   g_assert_cmpint (gi_type_info_get_array_type (type_info), ==, GI_ARRAY_TYPE_C);
     682                 :           1 :   g_assert_false (gi_type_info_is_zero_terminated (type_info));
     683                 :           1 :   gboolean ok = gi_type_info_get_array_length_index (type_info, &length_ix);
     684                 :           1 :   g_assert_true (ok);
     685                 :           1 :   g_assert_cmpuint (length_ix, ==, 1);
     686                 :             : 
     687                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     688                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     689                 :             : 
     690                 :             :   /* verify array length argument */
     691                 :           1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (sig_info), 1);
     692                 :           1 :   g_assert_nonnull (arg_info);
     693                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (arg_info)), ==, "n_keys");
     694                 :             : 
     695                 :           1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     696                 :           1 :   g_clear_pointer (&type_info, gi_base_info_unref);
     697                 :           1 :   g_clear_pointer (&sig_info, gi_base_info_unref);
     698                 :           1 :   g_clear_pointer (&gsettings_info, gi_base_info_unref);
     699                 :           1 : }
     700                 :             : 
     701                 :             : static void
     702                 :           1 : test_repository_type_info_name (RepositoryFixture *fx,
     703                 :             :                                 const void *unused)
     704                 :             : {
     705                 :           1 :   GIInterfaceInfo *interface_info = NULL;
     706                 :             :   GIVFuncInfo *vfunc;
     707                 :             :   GITypeInfo *typeinfo;
     708                 :             : 
     709                 :           1 :   g_test_summary ("Test that gi_base_info_get_name() returns null for GITypeInfo");
     710                 :           1 :   g_test_bug ("https://gitlab.gnome.org/GNOME/gobject-introspection/issues/96");
     711                 :             : 
     712                 :           1 :   interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "File"));
     713                 :           1 :   g_assert_nonnull (interface_info);
     714                 :           1 :   vfunc = gi_interface_info_find_vfunc (interface_info, "read_async");
     715                 :           1 :   g_assert_nonnull (vfunc);
     716                 :             : 
     717                 :           1 :   typeinfo = gi_callable_info_get_return_type (GI_CALLABLE_INFO (vfunc));
     718                 :           1 :   g_assert_nonnull (typeinfo);
     719                 :             : 
     720                 :           1 :   g_assert_null (gi_base_info_get_name (GI_BASE_INFO (typeinfo)));
     721                 :             : 
     722                 :           1 :   g_clear_pointer (&interface_info, gi_base_info_unref);
     723                 :           1 :   g_clear_pointer (&vfunc, gi_base_info_unref);
     724                 :           1 :   g_clear_pointer (&typeinfo, gi_base_info_unref);
     725                 :           1 : }
     726                 :             : 
     727                 :             : static void
     728                 :           1 : test_repository_vfunc_info_with_no_invoker (RepositoryFixture *fx,
     729                 :             :                                             const void *unused)
     730                 :             : {
     731                 :           1 :   GIObjectInfo *object_info = NULL;
     732                 :           1 :   GIVFuncInfo *vfunc_info = NULL;
     733                 :           1 :   GIFunctionInfo *invoker_info = NULL;
     734                 :             : 
     735                 :           1 :   g_test_summary ("Test vfunc with no known invoker on object, such as GObject.dispose");
     736                 :             : 
     737                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     738                 :           1 :   g_assert_nonnull (object_info);
     739                 :             : 
     740                 :           1 :   vfunc_info = gi_object_info_find_vfunc (object_info, "dispose");
     741                 :           1 :   g_assert_nonnull (vfunc_info);
     742                 :             : 
     743                 :           1 :   invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
     744                 :           1 :   g_assert_null (invoker_info);
     745                 :             : 
     746                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     747                 :           1 :   g_clear_pointer (&vfunc_info, gi_base_info_unref);
     748                 :           1 : }
     749                 :             : 
     750                 :             : static void
     751                 :           1 : test_repository_vfunc_info_with_invoker_on_interface (RepositoryFixture *fx,
     752                 :             :                                                       const void *unused)
     753                 :             : {
     754                 :           1 :   GIInterfaceInfo *interface_info = NULL;
     755                 :           1 :   GIVFuncInfo *vfunc_info = NULL;
     756                 :           1 :   GIFunctionInfo *invoker_info = NULL;
     757                 :             : 
     758                 :           1 :   g_test_summary ("Test vfunc with invoker on interface, such as GFile.read_async");
     759                 :             : 
     760                 :           1 :   interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "File"));
     761                 :           1 :   g_assert_nonnull (interface_info);
     762                 :             : 
     763                 :           1 :   vfunc_info = gi_interface_info_find_vfunc (interface_info, "read_async");
     764                 :           1 :   g_assert_nonnull (vfunc_info);
     765                 :             : 
     766                 :           1 :   invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
     767                 :           1 :   g_assert_nonnull (invoker_info);
     768                 :             : 
     769                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "read_async");
     770                 :             : 
     771                 :           1 :   g_clear_pointer (&interface_info, gi_base_info_unref);
     772                 :           1 :   g_clear_pointer (&vfunc_info, gi_base_info_unref);
     773                 :           1 :   g_clear_pointer (&invoker_info, gi_base_info_unref);
     774                 :           1 : }
     775                 :             : 
     776                 :             : static void
     777                 :           1 : test_repository_vfunc_info_with_invoker_on_object (RepositoryFixture *fx,
     778                 :             :                                                    const void *unused)
     779                 :             : {
     780                 :           1 :   GIObjectInfo *object_info = NULL;
     781                 :           1 :   GIVFuncInfo *vfunc_info = NULL;
     782                 :           1 :   GIFunctionInfo *invoker_info = NULL;
     783                 :             : 
     784                 :           1 :   g_test_summary ("Test vfunc with invoker on object, such as GAppLaunchContext.get_display");
     785                 :             : 
     786                 :           1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "AppLaunchContext"));
     787                 :           1 :   g_assert_nonnull (object_info);
     788                 :             : 
     789                 :           1 :   vfunc_info = gi_object_info_find_vfunc (object_info, "get_display");
     790                 :           1 :   g_assert_nonnull (vfunc_info);
     791                 :             : 
     792                 :           1 :   invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
     793                 :           1 :   g_assert_nonnull (invoker_info);
     794                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "get_display");
     795                 :             : 
     796                 :             :   /* And let's be sure we can find the method directly */
     797                 :           1 :   g_clear_pointer (&invoker_info, gi_base_info_unref);
     798                 :             : 
     799                 :           1 :   invoker_info = gi_object_info_find_method (object_info, "get_display");
     800                 :           1 :   g_assert_nonnull (invoker_info);
     801                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "get_display");
     802                 :             : 
     803                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     804                 :           1 :   g_clear_pointer (&vfunc_info, gi_base_info_unref);
     805                 :           1 :   g_clear_pointer (&invoker_info, gi_base_info_unref);
     806                 :           1 : }
     807                 :             : 
     808                 :             : static void
     809                 :           1 : test_repository_find_by_gtype (RepositoryFixture *fx,
     810                 :             :                                const void        *unused)
     811                 :             : {
     812                 :           1 :   GIObjectInfo *object_info = NULL;
     813                 :             : 
     814                 :           1 :   g_test_summary ("Test finding a GType");
     815                 :             : 
     816                 :           1 :   object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT);
     817                 :           1 :   g_assert_nonnull (object_info);
     818                 :           1 :   g_assert_true (GI_IS_OBJECT_INFO (object_info));
     819                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
     820                 :             : 
     821                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     822                 :             : 
     823                 :             :   /* Find it again; this time it should hit the cache. */
     824                 :           1 :   object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT);
     825                 :           1 :   g_assert_nonnull (object_info);
     826                 :           1 :   g_assert_true (GI_IS_OBJECT_INFO (object_info));
     827                 :           1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
     828                 :             : 
     829                 :           1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     830                 :             : 
     831                 :             :   /* Try and find an unknown GType. */
     832                 :           1 :   g_assert_null (gi_repository_find_by_gtype (fx->repository, GI_TYPE_BASE_INFO));
     833                 :             : 
     834                 :             :   /* And check caching for unknown GTypes. */
     835                 :           1 :   g_assert_null (gi_repository_find_by_gtype (fx->repository, GI_TYPE_BASE_INFO));
     836                 :             : 
     837                 :             :   /* Now try and find one which will resolve in both Gio and GioUnix/GioWin32.
     838                 :             :    * The longest-named typelib should be returned. */
     839                 :             :   {
     840                 :             :     GType platform_specific_type;
     841                 :             :     const char *expected_name, *expected_namespace;
     842                 :             : 
     843                 :             : #if defined(G_OS_UNIX) && !(__APPLE__)
     844                 :           1 :     platform_specific_type = G_TYPE_DESKTOP_APP_INFO;
     845                 :           1 :     expected_name = "DesktopAppInfo";
     846                 :           1 :     expected_namespace = "GioUnix";
     847                 :             : #elif defined(G_OS_WIN32)
     848                 :             :     platform_specific_type = G_TYPE_WIN32_INPUT_STREAM;
     849                 :             :     expected_name = "InputStream";
     850                 :             :     expected_namespace = "GioWin32";
     851                 :             : #else
     852                 :             :     platform_specific_type = G_TYPE_INVALID;
     853                 :             :     expected_name = NULL;
     854                 :             :     expected_namespace = NULL;
     855                 :             : #endif
     856                 :             : 
     857                 :           1 :     if (expected_name != NULL)
     858                 :             :       {
     859                 :           1 :         object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, platform_specific_type);
     860                 :           1 :         g_assert_nonnull (object_info);
     861                 :           1 :         g_assert_true (GI_IS_OBJECT_INFO (object_info));
     862                 :           1 :         g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, expected_name);
     863                 :           1 :         g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, expected_namespace);
     864                 :           1 :         g_clear_pointer (&object_info, gi_base_info_unref);
     865                 :             :       }
     866                 :             :   }
     867                 :           1 : }
     868                 :             : 
     869                 :             : static void
     870                 :           1 : test_repository_loaded_namespaces (RepositoryFixture *fx,
     871                 :             :                                    const void        *unused)
     872                 :             : {
     873                 :             :   char **namespaces;
     874                 :             :   size_t n_namespaces;
     875                 :             : 
     876                 :             :   /* These should be in alphabetical order */
     877                 :             : #if defined(G_OS_UNIX)
     878                 :           1 :   const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", "GioUnix", NULL };
     879                 :             : #elif defined(G_OS_WIN32)
     880                 :             :   const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", "GioWin32", NULL };
     881                 :             : #else
     882                 :             :   const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", NULL };
     883                 :             : #endif
     884                 :             : 
     885                 :           1 :   g_test_summary ("Test listing loaded namespaces");
     886                 :             : 
     887                 :           1 :   namespaces = gi_repository_get_loaded_namespaces (fx->repository, &n_namespaces);
     888                 :           6 :   g_assert_cmpstrv (namespaces, expected_namespaces);
     889                 :           1 :   g_assert_cmpuint (n_namespaces, ==, g_strv_length ((char **) expected_namespaces));
     890                 :           1 :   g_strfreev (namespaces);
     891                 :             : 
     892                 :             :   /* Test again but without passing `n_namespaces`. */
     893                 :           1 :   namespaces = gi_repository_get_loaded_namespaces (fx->repository, NULL);
     894                 :           6 :   g_assert_cmpstrv (namespaces, expected_namespaces);
     895                 :           1 :   g_strfreev (namespaces);
     896                 :           1 : }
     897                 :             : 
     898                 :             : static void
     899                 :           1 : test_repository_dup_default (void)
     900                 :             : {
     901                 :           1 :   GIRepository *repository1 = gi_repository_dup_default ();
     902                 :           1 :   GIRepository *repository2 = gi_repository_dup_default ();
     903                 :             : 
     904                 :           1 :   g_assert_nonnull (repository1);
     905                 :           1 :   g_assert_nonnull (repository2);
     906                 :           1 :   g_assert_true (repository1 == repository2);
     907                 :             : 
     908                 :           1 :   g_clear_object (&repository1);
     909                 :           1 :   g_clear_object (&repository2);
     910                 :           1 : }
     911                 :             : 
     912                 :             : int
     913                 :           1 : main (int   argc,
     914                 :             :       char *argv[])
     915                 :             : {
     916                 :           1 :   repository_init (&argc, &argv);
     917                 :             : 
     918                 :           1 :   ADD_REPOSITORY_TEST ("/repository/basic", test_repository_basic, &typelib_load_spec_glib);
     919                 :           1 :   ADD_REPOSITORY_TEST ("/repository/info", test_repository_info, &typelib_load_spec_gobject);
     920                 :           1 :   ADD_REPOSITORY_TEST ("/repository/dependencies", test_repository_dependencies, &typelib_load_spec_gobject);
     921                 :           1 :   ADD_REPOSITORY_TEST ("/repository/base-info/clear", test_repository_base_info_clear, &typelib_load_spec_gobject);
     922                 :           1 :   ADD_REPOSITORY_TEST ("/repository/arg-info", test_repository_arg_info, &typelib_load_spec_gobject);
     923                 :           1 :   ADD_REPOSITORY_TEST ("/repository/callable-info", test_repository_callable_info, &typelib_load_spec_gobject);
     924                 :           1 :   ADD_REPOSITORY_TEST ("/repository/callback-info", test_repository_callback_info, &typelib_load_spec_gobject);
     925                 :           1 :   ADD_REPOSITORY_TEST ("/repository/char-types", test_repository_char_types, &typelib_load_spec_gobject);
     926                 :           1 :   ADD_REPOSITORY_TEST ("/repository/constructor-return-type", test_repository_constructor_return_type, &typelib_load_spec_gobject);
     927                 :           1 :   ADD_REPOSITORY_TEST ("/repository/enum-info-c-identifier", test_repository_enum_info_c_identifier, &typelib_load_spec_glib);
     928                 :           1 :   ADD_REPOSITORY_TEST ("/repository/enum-info-static-methods", test_repository_enum_info_static_methods, &typelib_load_spec_glib);
     929                 :           1 :   ADD_REPOSITORY_TEST ("/repository/error-quark", test_repository_error_quark, &typelib_load_spec_gio_platform);
     930                 :           1 :   ADD_REPOSITORY_TEST ("/repository/flags-info-c-identifier", test_repository_flags_info_c_identifier, &typelib_load_spec_gobject);
     931                 :           1 :   ADD_REPOSITORY_TEST ("/repository/fundamental-ref-func", test_repository_fundamental_ref_func, &typelib_load_spec_gobject);
     932                 :           1 :   ADD_REPOSITORY_TEST ("/repository/instance-method-ownership-transfer", test_repository_instance_method_ownership_transfer, &typelib_load_spec_gio);
     933                 :           1 :   ADD_REPOSITORY_TEST ("/repository/object-gtype-interfaces", test_repository_object_gtype_interfaces, &typelib_load_spec_gio);
     934                 :           1 :   ADD_REPOSITORY_TEST ("/repository/signal-info-with-array-length-arg", test_repository_signal_info_with_array_length_arg, &typelib_load_spec_gio);
     935                 :           1 :   ADD_REPOSITORY_TEST ("/repository/type-info-name", test_repository_type_info_name, &typelib_load_spec_gio);
     936                 :           1 :   ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-no-invoker", test_repository_vfunc_info_with_no_invoker, &typelib_load_spec_gobject);
     937                 :           1 :   ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-invoker-on-interface", test_repository_vfunc_info_with_invoker_on_interface, &typelib_load_spec_gio);
     938                 :           1 :   ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-invoker-on-object", test_repository_vfunc_info_with_invoker_on_object, &typelib_load_spec_gio);
     939                 :           1 :   ADD_REPOSITORY_TEST ("/repository/find-by-gtype", test_repository_find_by_gtype, &typelib_load_spec_gio_platform);
     940                 :           1 :   ADD_REPOSITORY_TEST ("/repository/loaded-namespaces", test_repository_loaded_namespaces, &typelib_load_spec_gio_platform);
     941                 :           1 :   g_test_add_func ("/repository/dup_default", test_repository_dup_default);
     942                 :             : 
     943                 :           1 :   return g_test_run ();
     944                 :             : }
        

Generated by: LCOV version 2.0-1