1/* GLib testing framework examples and tests
2 *
3 * Copyright (C) Matthew Waters <matthew@centricular.com>.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "config.h"
20
21#include <gio/gio.h>
22
23#include "gtesttlsbackend.h"
24
25static void
26set_default_database (void)
27{
28 GTlsBackend *backend;
29 GTlsDatabase *default_db, *file_db, *test_db;
30 GError *error = NULL;
31 gchar *path;
32
33 backend = g_tls_backend_get_default ();
34 g_assert_nonnull (backend);
35
36 default_db = g_tls_backend_get_default_database (backend);
37 g_assert_nonnull (default_db);
38
39 path = g_test_build_filename (file_type: G_TEST_DIST, first_path: "cert-tests", "cert1.pem", NULL);
40 file_db = g_tls_file_database_new (anchors: path, error: &error);
41 g_assert_no_error (error);
42 g_assert_nonnull (file_db);
43
44 /* setting a default database makes get_default_database return that database */
45 g_tls_backend_set_default_database (backend, database: file_db);
46 test_db = g_tls_backend_get_default_database (backend);
47 g_assert_nonnull (test_db);
48 g_assert_true (test_db == file_db);
49 g_object_unref (object: test_db);
50
51 /* setting a NULL default database returns the original default database */
52 g_tls_backend_set_default_database (backend, NULL);
53 test_db = g_tls_backend_get_default_database (backend);
54 g_assert_nonnull (test_db);
55 g_assert_true (test_db == default_db);
56
57 g_object_unref (object: default_db);
58 g_object_unref (object: file_db);
59 g_object_unref (object: test_db);
60 g_free (mem: path);
61}
62
63int
64main (int argc,
65 char *argv[])
66{
67 g_test_init (argc: &argc, argv: &argv, NULL);
68
69 _g_test_tls_backend_get_type ();
70
71 g_test_add_func (testpath: "/tls-backend/set-default-database",
72 test_func: set_default_database);
73
74 return g_test_run();
75}
76

source code of gtk/subprojects/glib/gio/tests/tls-database.c