LCOV - code coverage report
Current view: top level - glib/girepository/tests - autoptr.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 199 199 100.0 %
Date: 2024-05-07 05:15:23 Functions: 25 25 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2024 GNOME Foundation, Inc.
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General
      17                 :            :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Author: Philip Withnall <pwithnall@gnome.org>
      20                 :            :  */
      21                 :            : 
      22                 :            : #include "girepository.h"
      23                 :            : #include "girffi.h"
      24                 :            : #include "glib.h"
      25                 :            : #include "test-common.h"
      26                 :            : 
      27                 :            : static void
      28                 :          1 : test_autoptr_repository (RepositoryFixture *fx,
      29                 :            :                          const void        *unused)
      30                 :            : {
      31                 :          2 :   g_autoptr(GIRepository) repository = gi_repository_new ();
      32                 :          1 :   g_assert_nonnull (repository);
      33                 :          1 : }
      34                 :            : 
      35                 :            : static void
      36                 :          1 : test_autoptr_typelib (RepositoryFixture *fx,
      37                 :            :                       const void        *unused)
      38                 :            : {
      39                 :          1 :   g_autoptr(GITypelib) typelib = NULL;
      40                 :          1 :   GError *local_error = NULL;
      41                 :            : 
      42                 :          1 :   typelib = gi_repository_require (fx->repository, "Gio", "2.0",
      43                 :            :                                    GI_REPOSITORY_LOAD_FLAG_NONE, &local_error);
      44                 :          1 :   g_assert_no_error (local_error);
      45                 :          1 :   g_assert_nonnull (typelib);
      46                 :            : 
      47                 :            :   /* gi_repository_require() doesn’t return a reference so let’s add one */
      48                 :          1 :   gi_typelib_ref (typelib);
      49                 :          1 : }
      50                 :            : 
      51                 :            : static void
      52                 :          1 : test_autoptr_base_info (RepositoryFixture *fx,
      53                 :            :                         const void        *unused)
      54                 :            : {
      55                 :          2 :   g_autoptr(GIBaseInfo) base_info = gi_repository_find_by_name (fx->repository, "Gio", "Resolver");
      56                 :          1 :   g_assert_nonnull (base_info);
      57                 :          1 : }
      58                 :            : 
      59                 :            : static void
      60                 :          1 : test_autoptr_arg_info (RepositoryFixture *fx,
      61                 :            :                        const void        *unused)
      62                 :            : {
      63                 :          1 :   GIObjectInfo *object_info = NULL;
      64                 :          1 :   GIFunctionInfo *method_info = NULL;
      65                 :          1 :   g_autoptr(GIArgInfo) arg_info = NULL;
      66                 :            : 
      67                 :          1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
      68                 :          1 :   g_assert_nonnull (object_info);
      69                 :          1 :   method_info = gi_object_info_find_method (object_info, "get_property");
      70                 :          1 :   g_assert_nonnull (method_info);
      71                 :          1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
      72                 :          1 :   g_assert_nonnull (arg_info);
      73                 :            : 
      74                 :          1 :   g_clear_pointer (&method_info, gi_base_info_unref);
      75                 :          1 :   g_clear_pointer (&object_info, gi_base_info_unref);
      76                 :          1 : }
      77                 :            : 
      78                 :            : static void
      79                 :          1 : test_autoptr_callable_info (RepositoryFixture *fx,
      80                 :            :                             const void        *unused)
      81                 :            : {
      82                 :          2 :   g_autoptr(GICallableInfo) callable_info = GI_CALLABLE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "tls_server_connection_new"));
      83                 :          1 :   g_assert_nonnull (callable_info);
      84                 :          1 : }
      85                 :            : 
      86                 :            : static void
      87                 :          1 : test_autoptr_callback_info (RepositoryFixture *fx,
      88                 :            :                             const void        *unused)
      89                 :            : {
      90                 :          2 :   g_autoptr(GICallbackInfo) callback_info = GI_CALLBACK_INFO (gi_repository_find_by_name (fx->repository, "Gio", "AsyncReadyCallback"));
      91                 :          1 :   g_assert_nonnull (callback_info);
      92                 :          1 : }
      93                 :            : 
      94                 :            : static void
      95                 :          1 : test_autoptr_constant_info (RepositoryFixture *fx,
      96                 :            :                             const void        *unused)
      97                 :            : {
      98                 :          2 :   g_autoptr(GIConstantInfo) constant_info = GI_CONSTANT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBUS_METHOD_INVOCATION_HANDLED"));
      99                 :          1 :   g_assert_nonnull (constant_info);
     100                 :          1 : }
     101                 :            : 
     102                 :            : static void
     103                 :          1 : test_autoptr_enum_info (RepositoryFixture *fx,
     104                 :            :                         const void        *unused)
     105                 :            : {
     106                 :          2 :   g_autoptr(GIEnumInfo) enum_info = GI_ENUM_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusError"));
     107                 :          1 :   g_assert_nonnull (enum_info);
     108                 :          1 : }
     109                 :            : 
     110                 :            : static void
     111                 :          1 : test_autoptr_field_info (RepositoryFixture *fx,
     112                 :            :                          const void        *unused)
     113                 :            : {
     114                 :          1 :   GIStructInfo *struct_info = NULL;
     115                 :          1 :   g_autoptr(GIFieldInfo) field_info = NULL;
     116                 :            : 
     117                 :          1 :   struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "ActionEntry"));
     118                 :          1 :   g_assert_nonnull (struct_info);
     119                 :          1 :   field_info = gi_struct_info_find_field (struct_info, "name");
     120                 :          1 :   g_assert_nonnull (field_info);
     121                 :            : 
     122                 :          1 :   g_clear_pointer (&struct_info, gi_base_info_unref);
     123                 :          1 : }
     124                 :            : 
     125                 :            : static void
     126                 :          1 : test_autoptr_flags_info (RepositoryFixture *fx,
     127                 :            :                          const void        *unused)
     128                 :            : {
     129                 :          2 :   g_autoptr(GIFlagsInfo) flags_info = GI_FLAGS_INFO (gi_repository_find_by_name (fx->repository, "Gio", "AppInfoCreateFlags"));
     130                 :          1 :   g_assert_nonnull (flags_info);
     131                 :          1 : }
     132                 :            : 
     133                 :            : static void
     134                 :          1 : test_autoptr_function_info (RepositoryFixture *fx,
     135                 :            :                             const void        *unused)
     136                 :            : {
     137                 :          2 :   g_autoptr(GIFunctionInfo) function_info = GI_FUNCTION_INFO (gi_repository_find_by_name (fx->repository, "Gio", "tls_server_connection_new"));
     138                 :          1 :   g_assert_nonnull (function_info);
     139                 :          1 : }
     140                 :            : 
     141                 :            : static void
     142                 :          1 : test_autoptr_interface_info (RepositoryFixture *fx,
     143                 :            :                              const void        *unused)
     144                 :            : {
     145                 :          2 :   g_autoptr(GIInterfaceInfo) interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "AsyncInitable"));
     146                 :          1 :   g_assert_nonnull (interface_info);
     147                 :          1 : }
     148                 :            : 
     149                 :            : static void
     150                 :          1 : test_autoptr_object_info (RepositoryFixture *fx,
     151                 :            :                           const void        *unused)
     152                 :            : {
     153                 :          2 :   g_autoptr(GIObjectInfo) object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "BufferedInputStream"));
     154                 :          1 :   g_assert_nonnull (object_info);
     155                 :          1 : }
     156                 :            : 
     157                 :            : static void
     158                 :          1 : test_autoptr_property_info (RepositoryFixture *fx,
     159                 :            :                             const void        *unused)
     160                 :            : {
     161                 :          1 :   GIObjectInfo *object_info = NULL;
     162                 :          1 :   g_autoptr(GIPropertyInfo) property_info = NULL;
     163                 :            : 
     164                 :          1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "BufferedInputStream"));
     165                 :          1 :   g_assert_nonnull (object_info);
     166                 :          1 :   property_info = gi_object_info_get_property (object_info, 0);
     167                 :          1 :   g_assert_nonnull (property_info);
     168                 :            : 
     169                 :          1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     170                 :          1 : }
     171                 :            : 
     172                 :            : static void
     173                 :          1 : test_autoptr_registered_type_info (RepositoryFixture *fx,
     174                 :            :                                    const void        *unused)
     175                 :            : {
     176                 :          1 :   g_autoptr(GIRegisteredTypeInfo) registered_type_info =
     177                 :          1 :       GI_REGISTERED_TYPE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "SrvTarget"));
     178                 :          1 :   g_assert_nonnull (registered_type_info);
     179                 :          1 : }
     180                 :            : 
     181                 :            : static void
     182                 :          1 : test_autoptr_signal_info (RepositoryFixture *fx,
     183                 :            :                           const void        *unused)
     184                 :            : {
     185                 :          1 :   GIObjectInfo *object_info = NULL;
     186                 :          1 :   g_autoptr(GISignalInfo) signal_info = NULL;
     187                 :            : 
     188                 :          1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Cancellable"));
     189                 :          1 :   g_assert_nonnull (object_info);
     190                 :          1 :   signal_info = gi_object_info_find_signal (object_info, "cancelled");
     191                 :          1 :   g_assert_nonnull (signal_info);
     192                 :            : 
     193                 :          1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     194                 :          1 : }
     195                 :            : 
     196                 :            : static void
     197                 :          1 : test_autoptr_struct_info (RepositoryFixture *fx,
     198                 :            :                           const void        *unused)
     199                 :            : {
     200                 :          2 :   g_autoptr(GIStructInfo) struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusAnnotationInfo"));
     201                 :          1 :   g_assert_nonnull (struct_info);
     202                 :          1 : }
     203                 :            : 
     204                 :            : static void
     205                 :          1 : test_autoptr_type_info (RepositoryFixture *fx,
     206                 :            :                         const void        *unused)
     207                 :            : {
     208                 :          1 :   GIStructInfo *struct_info = NULL;
     209                 :          1 :   GIFieldInfo *field_info = NULL;
     210                 :          1 :   g_autoptr(GITypeInfo) type_info = NULL;
     211                 :            : 
     212                 :          1 :   struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "ActionEntry"));
     213                 :          1 :   g_assert_nonnull (struct_info);
     214                 :          1 :   field_info = gi_struct_info_find_field (struct_info, "name");
     215                 :          1 :   g_assert_nonnull (field_info);
     216                 :          1 :   type_info = gi_field_info_get_type_info (field_info);
     217                 :          1 :   g_assert_nonnull (type_info);
     218                 :            : 
     219                 :          1 :   g_clear_pointer (&field_info, gi_base_info_unref);
     220                 :          1 :   g_clear_pointer (&struct_info, gi_base_info_unref);
     221                 :          1 : }
     222                 :            : 
     223                 :            : static void
     224                 :          1 : test_autoptr_union_info (RepositoryFixture *fx,
     225                 :            :                          const void        *unused)
     226                 :            : {
     227                 :          2 :   g_autoptr(GIUnionInfo) union_info = GI_UNION_INFO (gi_repository_find_by_name (fx->repository, "GLib", "DoubleIEEE754"));
     228                 :          1 :   g_assert_nonnull (union_info);
     229                 :          1 : }
     230                 :            : 
     231                 :            : static void
     232                 :          1 : test_autoptr_value_info (RepositoryFixture *fx,
     233                 :            :                          const void        *unused)
     234                 :            : {
     235                 :          1 :   GIEnumInfo *enum_info = NULL;
     236                 :          1 :   g_autoptr(GIValueInfo) value_info = NULL;
     237                 :            : 
     238                 :          1 :   enum_info = GI_ENUM_INFO (gi_repository_find_by_name (fx->repository, "Gio", "ZlibCompressorFormat"));
     239                 :          1 :   g_assert_nonnull (enum_info);
     240                 :          1 :   value_info = gi_enum_info_get_value (enum_info, 0);
     241                 :          1 :   g_assert_nonnull (value_info);
     242                 :            : 
     243                 :          1 :   g_clear_pointer (&enum_info, gi_base_info_unref);
     244                 :          1 : }
     245                 :            : 
     246                 :            : static void
     247                 :          1 : test_autoptr_vfunc_info (RepositoryFixture *fx,
     248                 :            :                          const void        *unused)
     249                 :            : {
     250                 :          1 :   GIInterfaceInfo *interface_info = NULL;
     251                 :          1 :   g_autoptr(GIVFuncInfo) vfunc_info = NULL;
     252                 :            : 
     253                 :          1 :   interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Action"));
     254                 :          1 :   g_assert_nonnull (interface_info);
     255                 :          1 :   vfunc_info = gi_interface_info_find_vfunc (interface_info, "activate");
     256                 :          1 :   g_assert_nonnull (vfunc_info);
     257                 :            : 
     258                 :          1 :   g_clear_pointer (&interface_info, gi_base_info_unref);
     259                 :          1 : }
     260                 :            : 
     261                 :            : static void
     262                 :          1 : test_auto_arg_info (RepositoryFixture *fx,
     263                 :            :                     const void        *unused)
     264                 :            : {
     265                 :          1 :   GIObjectInfo *object_info = NULL;
     266                 :          1 :   GIFunctionInfo *method_info = NULL;
     267                 :          1 :   g_auto(GIArgInfo) arg_info = { 0, };
     268                 :            : 
     269                 :          1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     270                 :          1 :   g_assert_nonnull (object_info);
     271                 :          1 :   method_info = gi_object_info_find_method (object_info, "get_property");
     272                 :          1 :   g_assert_nonnull (method_info);
     273                 :          1 :   gi_callable_info_load_arg (GI_CALLABLE_INFO (method_info), 0, &arg_info);
     274                 :          1 :   g_assert_true (GI_IS_ARG_INFO (&arg_info));
     275                 :            : 
     276                 :          1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     277                 :          1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     278                 :          1 : }
     279                 :            : 
     280                 :            : static void
     281                 :          1 : test_auto_type_info (RepositoryFixture *fx,
     282                 :            :                      const void        *unused)
     283                 :            : {
     284                 :          1 :   GIObjectInfo *object_info = NULL;
     285                 :          1 :   GIFunctionInfo *method_info = NULL;
     286                 :          1 :   GIArgInfo *arg_info = NULL;
     287                 :          1 :   g_auto(GITypeInfo) type_info = { 0, };
     288                 :            : 
     289                 :          1 :   object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
     290                 :          1 :   g_assert_nonnull (object_info);
     291                 :          1 :   method_info = gi_object_info_find_method (object_info, "get_property");
     292                 :          1 :   g_assert_nonnull (method_info);
     293                 :          1 :   arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
     294                 :          1 :   g_assert_nonnull (arg_info);
     295                 :          1 :   gi_arg_info_load_type_info (arg_info, &type_info);
     296                 :          1 :   g_assert_true (GI_IS_TYPE_INFO (&type_info));
     297                 :            : 
     298                 :          1 :   g_clear_pointer (&arg_info, gi_base_info_unref);
     299                 :          1 :   g_clear_pointer (&method_info, gi_base_info_unref);
     300                 :          1 :   g_clear_pointer (&object_info, gi_base_info_unref);
     301                 :          1 : }
     302                 :            : 
     303                 :            : static void
     304                 :          1 : test_auto_function_invoker (RepositoryFixture *fx,
     305                 :            :                             const void        *unused)
     306                 :            : {
     307                 :          1 :   GIFunctionInfo *function_info = NULL;
     308                 :          1 :   g_auto(GIFunctionInvoker) invoker = { 0, };
     309                 :          1 :   GError *local_error = NULL;
     310                 :            : 
     311                 :          1 :   function_info = GI_FUNCTION_INFO (gi_repository_find_by_name (fx->repository, "Gio", "tls_server_connection_new"));
     312                 :          1 :   g_assert_nonnull (function_info);
     313                 :          1 :   gi_function_info_prep_invoker (function_info, &invoker, &local_error);
     314                 :          1 :   g_assert_no_error (local_error);
     315                 :            : 
     316                 :          1 :   g_clear_pointer (&function_info, gi_base_info_unref);
     317                 :          1 : }
     318                 :            : 
     319                 :            : int
     320                 :          1 : main (int   argc,
     321                 :            :       char *argv[])
     322                 :            : {
     323                 :          1 :   repository_init (&argc, &argv);
     324                 :            : 
     325                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/repository", test_autoptr_repository, &typelib_load_spec_gio);
     326                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/typelib", test_autoptr_typelib, &typelib_load_spec_gio);
     327                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/base-info", test_autoptr_base_info, &typelib_load_spec_gio);
     328                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/arg-info", test_autoptr_arg_info, &typelib_load_spec_gio);
     329                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/callable-info", test_autoptr_callable_info, &typelib_load_spec_gio);
     330                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/callback-info", test_autoptr_callback_info, &typelib_load_spec_gio);
     331                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/constant-info", test_autoptr_constant_info, &typelib_load_spec_gio);
     332                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/enum-info", test_autoptr_enum_info, &typelib_load_spec_gio);
     333                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/field-info", test_autoptr_field_info, &typelib_load_spec_gio);
     334                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/flags-info", test_autoptr_flags_info, &typelib_load_spec_gio);
     335                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/function-info", test_autoptr_function_info, &typelib_load_spec_gio);
     336                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/interface-info", test_autoptr_interface_info, &typelib_load_spec_gio);
     337                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/object-info", test_autoptr_object_info, &typelib_load_spec_gio);
     338                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/property-info", test_autoptr_property_info, &typelib_load_spec_gio);
     339                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/registered-type-info", test_autoptr_registered_type_info, &typelib_load_spec_gio);
     340                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/signal-info", test_autoptr_signal_info, &typelib_load_spec_gio);
     341                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/struct-info", test_autoptr_struct_info, &typelib_load_spec_gio);
     342                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/type-info", test_autoptr_type_info, &typelib_load_spec_gio);
     343                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/union-info", test_autoptr_union_info, &typelib_load_spec_glib);
     344                 :            :   /* no easy way to test GIUnresolvedInfo */
     345                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/value-info", test_autoptr_value_info, &typelib_load_spec_gio);
     346                 :          1 :   ADD_REPOSITORY_TEST ("/autoptr/vfunc-info", test_autoptr_vfunc_info, &typelib_load_spec_gio);
     347                 :            : 
     348                 :          1 :   ADD_REPOSITORY_TEST ("/auto/arg-info", test_auto_arg_info, &typelib_load_spec_gio);
     349                 :          1 :   ADD_REPOSITORY_TEST ("/auto/type-info", test_auto_type_info, &typelib_load_spec_gio);
     350                 :            : 
     351                 :          1 :   ADD_REPOSITORY_TEST ("/auto/function-invoker", test_auto_function_invoker, &typelib_load_spec_gio);
     352                 :            : 
     353                 :          1 :   return g_test_run ();
     354                 :            : }

Generated by: LCOV version 1.14