libpurple/tests/test_ui.c

Fri, 11 Mar 2022 03:29:48 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Fri, 11 Mar 2022 03:29:48 -0600
changeset 41281
aa8fc0497d6d
parent 41129
4be9a7876d35
child 41396
2ef3d6eeffb3
permissions
-rw-r--r--

Add an echo user to the demo protocol

Testing Done:
Opened a conversation and typed a few message.

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

38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * pidgin
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 *
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 * Pidgin is the legal property of its developers, whose names are too numerous
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * source distribution.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 *
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * (at your option) any later version.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 *
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * GNU General Public License for more details.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 *
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 *
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 */
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 #include "purple.h"
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 #include <glib.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include <glib/gprintf.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 #include <signal.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 #include <string.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 #ifdef _WIN32
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 # include <conio.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 #else
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 # include <unistd.h>
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 #endif
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
38832
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
37 #include "test_ui.h"
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 /*** Conversation uiops ***/
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 static void
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 test_write_conv(PurpleConversation *conv, PurpleMessage *msg)
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 {
40541
9ceb8d25d4d9 PurpleMessage cleanups from hell
Gary Kramlich <grim@reaperworld.com>
parents: 38834
diff changeset
43 gchar *timestamp = purple_message_format_timestamp(msg, "(%H:%M:%S)");
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 printf("(%s) %s %s: %s\n",
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 purple_conversation_get_name(conv),
40541
9ceb8d25d4d9 PurpleMessage cleanups from hell
Gary Kramlich <grim@reaperworld.com>
parents: 38834
diff changeset
47 timestamp,
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 purple_message_get_author_alias(msg),
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 purple_message_get_contents(msg));
40541
9ceb8d25d4d9 PurpleMessage cleanups from hell
Gary Kramlich <grim@reaperworld.com>
parents: 38834
diff changeset
50
9ceb8d25d4d9 PurpleMessage cleanups from hell
Gary Kramlich <grim@reaperworld.com>
parents: 38834
diff changeset
51 g_free(timestamp);
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 }
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 static PurpleConversationUiOps test_conv_uiops = {
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 .write_conv = test_write_conv
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 };
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 static void
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 test_ui_init(void)
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 {
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 purple_conversations_set_ui_ops(&test_conv_uiops);
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 }
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 static PurpleCoreUiOps test_core_uiops = {
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 .ui_init = test_ui_init
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 };
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
41109
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
68 static gboolean
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
69 test_ui_init_history(GError **error) {
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
70 PurpleHistoryManager *manager = NULL;
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
71 PurpleHistoryAdapter *adapter = NULL;
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
72 const gchar *id = NULL;
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
73
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
74 manager = purple_history_manager_get_default();
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
75
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
76 adapter = purple_sqlite_history_adapter_new(":memory:");
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
77 id = purple_history_adapter_get_id(adapter);
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
78
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
79 if(!purple_history_manager_register(manager, adapter, error)) {
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
80 g_clear_object(&adapter);
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
81
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
82 return FALSE;
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
83 }
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
84
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
85 /* The manager adds a ref to the adapter on registration, so we can remove
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
86 * our reference.
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
87 */
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
88 g_clear_object(&adapter);
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
89
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
90 return purple_history_manager_set_active(manager, id, error);
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
91 }
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
92
38832
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
93 void
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
94 test_ui_purple_init(void) {
41109
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
95 GError *error = NULL;
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
96
38832
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
97 #ifndef _WIN32
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
98 /* libpurple's built-in DNS resolution forks processes to perform
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
99 * blocking lookups without blocking the main process. It does not
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
100 * handle SIGCHLD itself, so if the UI does not you quickly get an army
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
101 * of zombie subprocesses marching around.
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
102 */
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
103 signal(SIGCHLD, SIG_IGN);
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
104 #endif
7ad7854d8e60 Create a very basic ui for testing
Gary Kramlich <grim@reaperworld.com>
parents: 38831
diff changeset
105
38834
e4144efa975e Clean up a bunch of the cruft I accidentally created
Gary Kramlich <grim@reaperworld.com>
parents: 38832
diff changeset
106 /* set the magic PURPLE_PLUGINS_SKIP environment variable */
e4144efa975e Clean up a bunch of the cruft I accidentally created
Gary Kramlich <grim@reaperworld.com>
parents: 38832
diff changeset
107 g_setenv("PURPLE_PLUGINS_SKIP", "1", TRUE);
e4144efa975e Clean up a bunch of the cruft I accidentally created
Gary Kramlich <grim@reaperworld.com>
parents: 38832
diff changeset
108
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 /* Set the core-uiops, which is used to
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 * - initialize the ui specific preferences.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 * - initialize the debug ui.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 * - initialize the ui components for all the modules.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 * - uninitialize the ui components for all the modules when the core terminates.
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 */
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 purple_core_set_ui_ops(&test_core_uiops);
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 /* Now that all the essential stuff has been set, let's try to init the core. It's
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 * necessary to provide a non-NULL name for the current ui to the core. This name
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 if (!purple_core_init("test-ui")) {
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 /* Initializing the core failed. Terminate. */
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 fprintf(stderr,
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 "libpurple initialization failed. Dumping core.\n"
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 "Please report this!\n");
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 abort();
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 }
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
41109
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
128 if(!test_ui_init_history(&error)) {
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
129 g_critical("failed to initialize the history api: %s",
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
130 error ? error->message : "unknown");
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
131 g_clear_error(&error);
755e1554051c Make user interfaces setup the default history adapter.
Gary Kramlich <grim@reaperworld.com>
parents: 40669
diff changeset
132 }
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 /* Load the preferences. */
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 purple_prefs_load();
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
41129
4be9a7876d35 Fix the unit tests that were broke by the g_log transition
Gary Kramlich <grim@reaperworld.com>
parents: 41127
diff changeset
137 purple_prefs_add_none("/purple");
4be9a7876d35 Fix the unit tests that were broke by the g_log transition
Gary Kramlich <grim@reaperworld.com>
parents: 41127
diff changeset
138 purple_prefs_add_none("/purple/test_ui");
4be9a7876d35 Fix the unit tests that were broke by the g_log transition
Gary Kramlich <grim@reaperworld.com>
parents: 41127
diff changeset
139 purple_prefs_add_none("/purple/test_ui/plugins");
4be9a7876d35 Fix the unit tests that were broke by the g_log transition
Gary Kramlich <grim@reaperworld.com>
parents: 41127
diff changeset
140 purple_prefs_add_path_list("/purple/test_ui/plugins/saved", NULL);
4be9a7876d35 Fix the unit tests that were broke by the g_log transition
Gary Kramlich <grim@reaperworld.com>
parents: 41127
diff changeset
141
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 /* Load the desired plugins. The client should save the list of loaded plugins in
40669
48dfed6f4f1f Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40541
diff changeset
143 * the preferences using purple_plugins_save_loaded() */
48dfed6f4f1f Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40541
diff changeset
144 purple_plugins_load_saved("/purple/test_ui/plugins/saved");
38831
d260f3b61831 The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 }

mercurial