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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2024 GNOME Foundation
       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                 :            : 
      20                 :            : #include "config.h"
      21                 :            : 
      22                 :            : #include "girepository.h"
      23                 :            : #include "test-common.h"
      24                 :            : 
      25                 :            : static void
      26                 :          1 : test_basic (RepositoryFixture *fx,
      27                 :            :             const void        *unused)
      28                 :            : {
      29                 :          1 :   GIUnionInfo *double_info = NULL;
      30                 :          1 :   GIFieldInfo *field_info = NULL;
      31                 :          1 :   size_t offset = 123;
      32                 :            : 
      33                 :          1 :   g_test_summary ("Test basic properties of GIUnionInfo");
      34                 :            : 
      35                 :          1 :   double_info = GI_UNION_INFO (gi_repository_find_by_name (fx->repository, "GLib", "DoubleIEEE754"));
      36                 :          1 :   g_assert_nonnull (double_info);
      37                 :            : 
      38                 :          1 :   g_assert_cmpuint (gi_union_info_get_n_fields (double_info), ==, 1);
      39                 :            : 
      40                 :          1 :   field_info = gi_union_info_get_field (double_info, 0);
      41                 :          1 :   g_assert_true (GI_IS_FIELD_INFO (field_info));
      42                 :          1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (field_info)), ==, "v_double");
      43                 :          1 :   g_clear_pointer (&field_info, gi_base_info_unref);
      44                 :            : 
      45                 :          1 :   g_assert_cmpuint (gi_union_info_get_n_methods (double_info), ==, 0);
      46                 :          1 :   g_assert_null (gi_union_info_find_method (double_info, "not_exist"));
      47                 :            : 
      48                 :          1 :   g_assert_false (gi_union_info_is_discriminated (double_info));
      49                 :          1 :   g_assert_false (gi_union_info_get_discriminator_offset (double_info, &offset));
      50                 :          1 :   g_assert_cmpuint (offset, ==, 0);
      51                 :          1 :   g_assert_null (gi_union_info_get_discriminator_type (double_info));
      52                 :          1 :   g_assert_null (gi_union_info_get_discriminator (double_info, 0));
      53                 :            : 
      54                 :          1 :   g_assert_cmpuint (gi_union_info_get_size (double_info), ==, 8);
      55                 :          1 :   g_assert_cmpuint (gi_union_info_get_alignment (double_info), ==, G_ALIGNOF (GDoubleIEEE754));
      56                 :            : 
      57                 :          1 :   g_assert_null (gi_union_info_get_copy_function_name (double_info));
      58                 :          1 :   g_assert_null (gi_union_info_get_free_function_name (double_info));
      59                 :            : 
      60                 :          1 :   g_clear_pointer (&double_info, gi_base_info_unref);
      61                 :          1 : }
      62                 :            : 
      63                 :            : static void
      64                 :          1 : test_methods (RepositoryFixture *fx,
      65                 :            :               const void        *unused)
      66                 :            : {
      67                 :          1 :   GIUnionInfo *mutex_info = NULL;
      68                 :          1 :   GIFunctionInfo *method_info = NULL;
      69                 :            : 
      70                 :          1 :   g_test_summary ("Test retrieving methods from GIUnionInfo");
      71                 :            : 
      72                 :          1 :   mutex_info = GI_UNION_INFO (gi_repository_find_by_name (fx->repository, "GLib", "Mutex"));
      73                 :          1 :   g_assert_nonnull (mutex_info);
      74                 :            : 
      75                 :          1 :   g_assert_cmpuint (gi_union_info_get_n_methods (mutex_info), ==, 5);
      76                 :            : 
      77                 :          1 :   method_info = gi_union_info_get_method (mutex_info, 0);
      78                 :          1 :   g_assert_true (GI_IS_FUNCTION_INFO (method_info));
      79                 :          1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (method_info)), ==, "clear");
      80                 :          1 :   g_clear_pointer (&method_info, gi_base_info_unref);
      81                 :            : 
      82                 :          1 :   method_info = gi_union_info_find_method (mutex_info, "trylock");
      83                 :          1 :   g_assert_true (GI_IS_FUNCTION_INFO (method_info));
      84                 :          1 :   g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (method_info)), ==, "trylock");
      85                 :          1 :   g_clear_pointer (&method_info, gi_base_info_unref);
      86                 :            : 
      87                 :          1 :   g_clear_pointer (&mutex_info, gi_base_info_unref);
      88                 :          1 : }
      89                 :            : 
      90                 :            : int
      91                 :          1 : main (int argc,
      92                 :            :       char *argv[])
      93                 :            : {
      94                 :          1 :   repository_init (&argc, &argv);
      95                 :            : 
      96                 :          1 :   ADD_REPOSITORY_TEST ("/union-info/basic", test_basic, &typelib_load_spec_glib);
      97                 :          1 :   ADD_REPOSITORY_TEST ("/union-info/methods", test_methods, &typelib_load_spec_glib);
      98                 :            : 
      99                 :          1 :   return g_test_run ();
     100                 :            : }

Generated by: LCOV version 1.14