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
|
43057
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * This library is free software; you can redistribute it and/or |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * modify it under the terms of the GNU Lesser General Public |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * License as published by the Free Software Foundation; either |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * version 2 of the License, or (at your option) any later version. |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * This library is distributed in the hope that it will be useful, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * Lesser General Public License for more details. |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU Lesser General Public |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | */ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | #include <glib.h> |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | #include <purple.h> |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | /****************************************************************************** |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | * Test Protocol |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | *****************************************************************************/ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | G_DECLARE_FINAL_TYPE(TestPurpleCommandsProtocol, test_purple_commands_protocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | TEST_PURPLE, COMMANDS_PROTOCOL, PurpleProtocol) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | struct _TestPurpleCommandsProtocol { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | PurpleProtocol parent; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | }; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | test_purple_commands_protocol_send_message_async(PurpleProtocolConversation *protocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | PurpleConversation *conversation, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | PurpleMessage *message, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | GCancellable *cancellable, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | GAsyncReadyCallback callback, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | gpointer data) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | GTask *task = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | task = g_task_new(G_OBJECT(protocol), cancellable, callback, data); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | g_task_return_boolean(task, TRUE); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | g_clear_object(&task); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | purple_conversation_write_message(conversation, message); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | static gboolean |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | test_purple_commands_protocol_send_message_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | GAsyncResult* result, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | GError** error) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | return g_task_propagate_boolean(G_TASK(result), error); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | test_purple_commands_protocol_conversation_init(PurpleProtocolConversationInterface *iface) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | iface->send_message_async = |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | test_purple_commands_protocol_send_message_async; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | iface->send_message_finish = |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | test_purple_commands_protocol_send_message_finish; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleCommandsProtocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | test_purple_commands_protocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | PURPLE_TYPE_PROTOCOL, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_CONVERSATION, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | test_purple_commands_protocol_conversation_init)) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | test_purple_commands_protocol_init(G_GNUC_UNUSED TestPurpleCommandsProtocol *protocol) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | test_purple_commands_protocol_class_init(G_GNUC_UNUSED TestPurpleCommandsProtocolClass *klass) |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | static PurpleProtocol * |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | test_purple_commands_protocol_new(void) { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | return g_object_new( |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | test_purple_commands_protocol_get_type(), |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | "id", "test", |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | "name", "test", |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | NULL); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | /****************************************************************************** |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | * Helpers |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | *****************************************************************************/ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | static PurpleConversation * |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | test_purple_commands_create_conversation(void) { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | PurpleAccount *account = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | PurpleConversation *conversation = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | PurpleProtocol *protocol = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | protocol = test_purple_commands_protocol_new(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | account = g_object_new(PURPLE_TYPE_ACCOUNT, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | "protocol", protocol, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | "username", "slater", |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | NULL); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | g_clear_object(&protocol); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | conversation = g_object_new( |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | PURPLE_TYPE_CONVERSATION, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 | "account", account, |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | NULL); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | g_clear_object(&account); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | return conversation; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | /****************************************************************************** |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | * Tests |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | *****************************************************************************/ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | test_purple_commands_say_execute(void) { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | PurpleCommand *command = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 | PurpleConversation *conversation = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 | PurpleMessage *message = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | GListModel *messages = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 | const char *contents = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | conversation = test_purple_commands_create_conversation(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 | command = purple_say_command_new(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 | purple_command_execute(command, conversation, "my name"); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | /* We have to iterate the main loop as this command calls an async method |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | * which holds an extra reference on the command. */ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 | g_main_context_iteration(NULL, FALSE); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 | g_assert_cmpuint(purple_command_get_use_count(command), ==, 1); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 | g_assert_finalize_object(command); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 | messages = purple_conversation_get_messages(conversation); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 | g_assert_true(G_IS_LIST_MODEL(messages)); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
143 | g_assert_cmpuint(g_list_model_get_n_items(messages), ==, 1); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 | message = g_list_model_get_item(messages, 0); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 | g_assert_true(PURPLE_IS_MESSAGE(message)); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 | contents = purple_message_get_contents(message); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | g_assert_cmpstr(contents, ==, "my name"); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 | /* The message still exists in the conversation, so we can only removed our |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 | * reference which we got from g_list_model_get_item above. |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 | */ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 | g_clear_object(&message); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 | g_assert_finalize_object(conversation); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 | static void |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 | test_purple_commands_action_execute(void) { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | PurpleCommand *command = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | PurpleConversation *conversation = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 | PurpleMessage *message = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 | GListModel *messages = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 | const char *contents = NULL; |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 | conversation = test_purple_commands_create_conversation(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 | command = purple_action_command_new(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 | purple_command_execute(command, conversation, "sighs"); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 | /* We have to iterate the main loop as this command calls an async method |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 | * which holds an extra reference on the command. */ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 | g_main_context_iteration(NULL, FALSE); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 | g_assert_cmpuint(purple_command_get_use_count(command), ==, 1); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | g_assert_finalize_object(command); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | messages = purple_conversation_get_messages(conversation); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | g_assert_true(G_IS_LIST_MODEL(messages)); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 | g_assert_cmpuint(g_list_model_get_n_items(messages), ==, 1); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | message = g_list_model_get_item(messages, 0); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | g_assert_true(PURPLE_IS_MESSAGE(message)); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | contents = purple_message_get_contents(message); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | g_assert_cmpstr(contents, ==, "sighs"); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | g_assert_true(purple_message_get_action(message)); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | /* The message still exists in the conversation, so we can only removed our |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | * reference which we got from g_list_model_get_item above. |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 | */ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 | g_clear_object(&message); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 | g_assert_finalize_object(conversation); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 | } |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 | /****************************************************************************** |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 | * Main |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 | *****************************************************************************/ |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 | int |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 | main(int argc, char *argv[]) { |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
204 | g_test_init(&argc, &argv, NULL); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
205 | g_test_set_nonfatal_assertions(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
206 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
207 | g_test_add_func("/commands/say/execute", test_purple_commands_say_execute); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 | g_test_add_func("/commands/action/execute", |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
209 | test_purple_commands_action_execute); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
210 | |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
211 | return g_test_run(); |
|
2c801eae5449
Add commands for say and action
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
212 | } |