Sat, 09 Aug 2025 17:37:27 +0800
Fix the birb header path
The birb header referred would only work with birb provided by wrap casuing
build to fail because of system-installed birb dependency. The commit points
it to the correct path <birb.h>.
See: https://keep.imfreedom.org/birb/birb/file/5bf00c7d7f80/birb/meson.build#l77
| 42844 | 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 | ||
|
43265
7960b5f85729
Update to birb 0.4 and use the testing helpers in libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
43100
diff
changeset
|
21 | #include <birb.h> |
| 42844 | 22 | |
|
43265
7960b5f85729
Update to birb 0.4 and use the testing helpers in libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
43100
diff
changeset
|
23 | #include <purple.h> |
| 42844 | 24 | |
| 25 | /****************************************************************************** | |
| 26 | * Tests | |
| 27 | *****************************************************************************/ | |
| 28 | static void | |
| 29 | test_purple_message_new_with_conversation(void) { | |
| 30 | PurpleAccount *account = NULL; | |
| 31 | PurpleConversation *conversation = NULL; | |
| 32 | PurpleMessages *messages = NULL; | |
| 33 | ||
| 34 | account = purple_account_new("test", "test"); | |
| 35 | conversation = g_object_new( | |
| 36 | PURPLE_TYPE_CONVERSATION, | |
| 37 | "account", account, | |
| 38 | NULL); | |
| 39 | ||
| 40 | messages = purple_messages_new(conversation); | |
| 41 | g_assert_true(PURPLE_IS_MESSAGES(messages)); | |
| 42 | g_assert_true(G_IS_LIST_MODEL(messages)); | |
| 43 | ||
| 44 | g_assert_finalize_object(messages); | |
| 45 | g_assert_finalize_object(conversation); | |
| 46 | g_clear_object(&account); | |
| 47 | } | |
| 48 | ||
| 49 | static void | |
| 50 | test_purple_message_new_without_conversation(void) { | |
| 51 | if(g_test_subprocess()) { | |
| 52 | PurpleMessages *messages = NULL; | |
| 53 | ||
| 54 | messages = purple_messages_new(NULL); | |
| 55 | g_assert_null(messages); | |
| 56 | ||
| 57 | g_assert_not_reached(); | |
| 58 | } | |
| 59 | ||
| 60 | g_test_trap_subprocess(NULL, 0, 0); | |
| 61 | g_test_trap_assert_stderr("*CRITICAL*IS_CONVERSATION*failed*"); | |
| 62 | } | |
| 63 | ||
| 64 | static void | |
| 65 | test_purple_messages_properties(void) { | |
| 66 | PurpleAccount *account = NULL; | |
| 67 | PurpleConversation *conversation1 = NULL; | |
| 68 | PurpleConversation *conversation2 = NULL; | |
| 69 | PurpleMessages *messages = NULL; | |
| 70 | ||
| 71 | account = purple_account_new("test", "test"); | |
| 72 | conversation1 = g_object_new( | |
| 73 | PURPLE_TYPE_CONVERSATION, | |
| 74 | "account", account, | |
| 75 | NULL); | |
| 76 | ||
| 77 | messages = g_object_new( | |
| 78 | PURPLE_TYPE_MESSAGES, | |
| 79 | "conversation", conversation1, | |
| 80 | NULL); | |
| 81 | ||
| 82 | g_object_get( | |
| 83 | G_OBJECT(messages), | |
| 84 | "conversation", &conversation2, | |
| 85 | NULL); | |
| 86 | ||
| 87 | g_assert_true(conversation2 == conversation1); | |
| 88 | g_clear_object(&conversation2); | |
| 89 | ||
| 90 | g_assert_finalize_object(messages); | |
| 91 | g_assert_finalize_object(conversation1); | |
| 92 | g_clear_object(&account); | |
| 93 | } | |
| 94 | ||
| 95 | static void | |
| 96 | test_purple_messages_add_single(void) { | |
| 97 | PurpleAccount *account = NULL; | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
98 | PurpleContactInfo *info = NULL; |
| 42844 | 99 | PurpleConversation *conversation = NULL; |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
100 | PurpleConversationMember *author = NULL; |
| 42844 | 101 | PurpleMessage *message1 = NULL; |
| 102 | PurpleMessage *message2 = NULL; | |
| 103 | PurpleMessages *messages = NULL; | |
| 104 | guint counter = 0; | |
| 105 | ||
| 106 | account = purple_account_new("test", "test"); | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
107 | info = purple_account_get_contact_info(account); |
| 42844 | 108 | conversation = g_object_new( |
| 109 | PURPLE_TYPE_CONVERSATION, | |
| 110 | "account", account, | |
| 111 | NULL); | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
112 | author = purple_conversation_find_or_add_member(conversation, info, FALSE, |
|
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
113 | NULL); |
| 42844 | 114 | |
| 115 | messages = purple_messages_new(conversation); | |
|
43265
7960b5f85729
Update to birb 0.4 and use the testing helpers in libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
43100
diff
changeset
|
116 | birb_count_list_model_items_changed(G_LIST_MODEL(messages), &counter); |
| 42844 | 117 | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
118 | message1 = purple_message_new(author, "test message"); |
| 42844 | 119 | purple_messages_add(messages, message1); |
| 120 | g_assert_cmpuint(counter, ==, 1); | |
| 121 | ||
| 122 | message2 = g_list_model_get_item(G_LIST_MODEL(messages), 0); | |
| 123 | g_assert_true(PURPLE_IS_MESSAGE(message2)); | |
| 124 | g_assert_true(message2 == message1); | |
| 125 | g_clear_object(&message2); | |
| 126 | ||
| 127 | g_assert_finalize_object(messages); | |
| 128 | g_assert_finalize_object(message1); | |
| 129 | g_assert_finalize_object(conversation); | |
| 130 | g_clear_object(&account); | |
| 131 | } | |
| 132 | ||
| 133 | static void | |
| 134 | test_purple_messages_add_multiple(void) { | |
| 135 | PurpleAccount *account = NULL; | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
136 | PurpleContactInfo *info = NULL; |
| 42844 | 137 | PurpleConversation *conversation = NULL; |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
138 | PurpleConversationMember *author = NULL; |
| 42844 | 139 | PurpleMessage *message = NULL; |
| 140 | PurpleMessage *message1 = NULL; | |
| 141 | PurpleMessage *message2 = NULL; | |
| 142 | PurpleMessages *messages = NULL; | |
| 143 | GDateTime *dt1 = NULL; | |
| 144 | GDateTime *dt2 = NULL; | |
| 145 | GTimeZone *zone = NULL; | |
| 146 | guint counter = 0; | |
| 147 | ||
| 148 | /* This test adds two messages to the collection, the first one has an | |
| 149 | * older timestamp than the first, which lets us test the automatic | |
| 150 | * sorting. | |
| 151 | */ | |
| 152 | ||
| 153 | account = purple_account_new("test", "test"); | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
154 | info = purple_account_get_contact_info(account); |
| 42844 | 155 | conversation = g_object_new( |
| 156 | PURPLE_TYPE_CONVERSATION, | |
| 157 | "account", account, | |
| 158 | NULL); | |
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
159 | author = purple_conversation_find_or_add_member(conversation, info, FALSE, |
|
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
160 | NULL); |
| 42844 | 161 | |
| 162 | messages = purple_messages_new(conversation); | |
|
43265
7960b5f85729
Update to birb 0.4 and use the testing helpers in libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
43100
diff
changeset
|
163 | birb_count_list_model_items_changed(G_LIST_MODEL(messages), &counter); |
| 42844 | 164 | |
| 165 | zone = g_time_zone_new_utc(); | |
| 166 | ||
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
167 | message1 = purple_message_new(author, "second message"); |
| 42844 | 168 | dt1 = g_date_time_new_from_iso8601("2024-08-07T03:07:33+0000", zone); |
| 169 | purple_message_set_timestamp(message1, dt1); | |
| 170 | g_clear_pointer(&dt1, g_date_time_unref); | |
| 171 | purple_messages_add(messages, message1); | |
| 172 | g_assert_cmpuint(counter, ==, 1); | |
| 173 | ||
|
43100
e6df74d36862
Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents:
42844
diff
changeset
|
174 | message2 = purple_message_new(author, "first message"); |
| 42844 | 175 | dt2 = g_date_time_new_from_iso8601("2024-08-07T03:06:33+0000", zone); |
| 176 | purple_message_set_timestamp(message2, dt2); | |
| 177 | g_clear_pointer(&dt2, g_date_time_unref); | |
| 178 | purple_messages_add(messages, message2); | |
| 179 | g_assert_cmpuint(counter, ==, 2); | |
| 180 | ||
| 181 | /* Make sure that the first item in the list is message2. */ | |
| 182 | message = g_list_model_get_item(G_LIST_MODEL(messages), 0); | |
| 183 | g_assert_true(PURPLE_IS_MESSAGE(message)); | |
| 184 | g_assert_true(message == message2); | |
| 185 | g_clear_object(&message); | |
| 186 | ||
| 187 | /* Make sure that the second item in the list is message1. */ | |
| 188 | message = g_list_model_get_item(G_LIST_MODEL(messages), 1); | |
| 189 | g_assert_true(PURPLE_IS_MESSAGE(message)); | |
| 190 | g_assert_true(message == message1); | |
| 191 | g_clear_object(&message); | |
| 192 | ||
| 193 | g_clear_pointer(&zone, g_time_zone_unref); | |
| 194 | g_assert_finalize_object(messages); | |
| 195 | g_assert_finalize_object(message1); | |
| 196 | g_assert_finalize_object(message2); | |
| 197 | g_assert_finalize_object(conversation); | |
| 198 | g_clear_object(&account); | |
| 199 | } | |
| 200 | ||
| 201 | /****************************************************************************** | |
| 202 | * Main | |
| 203 | *****************************************************************************/ | |
| 204 | int | |
| 205 | main(int argc, char *argv[]) { | |
| 206 | g_test_init(&argc, &argv, NULL); | |
| 207 | g_test_set_nonfatal_assertions(); | |
| 208 | ||
| 209 | g_test_add_func("/messages/new/with-conversation", | |
| 210 | test_purple_message_new_with_conversation); | |
| 211 | g_test_add_func("/messages/new/without-conversation", | |
| 212 | test_purple_message_new_without_conversation); | |
| 213 | ||
| 214 | g_test_add_func("/messages/properties", test_purple_messages_properties); | |
| 215 | ||
| 216 | g_test_add_func("/messages/add/single", test_purple_messages_add_single); | |
| 217 | g_test_add_func("/messages/add/multiple", | |
| 218 | test_purple_messages_add_multiple); | |
| 219 | ||
| 220 | return g_test_run(); | |
| 221 | } |