LCOV - code coverage report
Current view: top level - glib/gobject/tests - testing.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 12 18 66.7 %
Date: 2024-04-30 05:17:35 Functions: 2 3 66.7 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* GLib testing framework examples and tests
       2                 :            :  *
       3                 :            :  * Copyright © 2019 Endless Mobile, Inc.
       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: Philip Withnall <withnall@endlessm.com>
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : 
      25                 :            : /* We want to distinguish between messages originating from libglib
      26                 :            :  * and messages originating from this program.
      27                 :            :  */
      28                 :            : #undef G_LOG_DOMAIN
      29                 :            : #define G_LOG_DOMAIN "testing"
      30                 :            : 
      31                 :            : #include <glib.h>
      32                 :            : #include <glib-object.h>
      33                 :            : #include <locale.h>
      34                 :            : #include <stdlib.h>
      35                 :            : 
      36                 :            : static void
      37                 :          0 : test_assert_finalize_object_subprocess_bad (void)
      38                 :            : {
      39                 :          0 :   GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
      40                 :          0 :   g_object_ref (obj);
      41                 :            : 
      42                 :            :   /* This should emit an assertion failure. */
      43                 :          0 :   g_assert_finalize_object (obj);
      44                 :            : 
      45                 :          0 :   g_object_unref (obj);
      46                 :            : 
      47                 :          0 :   exit (0);
      48                 :            : }
      49                 :            : 
      50                 :            : static void
      51                 :          1 : test_assert_finalize_object (void)
      52                 :            : {
      53                 :          1 :   GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
      54                 :            : 
      55                 :          1 :   g_assert_finalize_object (obj);
      56                 :            : 
      57                 :          1 :   g_test_trap_subprocess ("/assert/finalize_object/subprocess/bad", 0,
      58                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
      59                 :          1 :   g_test_trap_assert_failed ();
      60                 :          1 :   g_test_trap_assert_stderr ("*g_assert_finalize_object:*'weak_pointer' should be NULL*");
      61                 :          1 : }
      62                 :            : 
      63                 :            : int
      64                 :          1 : main (int   argc,
      65                 :            :       char *argv[])
      66                 :            : {
      67                 :          1 :   g_test_init (&argc, &argv, NULL);
      68                 :            : 
      69                 :          1 :   g_test_add_func ("/assert/finalize_object", test_assert_finalize_object);
      70                 :          1 :   g_test_add_func ("/assert/finalize_object/subprocess/bad",
      71                 :            :                    test_assert_finalize_object_subprocess_bad);
      72                 :            : 
      73                 :          1 :   return g_test_run ();
      74                 :            : }

Generated by: LCOV version 1.14