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

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2024 GNOME Foundation, Inc.
       3                 :             :  * Copyright 2024 Evan Welsh
       4                 :             :  *
       5                 :             :  * SPDX-License-Identifier: LGPL-2.1-or-later
       6                 :             :  *
       7                 :             :  * This library is free software; you can redistribute it and/or
       8                 :             :  * modify it under the terms of the GNU Lesser General Public
       9                 :             :  * License as published by the Free Software Foundation; either
      10                 :             :  * version 2.1 of the License, or (at your option) any later version.
      11                 :             :  *
      12                 :             :  * This library is distributed in the hope that it will be useful,
      13                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :             :  * Lesser General Public License for more details.
      16                 :             :  *
      17                 :             :  * You should have received a copy of the GNU Lesser General
      18                 :             :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19                 :             :  *
      20                 :             :  * Author: Evan Welsh <contact@evanwelsh.com>
      21                 :             :  */
      22                 :             : 
      23                 :             : #include "girepository.h"
      24                 :             : #include "test-common.h"
      25                 :             : 
      26                 :             : static void
      27                 :           1 : test_callable_get_sync_function_for_async_function (RepositoryFixture *fx,
      28                 :             :                                                     const void        *unused)
      29                 :             : {
      30                 :             :   GIBaseInfo *info;
      31                 :             : 
      32                 :           1 :   info = gi_repository_find_by_name (fx->repository, "Gio", "File");
      33                 :           1 :   g_assert_nonnull (info);
      34                 :           1 :   g_assert_true (GI_IS_INTERFACE_INFO (info));
      35                 :             : 
      36                 :           1 :   GICallableInfo *callable_info = (GICallableInfo *) gi_interface_info_find_method ((GIInterfaceInfo *) info, "load_contents_async");
      37                 :           1 :   g_assert_nonnull (callable_info);
      38                 :             : 
      39                 :           1 :   g_assert_true (gi_callable_info_is_async (callable_info));
      40                 :             : 
      41                 :           1 :   GICallableInfo *sync_info = gi_callable_info_get_sync_function (callable_info);
      42                 :           1 :   g_assert_nonnull (sync_info);
      43                 :             : 
      44                 :           1 :   GICallableInfo *finish_info = gi_callable_info_get_finish_function (callable_info);
      45                 :           1 :   g_assert_nonnull (finish_info);
      46                 :             : 
      47                 :           1 :   g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) sync_info), ==, "load_contents");
      48                 :           1 :   g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) finish_info), ==, "load_contents_finish");
      49                 :             : 
      50                 :           1 :   GICallableInfo *async_info = gi_callable_info_get_async_function (sync_info);
      51                 :             : 
      52                 :           1 :   g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) async_info), ==, "load_contents_async");
      53                 :             : 
      54                 :           1 :   gi_base_info_unref (async_info);
      55                 :           1 :   gi_base_info_unref (sync_info);
      56                 :           1 :   gi_base_info_unref (finish_info);
      57                 :           1 :   gi_base_info_unref (callable_info);
      58                 :           1 :   gi_base_info_unref (info);
      59                 :           1 : }
      60                 :             : 
      61                 :             : static void
      62                 :           1 : test_callable_get_async_function_for_sync_function (RepositoryFixture *fx,
      63                 :             :                                                     const void        *unused)
      64                 :             : {
      65                 :             :   GIBaseInfo *info;
      66                 :             : 
      67                 :           1 :   info = gi_repository_find_by_name (fx->repository, "Gio", "File");
      68                 :           1 :   g_assert_nonnull (info);
      69                 :           1 :   g_assert_true (g_type_is_a (G_TYPE_FROM_INSTANCE (info), gi_interface_info_get_type ()));
      70                 :             : 
      71                 :           1 :   GICallableInfo *callable_info = (GICallableInfo *) gi_interface_info_find_method ((GIInterfaceInfo *) info, "load_contents");
      72                 :             : 
      73                 :             :   {
      74                 :           1 :     GICallableInfo *async_func = gi_callable_info_get_async_function (callable_info);
      75                 :           1 :     g_assert_nonnull (async_func);
      76                 :             : 
      77                 :           1 :     GICallableInfo *finish_func = gi_callable_info_get_finish_function (callable_info);
      78                 :           1 :     g_assert_null (finish_func);
      79                 :             : 
      80                 :           1 :     GICallableInfo *sync_func = gi_callable_info_get_sync_function (callable_info);
      81                 :           1 :     g_assert_null (sync_func);
      82                 :             : 
      83                 :           1 :     gi_base_info_unref ((GIBaseInfo *) async_func);
      84                 :             :   }
      85                 :             : 
      86                 :           1 :   GICallableInfo *async_info = gi_callable_info_get_async_function (callable_info);
      87                 :             : 
      88                 :             :   {
      89                 :           1 :     GICallableInfo *async_func = gi_callable_info_get_async_function (async_info);
      90                 :           1 :     g_assert_null (async_func);
      91                 :             : 
      92                 :           1 :     GICallableInfo *finish_func = gi_callable_info_get_finish_function (async_info);
      93                 :           1 :     g_assert_nonnull (finish_func);
      94                 :             : 
      95                 :           1 :     GICallableInfo *sync_func = gi_callable_info_get_sync_function (async_info);
      96                 :           1 :     g_assert_nonnull (sync_func);
      97                 :             : 
      98                 :           1 :     gi_base_info_unref ((GIBaseInfo *) finish_func);
      99                 :           1 :     gi_base_info_unref ((GIBaseInfo *) sync_func);
     100                 :             :   }
     101                 :             : 
     102                 :           1 :   g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) async_info), ==, "load_contents_async");
     103                 :             : 
     104                 :           1 :   GICallableInfo *sync_info = gi_callable_info_get_sync_function (async_info);
     105                 :             : 
     106                 :             :   {
     107                 :           1 :     GICallableInfo *async_func = gi_callable_info_get_async_function (sync_info);
     108                 :           1 :     g_assert_nonnull (async_func);
     109                 :             : 
     110                 :           1 :     GICallableInfo *finish_func = gi_callable_info_get_finish_function (sync_info);
     111                 :           1 :     g_assert_null (finish_func);
     112                 :             : 
     113                 :           1 :     GICallableInfo *sync_func = gi_callable_info_get_sync_function (sync_info);
     114                 :           1 :     g_assert_null (sync_func);
     115                 :             : 
     116                 :           1 :     gi_base_info_unref ((GIBaseInfo *) async_func);
     117                 :             :   }
     118                 :             : 
     119                 :           1 :   g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) sync_info), ==, "load_contents");
     120                 :             : 
     121                 :           1 :   gi_base_info_unref ((GIBaseInfo *) async_info);
     122                 :           1 :   gi_base_info_unref ((GIBaseInfo *) sync_info);
     123                 :           1 :   gi_base_info_unref ((GIBaseInfo *) callable_info);
     124                 :           1 :   gi_base_info_unref (info);
     125                 :           1 : }
     126                 :             : 
     127                 :             : static void
     128                 :           1 : test_callable_info_is_method (RepositoryFixture *fx,
     129                 :             :                               const void *unused)
     130                 :             : {
     131                 :             :   GIBaseInfo *info;
     132                 :             :   GIFunctionInfo *func_info;
     133                 :             :   GIVFuncInfo *vfunc_info;
     134                 :             :   GISignalInfo *sig_info;
     135                 :             :   GIBaseInfo *cb_info;
     136                 :             : 
     137                 :           1 :   info = gi_repository_find_by_name (fx->repository, "Gio", "ActionGroup");
     138                 :           1 :   g_assert_nonnull (info);
     139                 :             : 
     140                 :           1 :   func_info = gi_interface_info_find_method (GI_INTERFACE_INFO (info), "action_added");
     141                 :           1 :   g_assert_nonnull (func_info);
     142                 :             : 
     143                 :           1 :   g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (func_info)));
     144                 :             : 
     145                 :           1 :   vfunc_info = gi_interface_info_find_vfunc (GI_INTERFACE_INFO (info), "action_added");
     146                 :           1 :   g_assert_nonnull (vfunc_info);
     147                 :             : 
     148                 :           1 :   g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (vfunc_info)));
     149                 :             : 
     150                 :           1 :   sig_info = gi_interface_info_find_signal (GI_INTERFACE_INFO (info), "action-added");
     151                 :           1 :   g_assert_nonnull (sig_info);
     152                 :             : 
     153                 :           1 :   g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (sig_info)));
     154                 :             : 
     155                 :           1 :   cb_info = gi_repository_find_by_name (fx->repository, "Gio", "AsyncReadyCallback");
     156                 :           1 :   g_assert_nonnull (cb_info);
     157                 :             : 
     158                 :           1 :   g_assert_false (gi_callable_info_is_method (GI_CALLABLE_INFO (cb_info)));
     159                 :             : 
     160                 :           1 :   gi_base_info_unref (info);
     161                 :           1 :   gi_base_info_unref ((GIBaseInfo *) func_info);
     162                 :           1 :   gi_base_info_unref ((GIBaseInfo *) vfunc_info);
     163                 :           1 :   gi_base_info_unref ((GIBaseInfo *) sig_info);
     164                 :           1 :   gi_base_info_unref (cb_info);
     165                 :           1 : }
     166                 :             : 
     167                 :             : static void
     168                 :           1 : test_callable_info_static_method (RepositoryFixture *fx,
     169                 :             :                                   const void *unused)
     170                 :             : {
     171                 :             :   GIBaseInfo *info;
     172                 :             :   GIFunctionInfo *func_info;
     173                 :             : 
     174                 :           1 :   info = gi_repository_find_by_name (fx->repository, "Gio", "Application");
     175                 :           1 :   g_assert_nonnull (info);
     176                 :             : 
     177                 :           1 :   func_info = gi_object_info_find_method (GI_OBJECT_INFO (info), "get_default");
     178                 :           1 :   g_assert_nonnull (func_info);
     179                 :             : 
     180                 :           1 :   g_assert_false (gi_callable_info_is_method (GI_CALLABLE_INFO (func_info)));
     181                 :             : 
     182                 :           1 :   gi_base_info_unref (info);
     183                 :           1 :   gi_base_info_unref ((GIBaseInfo *) func_info);
     184                 :           1 : }
     185                 :             : 
     186                 :             : static void
     187                 :           1 : test_callable_info_static_vfunc (RepositoryFixture *fx,
     188                 :             :                                  const void *unused)
     189                 :             : {
     190                 :             :   GIBaseInfo *info;
     191                 :             :   GIVFuncInfo *vfunc_info;
     192                 :             : 
     193                 :           1 :   g_test_bug ("https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/361");
     194                 :             : 
     195                 :           1 :   info = gi_repository_find_by_name (fx->repository, "Gio", "Icon");
     196                 :           1 :   g_assert_nonnull (info);
     197                 :             : 
     198                 :           1 :   vfunc_info = gi_interface_info_find_vfunc (GI_INTERFACE_INFO (info), "from_tokens");
     199                 :           1 :   if (!vfunc_info)
     200                 :             :     {
     201                 :           1 :       g_test_skip ("g-ir-scanner is not new enough");
     202                 :           1 :       gi_base_info_unref (info);
     203                 :           1 :       return;
     204                 :             :     }
     205                 :           0 :   g_assert_nonnull (vfunc_info);
     206                 :             : 
     207                 :           0 :   g_assert_false (gi_callable_info_is_method (GI_CALLABLE_INFO (vfunc_info)));
     208                 :             : 
     209                 :           0 :   gi_base_info_unref (info);
     210                 :           0 :   gi_base_info_unref ((GIBaseInfo *) vfunc_info);
     211                 :             : }
     212                 :             : 
     213                 :             : int
     214                 :           1 : main (int argc, char **argv)
     215                 :             : {
     216                 :           1 :   repository_init (&argc, &argv);
     217                 :             : 
     218                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/sync-function", test_callable_get_sync_function_for_async_function, &typelib_load_spec_gio);
     219                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/async-function", test_callable_get_async_function_for_sync_function, &typelib_load_spec_gio);
     220                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/is-method", test_callable_info_is_method, &typelib_load_spec_gio);
     221                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/static-method", test_callable_info_static_method, &typelib_load_spec_gio);
     222                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/static-vfunc", test_callable_info_static_vfunc, &typelib_load_spec_gio);
     223                 :             : 
     224                 :           1 :   return g_test_run ();
     225                 :             : }
        

Generated by: LCOV version 2.0-1