Meson: Group all glib tests into a single dict
[glib.git] / gio / tests / mount-operation.c
blob0f8566ac77f5bc1a93d33b683a7483486cf54eac
1 /* GLib testing framework examples and tests
3 * Copyright © 2018 Endless Mobile, Inc.
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.
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.
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/>.
18 * Author: Philip Withnall <withnall@endlessm.com>
21 #include <gio/gio.h>
22 #include <locale.h>
25 /* Smoketest for construction of a #GMountOperation. */
26 static void
27 test_construction (void)
29 GMountOperation *op = NULL;
31 op = g_mount_operation_new ();
32 g_assert_nonnull (op);
33 g_assert_true (G_IS_MOUNT_OPERATION (op));
34 g_object_unref (op);
37 /* Test the property getters and setters on #GMountOperation work correctly. */
38 static void
39 test_properties (void)
41 GMountOperation *op = NULL;
42 gchar *username = NULL;
43 gchar *password = NULL;
44 gboolean anonymous;
45 gchar *domain = NULL;
46 GPasswordSave password_save;
47 int choice;
48 gboolean hidden_volume;
49 gboolean system_volume;
50 guint pim;
52 op = g_mount_operation_new ();
54 g_object_get (op,
55 "username", &username,
56 "password", &password,
57 "anonymous", &anonymous,
58 "domain", &domain,
59 "password-save", &password_save,
60 "choice", &choice,
61 "is-tcrypt-hidden-volume", &hidden_volume,
62 "is-tcrypt-system-volume", &system_volume,
63 "pim", &pim,
64 NULL);
66 g_assert_cmpstr (username, ==, g_mount_operation_get_username (op));
67 g_assert_cmpstr (password, ==, g_mount_operation_get_password (op));
68 g_assert_cmpint (anonymous, ==, g_mount_operation_get_anonymous (op));
69 g_assert_cmpstr (domain, ==, g_mount_operation_get_domain (op));
70 g_assert_cmpint (password_save, ==, g_mount_operation_get_password_save (op));
71 g_assert_cmpint (choice, ==, g_mount_operation_get_choice (op));
72 g_assert_cmpint (hidden_volume, ==, g_mount_operation_get_is_tcrypt_hidden_volume (op));
73 g_assert_cmpint (system_volume, ==, g_mount_operation_get_is_tcrypt_system_volume (op));
74 g_assert_cmpuint (pim, ==, g_mount_operation_get_pim (op));
76 g_mount_operation_set_username (op, "username");
77 g_assert_cmpstr (g_mount_operation_get_username (op), ==, "username");
79 g_mount_operation_set_password (op, "password");
80 g_assert_cmpstr (g_mount_operation_get_password (op), ==, "password");
82 g_mount_operation_set_anonymous (op, !anonymous);
83 g_assert_cmpint (g_mount_operation_get_anonymous (op), ==, !anonymous);
85 g_mount_operation_set_domain (op, "domain");
86 g_assert_cmpstr (g_mount_operation_get_domain (op), ==, "domain");
88 g_mount_operation_set_password_save (op, G_PASSWORD_SAVE_NEVER);
89 g_assert_cmpint (g_mount_operation_get_password_save (op), ==, G_PASSWORD_SAVE_NEVER);
91 g_mount_operation_set_choice (op, 5);
92 g_assert_cmpint (g_mount_operation_get_choice (op), ==, 5);
94 g_mount_operation_set_is_tcrypt_hidden_volume (op, !hidden_volume);
95 g_assert_cmpint (g_mount_operation_get_is_tcrypt_hidden_volume (op), ==, !hidden_volume);
97 g_mount_operation_set_is_tcrypt_system_volume (op, !system_volume);
98 g_assert_cmpint (g_mount_operation_get_is_tcrypt_system_volume (op), ==, !system_volume);
100 g_mount_operation_set_pim (op, 5);
101 g_assert_cmpuint (g_mount_operation_get_pim (op), ==, 5);
103 g_object_set (op,
104 "username", "other-username",
105 "password", "other-password",
106 "anonymous", FALSE,
107 "domain", "other-domain",
108 "password-save", G_PASSWORD_SAVE_PERMANENTLY,
109 "choice", 4,
110 "is-tcrypt-hidden-volume", FALSE,
111 "is-tcrypt-system-volume", FALSE,
112 "pim", 4,
113 NULL);
115 g_free (domain);
116 g_free (password);
117 g_free (username);
118 g_object_unref (op);
122 main (int argc,
123 char *argv[])
125 setlocale (LC_ALL, "");
126 g_test_init (&argc, &argv, NULL);
128 g_test_add_func ("/mount-operation/construction", test_construction);
129 g_test_add_func ("/mount-operation/properties", test_properties);
131 return g_test_run ();