libpurple/tests/test_command.c

Tue, 24 Sep 2024 21:28:06 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 24 Sep 2024 21:28:06 -0500
changeset 42967
9da19bb7e207
parent 42964
f0edc907e018
permissions
-rw-r--r--

Add a tags property to Purple.Command

Testing Done:
Ran the tests under valgrind and called in the turtles for good measure.

Bugs closed: PIDGIN-17973

Reviewed at https://reviews.imfreedom.org/r/3523/

42964
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include <purple.h>
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 /******************************************************************************
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 * Tests
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 *****************************************************************************/
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 test_purple_command_new(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 command = purple_command_new("name", "source", 100);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 g_assert_true(PURPLE_IS_COMMAND(command));
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 test_purple_command_properties(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleCommand *command = NULL;
42967
9da19bb7e207 Add a tags property to Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents: 42964
diff changeset
39 PurpleTags *tags = NULL;
42964
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 GDateTime *last_used1 = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 char *icon_name = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 char *name = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 char *source = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 char *summary = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 int priority = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 last_used = g_date_time_new_now_utc();
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 command = g_object_new(
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 PURPLE_TYPE_COMMAND,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 "icon-name", "icon",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 "last-used", last_used,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 "name", "name",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 "priority", 100,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 "source", "source",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 "summary", "summary",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 "use-count", 1337,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 g_assert_true(PURPLE_IS_COMMAND(command));
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 g_object_get(
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 G_OBJECT(command),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 "icon-name", &icon_name,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 "last-used", &last_used1,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 "name", &name,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 "priority", &priority,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 "source", &source,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 "summary", &summary,
42967
9da19bb7e207 Add a tags property to Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents: 42964
diff changeset
72 "tags", &tags,
42964
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 "use-count", &use_count,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 g_assert_cmpstr(icon_name, ==, "icon");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 g_clear_pointer(&icon_name, g_free);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 g_assert_true(birb_date_time_equal(last_used1, last_used));
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 birb_date_time_clear(&last_used1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 g_assert_cmpstr(name, ==, "name");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 g_clear_pointer(&name, g_free);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 g_assert_cmpint(priority, ==, 100);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 g_assert_cmpstr(source, ==, "source");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 g_clear_pointer(&source, g_free);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 g_assert_cmpstr(summary, ==, "summary");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 g_clear_pointer(&summary, g_free);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92
42967
9da19bb7e207 Add a tags property to Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents: 42964
diff changeset
93 g_assert_true(PURPLE_IS_TAGS(tags));
9da19bb7e207 Add a tags property to Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents: 42964
diff changeset
94 g_clear_object(&tags);
9da19bb7e207 Add a tags property to Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents: 42964
diff changeset
95
42964
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 g_assert_cmpuint(use_count, ==, 1337);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 birb_date_time_clear(&last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 /******************************************************************************
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 * Execute Tests
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 *****************************************************************************/
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 test_purple_command_executed_counter_cb(PurpleCommand *command,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 G_GNUC_UNUSED PurpleConversation *conversation,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 G_GNUC_UNUSED GStrv params,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 gpointer data)
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 guint *counter = data;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 g_assert_true(PURPLE_IS_COMMAND(command));
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 *counter = *counter + 1;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 test_purple_command_executed_params_cb(PurpleCommand *command,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 G_GNUC_UNUSED PurpleConversation *conversation,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 GStrv params,
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 gpointer data)
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 g_assert_true(PURPLE_IS_COMMAND(command));
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 g_assert_cmpstrv(params, data);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 test_purple_command_execute_null_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 purple_command_execute(command, NULL, NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 test_purple_command_execute_empty_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 const char * const expected[] = {NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 purple_command_execute(command, NULL, "");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 test_purple_command_execute_single_param(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 const char * const expected[] = {"param1", NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 purple_command_execute(command, NULL, "param1");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 test_purple_command_execute_multiple_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 const char * const expected[] = {"param1", "param2", "param3", NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 purple_command_execute(command, NULL, "param1 param2 param3");
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 test_purple_command_executev_null_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 purple_command_executev(command, NULL, NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 test_purple_command_executev_empty_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 const char * const expected[] = {NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 purple_command_executev(command, NULL, (GStrv)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 test_purple_command_executev_single_param(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 const char * const expected[] = {"param1", NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 purple_command_executev(command, NULL, (GStrv)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 static void
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 test_purple_command_executev_multiple_params(void) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 PurpleCommand *command = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 GDateTime *last_used = NULL;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 guint counter = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 guint use_count = 0;
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 const char * const expected[] = {"param1", "param2", "param3", NULL};
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 command = purple_command_new("command", "test", 0);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 G_CALLBACK(test_purple_command_executed_counter_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 &counter);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 g_signal_connect(command, "executed",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 G_CALLBACK(test_purple_command_executed_params_cb),
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 (gpointer)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 purple_command_executev(command, NULL, (GStrv)expected);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 g_assert_cmpuint(counter, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 last_used = purple_command_get_last_used(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 g_assert_nonnull(last_used);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 use_count = purple_command_get_use_count(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 g_assert_cmpuint(use_count, ==, 1);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 g_assert_finalize_object(command);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 }
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 /******************************************************************************
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 * Main
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 *****************************************************************************/
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 int
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 main(int argc, char *argv[]) {
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357 g_test_init(&argc, &argv, NULL);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 g_test_set_nonfatal_assertions();
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 g_test_add_func("/command/new", test_purple_command_new);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 g_test_add_func("/command/properties", test_purple_command_properties);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 g_test_add_func("/command/execute/null-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 test_purple_command_execute_null_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 g_test_add_func("/command/execute/empty-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 test_purple_command_execute_empty_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367 g_test_add_func("/command/execute/single-param",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 test_purple_command_execute_single_param);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 g_test_add_func("/command/execute/multiple-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 test_purple_command_execute_multiple_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 g_test_add_func("/command/executev/null-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373 test_purple_command_executev_null_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 g_test_add_func("/command/executev/empty-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375 test_purple_command_executev_empty_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 g_test_add_func("/command/executev/single-param",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 test_purple_command_executev_single_param);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 g_test_add_func("/command/executev/multiple-params",
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379 test_purple_command_executev_multiple_params);
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 return g_test_run();
f0edc907e018 Implement Purple.Command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 }

mercurial