LCOV - code coverage report
Current view: top level - girepository/tests - callable-info.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 100.0 % 62 62
Test Date: 2024-11-26 05:23:01 Functions: 100.0 % 3 3
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                 :             : int
     128                 :           1 : main (int argc, char **argv)
     129                 :             : {
     130                 :           1 :   repository_init (&argc, &argv);
     131                 :             : 
     132                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/sync-function", test_callable_get_sync_function_for_async_function, &typelib_load_spec_gio);
     133                 :           1 :   ADD_REPOSITORY_TEST ("/callable-info/async-function", test_callable_get_async_function_for_sync_function, &typelib_load_spec_gio);
     134                 :             : 
     135                 :           1 :   return g_test_run ();
     136                 :             : }
        

Generated by: LCOV version 2.0-1