| |
1 /* |
| |
2 * Purple - Internet Messaging Library |
| |
3 * Copyright (C) Pidgin Developers <devel@pidgin.im> |
| |
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 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 Public |
| |
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| |
17 */ |
| |
18 |
| |
19 #include <glib.h> |
| |
20 |
| |
21 #include <purple.h> |
| |
22 |
| |
23 #include "test_ui.h" |
| |
24 |
| |
25 /****************************************************************************** |
| |
26 * Callbacks |
| |
27 *****************************************************************************/ |
| |
28 static void |
| |
29 test_purple_notification_authorization_request_notify_cb(GObject *obj, |
| |
30 G_GNUC_UNUSED GParamSpec *pspec, |
| |
31 gpointer data) |
| |
32 { |
| |
33 guint *counter = data; |
| |
34 |
| |
35 g_assert_true(PURPLE_IS_NOTIFICATION(obj)); |
| |
36 |
| |
37 *counter = *counter + 1; |
| |
38 } |
| |
39 |
| |
40 /****************************************************************************** |
| |
41 * Tests |
| |
42 *****************************************************************************/ |
| |
43 static void |
| |
44 test_purple_notification_authorization_request_new(void) { |
| |
45 PurpleAccount *account = NULL; |
| |
46 PurpleAuthorizationRequest *request = NULL; |
| |
47 PurpleNotification *notification = NULL; |
| |
48 |
| |
49 account = purple_account_new("test", "test"); |
| |
50 request = purple_authorization_request_new(account, "remote-username"); |
| |
51 notification = purple_notification_authorization_request_new(request); |
| |
52 |
| |
53 g_assert_true(PURPLE_IS_NOTIFICATION(notification)); |
| |
54 g_assert_true(PURPLE_IS_NOTIFICATION_AUTHORIZATION_REQUEST(notification)); |
| |
55 |
| |
56 g_assert_finalize_object(notification); |
| |
57 |
| |
58 g_clear_object(&request); |
| |
59 g_clear_object(&account); |
| |
60 } |
| |
61 |
| |
62 static void |
| |
63 test_purple_notification_authorization_request_properties(void) { |
| |
64 PurpleAccount *account = NULL; |
| |
65 PurpleAuthorizationRequest *request = NULL; |
| |
66 PurpleAuthorizationRequest *request1 = NULL; |
| |
67 PurpleNotification *notification = NULL; |
| |
68 |
| |
69 account = purple_account_new("test", "test"); |
| |
70 request = purple_authorization_request_new(account, "username"); |
| |
71 |
| |
72 notification = g_object_new( |
| |
73 PURPLE_TYPE_NOTIFICATION_AUTHORIZATION_REQUEST, |
| |
74 "account", account, |
| |
75 "authorization-request", request, |
| |
76 NULL); |
| |
77 |
| |
78 g_object_get( |
| |
79 notification, |
| |
80 "authorization-request", &request1, |
| |
81 NULL); |
| |
82 |
| |
83 g_assert_true(request1 == request); |
| |
84 g_clear_object(&request1); |
| |
85 |
| |
86 g_assert_finalize_object(notification); |
| |
87 |
| |
88 g_clear_object(&request); |
| |
89 g_clear_object(&account); |
| |
90 } |
| |
91 |
| |
92 static void |
| |
93 test_purple_notification_authorization_request_updates_title(void) { |
| |
94 PurpleAccount *account = NULL; |
| |
95 PurpleAuthorizationRequest *request = NULL; |
| |
96 PurpleNotification *notification = NULL; |
| |
97 guint counter = 0; |
| |
98 |
| |
99 account = purple_account_new("test", "test"); |
| |
100 request = purple_authorization_request_new(account, "remote-username"); |
| |
101 |
| |
102 notification = purple_notification_authorization_request_new(request); |
| |
103 g_signal_connect(notification, "notify::title", |
| |
104 G_CALLBACK(test_purple_notification_authorization_request_notify_cb), |
| |
105 &counter); |
| |
106 |
| |
107 g_assert_cmpuint(counter, ==, 0); |
| |
108 |
| |
109 purple_authorization_request_set_alias(request, "foo"); |
| |
110 |
| |
111 g_assert_cmpuint(counter, ==, 1); |
| |
112 |
| |
113 g_assert_finalize_object(notification); |
| |
114 |
| |
115 g_clear_object(&request); |
| |
116 g_clear_object(&account); |
| |
117 } |
| |
118 |
| |
119 /****************************************************************************** |
| |
120 * Main |
| |
121 *****************************************************************************/ |
| |
122 gint |
| |
123 main(gint argc, gchar *argv[]) { |
| |
124 gint ret = 0; |
| |
125 |
| |
126 g_test_init(&argc, &argv, NULL); |
| |
127 |
| |
128 test_ui_purple_init(); |
| |
129 |
| |
130 g_test_add_func("/notification-request-authorization/new", |
| |
131 test_purple_notification_authorization_request_new); |
| |
132 g_test_add_func("/notification-request-authorization/properties", |
| |
133 test_purple_notification_authorization_request_properties); |
| |
134 g_test_add_func("/notification-request-authorization/updates-title", |
| |
135 test_purple_notification_authorization_request_updates_title); |
| |
136 |
| |
137 ret = g_test_run(); |
| |
138 |
| |
139 test_ui_purple_uninit(); |
| |
140 |
| |
141 return ret; |
| |
142 } |