1 | /* GLib testing framework examples and tests |
2 | * |
3 | * Copyright © 2018 Endless Mobile, Inc. |
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 | * Author: Philip Withnall <withnall@endlessm.com> |
19 | */ |
20 | |
21 | #include <gio/gio.h> |
22 | #include <locale.h> |
23 | |
24 | |
25 | /* Smoketest for construction of a #GMountOperation. */ |
26 | static void |
27 | test_construction (void) |
28 | { |
29 | GMountOperation *op = NULL; |
30 | |
31 | op = g_mount_operation_new (); |
32 | g_assert_nonnull (op); |
33 | g_assert_true (G_IS_MOUNT_OPERATION (op)); |
34 | g_object_unref (object: op); |
35 | } |
36 | |
37 | /* Test the property getters and setters on #GMountOperation work correctly. */ |
38 | static void |
39 | test_properties (void) |
40 | { |
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; |
51 | |
52 | op = g_mount_operation_new (); |
53 | |
54 | g_object_get (object: op, |
55 | first_property_name: "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); |
65 | |
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)); |
75 | |
76 | g_mount_operation_set_username (op, username: "username" ); |
77 | g_assert_cmpstr (g_mount_operation_get_username (op), ==, "username" ); |
78 | |
79 | g_mount_operation_set_password (op, password: "password" ); |
80 | g_assert_cmpstr (g_mount_operation_get_password (op), ==, "password" ); |
81 | |
82 | g_mount_operation_set_anonymous (op, anonymous: !anonymous); |
83 | g_assert_cmpint (g_mount_operation_get_anonymous (op), ==, !anonymous); |
84 | |
85 | g_mount_operation_set_domain (op, domain: "domain" ); |
86 | g_assert_cmpstr (g_mount_operation_get_domain (op), ==, "domain" ); |
87 | |
88 | g_mount_operation_set_password_save (op, save: G_PASSWORD_SAVE_NEVER); |
89 | g_assert_cmpint (g_mount_operation_get_password_save (op), ==, G_PASSWORD_SAVE_NEVER); |
90 | |
91 | g_mount_operation_set_choice (op, choice: 5); |
92 | g_assert_cmpint (g_mount_operation_get_choice (op), ==, 5); |
93 | |
94 | g_mount_operation_set_is_tcrypt_hidden_volume (op, hidden_volume: !hidden_volume); |
95 | g_assert_cmpint (g_mount_operation_get_is_tcrypt_hidden_volume (op), ==, !hidden_volume); |
96 | |
97 | g_mount_operation_set_is_tcrypt_system_volume (op, system_volume: !system_volume); |
98 | g_assert_cmpint (g_mount_operation_get_is_tcrypt_system_volume (op), ==, !system_volume); |
99 | |
100 | g_mount_operation_set_pim (op, pim: 5); |
101 | g_assert_cmpuint (g_mount_operation_get_pim (op), ==, 5); |
102 | |
103 | g_object_set (object: op, |
104 | first_property_name: "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); |
114 | |
115 | g_free (mem: domain); |
116 | g_free (mem: password); |
117 | g_free (mem: username); |
118 | g_object_unref (object: op); |
119 | } |
120 | |
121 | int |
122 | main (int argc, |
123 | char *argv[]) |
124 | { |
125 | setlocale (LC_ALL, locale: "" ); |
126 | g_test_init (argc: &argc, argv: &argv, NULL); |
127 | |
128 | g_test_add_func (testpath: "/mount-operation/construction" , test_func: test_construction); |
129 | g_test_add_func (testpath: "/mount-operation/properties" , test_func: test_properties); |
130 | |
131 | return g_test_run (); |
132 | } |
133 | |