libpurple/tests/test_notification.c

Sun, 10 Aug 2025 23:44:08 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:44:08 +0800
branch
purple_conversation_find_message_by_id
changeset 43309
099e1dfb856b
parent 43181
ccc35f487917
permissions
-rw-r--r--

Add Purple.Conversation.find_message_by_id

The method was added so that a protocol or plugin could easily lookup
for the reference for a message. This will be especially useful when a
protocol received a quoted message but only with an id.

41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
21 #include <birb.h>
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
22
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <purple.h>
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 * Tests
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 test_purple_notification_new(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 PurpleNotification *notification = NULL;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 GDateTime *created_timestamp = NULL;
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42648
diff changeset
32 const char *id = NULL;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
42988
c2357ee36551 Replace Purple.Notification.new_generic with Purple.Notification.new
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
34 notification = purple_notification_new(NULL, NULL);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 /* Make sure we got a valid notification. */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 g_assert_true(PURPLE_IS_NOTIFICATION(notification));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 /* Make sure that the id was generated. */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 id = purple_notification_get_id(notification);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 g_assert_nonnull(id);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
43181
ccc35f487917 Set Purple.Notification:create-timestamp to local now if not set
Gary Kramlich <grim@reaperworld.com>
parents: 42988
diff changeset
43 /* Make sure that the created-timestamp was set. */
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 created_timestamp = purple_notification_get_created_timestamp(notification);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 g_assert_nonnull(created_timestamp);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
42871
210e5f7d72a3 Modernize the Purple.Notification tests
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
47 g_assert_finalize_object(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 test_purple_notification_properties(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 PurpleNotification *notification = NULL;
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
53 GDateTime *created_timestamp = NULL;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
54 GDateTime *created_timestamp1 = NULL;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
55 char *icon_name1 = NULL;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
56 char *subtitle1 = NULL;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
57 char *title1 = NULL;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
58 gboolean interactive = FALSE;
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
59 gboolean persistent = FALSE;
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
60 gboolean read = FALSE;
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
61
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
62 created_timestamp = g_date_time_new_now_utc();
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
64 notification = g_object_new(
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
65 PURPLE_TYPE_NOTIFICATION,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
66 "created-timestamp", created_timestamp,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
67 "icon-name", "icon-name",
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
68 "interactive", TRUE,
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
69 "persistent", TRUE,
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
70 "read", TRUE,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
71 "subtitle", "subtitle",
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
72 "title", "title",
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
73 NULL);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 g_assert_true(PURPLE_IS_NOTIFICATION(notification));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
77 g_object_get(
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
78 notification,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
79 "created-timestamp", &created_timestamp1,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
80 "icon-name", &icon_name1,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
81 "interactive", &interactive,
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
82 "persistent", &persistent,
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
83 "read", &read,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
84 "subtitle", &subtitle1,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
85 "title", &title1,
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
86 NULL);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
88 g_assert_nonnull(created_timestamp1);
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
89 g_assert_true(g_date_time_equal(created_timestamp, created_timestamp1));
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
90 g_date_time_unref(created_timestamp1);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
92 g_assert_cmpstr(icon_name1, ==, "icon-name");
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
93 g_clear_pointer(&icon_name1, g_free);
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
94
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
95 g_assert_true(interactive);
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
96 g_assert_true(persistent);
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
97 g_assert_true(read);
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
98
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
99 g_assert_cmpstr(subtitle1, ==, "subtitle");
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
100 g_clear_pointer(&subtitle1, g_free);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
42909
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
102 g_assert_cmpstr(title1, ==, "title");
440ed16de928 Add a persistent property to Purple.Notification
Gary Kramlich <grim@reaperworld.com>
parents: 42871
diff changeset
103 g_clear_pointer(&title1, g_free);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104
42871
210e5f7d72a3 Modernize the Purple.Notification tests
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
105 g_date_time_unref(created_timestamp);
210e5f7d72a3 Modernize the Purple.Notification tests
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
106 g_assert_finalize_object(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 * Main
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 *****************************************************************************/
42648
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
112 int
70d33d4dac09 Add a subtitle property to PurpleNotification
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
113 main(int argc, char *argv[]) {
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 g_test_init(&argc, &argv, NULL);
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42648
diff changeset
115 g_test_set_nonfatal_assertions();
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 g_test_add_func("/notification/new",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 test_purple_notification_new);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 g_test_add_func("/notification/properties",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 test_purple_notification_properties);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42648
diff changeset
122 return g_test_run();
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 }

mercurial