LCOV - code coverage report
Current view: top level - glib/gio/tests - tls-database.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 29 29 100.0 %
Date: 2024-04-23 05:16:05 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* GLib testing framework examples and tests
       2                 :            :  *
       3                 :            :  * Copyright (C) Matthew Waters <matthew@centricular.com>.
       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                 :            : 
      21                 :            : #include "config.h"
      22                 :            : 
      23                 :            : #include <gio/gio.h>
      24                 :            : 
      25                 :            : #include "gtesttlsbackend.h"
      26                 :            : 
      27                 :            : static void
      28                 :          1 : set_default_database (void)
      29                 :            : {
      30                 :            :   GTlsBackend *backend;
      31                 :            :   GTlsDatabase *default_db, *file_db, *test_db;
      32                 :          1 :   GError *error = NULL;
      33                 :            :   gchar *path;
      34                 :            : 
      35                 :          1 :   backend = g_tls_backend_get_default ();
      36                 :          1 :   g_assert_nonnull (backend);
      37                 :            : 
      38                 :          1 :   default_db = g_tls_backend_get_default_database (backend);
      39                 :          1 :   g_assert_nonnull (default_db);
      40                 :            : 
      41                 :          1 :   path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert1.pem", NULL);
      42                 :          1 :   file_db = g_tls_file_database_new (path, &error);
      43                 :          1 :   g_assert_no_error (error);
      44                 :          1 :   g_assert_nonnull (file_db);
      45                 :            : 
      46                 :            :   /* setting a default database makes get_default_database return that database */
      47                 :          1 :   g_tls_backend_set_default_database (backend, file_db);
      48                 :          1 :   test_db = g_tls_backend_get_default_database (backend);
      49                 :          1 :   g_assert_nonnull (test_db);
      50                 :          1 :   g_assert_true (test_db == file_db);
      51                 :          1 :   g_object_unref (test_db);
      52                 :            : 
      53                 :            :   /* setting a NULL default database returns the original default database */
      54                 :          1 :   g_tls_backend_set_default_database (backend, NULL);
      55                 :          1 :   test_db = g_tls_backend_get_default_database (backend);
      56                 :          1 :   g_assert_nonnull (test_db);
      57                 :          1 :   g_assert_true (test_db == default_db);
      58                 :            : 
      59                 :          1 :   g_object_unref (default_db);
      60                 :          1 :   g_object_unref (file_db);
      61                 :          1 :   g_object_unref (test_db);
      62                 :          1 :   g_free (path);
      63                 :          1 : }
      64                 :            : 
      65                 :            : int
      66                 :          1 : main (int   argc,
      67                 :            :       char *argv[])
      68                 :            : {
      69                 :          1 :   g_test_init (&argc, &argv, NULL);
      70                 :            : 
      71                 :          1 :   _g_test_tls_backend_get_type ();
      72                 :            : 
      73                 :          1 :   g_test_add_func ("/tls-backend/set-default-database",
      74                 :            :                    set_default_database);
      75                 :            : 
      76                 :          1 :   return g_test_run();
      77                 :            : }

Generated by: LCOV version 1.14