Mon, 18 Sep 2017 22:29:40 -0500
The start of a ui for unit testing
|
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 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | #include "defines.h" |
|
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 | { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | time_t mtime = purple_message_get_time(msg); |
|
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), |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)), |
|
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)); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | } |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | static PurpleConversationUiOps test_conv_uiops = { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | .write_conv = test_write_conv |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | }; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | static void |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | test_ui_init(void) |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | 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
|
60 | } |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | static PurpleCoreUiOps test_core_uiops = { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | .ui_init = test_ui_init |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | }; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | static void |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | init_libpurple(void) { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | /* Set a custom user directory (optional) */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | purple_util_set_user_dir(TEST_DATA_DIR); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | /* We do not want any debugging for now to keep the noise to a minimum. */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | purple_debug_set_enabled(FALSE); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | /* 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
|
75 | * - initialize the ui specific preferences. |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | * - initialize the debug ui. |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | * - 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
|
78 | * - 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
|
79 | */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | 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
|
81 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | /* 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
|
83 | * 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
|
84 | * 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
|
85 | if (!purple_core_init("test-ui")) { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | /* Initializing the core failed. Terminate. */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | fprintf(stderr, |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | "libpurple initialization failed. Dumping core.\n" |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | "Please report this!\n"); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | abort(); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | } |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | /* Set path to search for plugins. The core (libpurple) takes care of loading the |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | * core-plugins, which includes the in-tree protocols. So it is not essential to add |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | * any path here, but it might be desired, especially for ui-specific plugins. */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | purple_plugins_add_search_path(TEST_DATA_DIR); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | purple_plugins_refresh(); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | /* Load the preferences. */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | purple_prefs_load(); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | /* Load the desired plugins. The client should save the list of loaded plugins in |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */ |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | purple_plugins_load_saved(TEST_DATA_DIR); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | } |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | gint |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | main(int argc, char *argv[]) { |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | GList *list, *iter; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 | int i, num; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | GList *names = NULL; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | const char *protocol = NULL; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | char name[128]; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | char *password; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | GMainLoop *loop = g_main_loop_new(NULL, FALSE); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | PurpleAccount *account; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | PurpleSavedStatus *status; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | char *res; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | #ifndef _WIN32 |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | /* libpurple's built-in DNS resolution forks processes to perform |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | * blocking lookups without blocking the main process. It does not |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 | * handle SIGCHLD itself, so if the UI does not you quickly get an army |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 | * of zombie subprocesses marching around. |
|
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 | signal(SIGCHLD, SIG_IGN); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | #endif |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | init_libpurple(); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 | printf("libpurple initialized.\n"); |
|
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 | g_main_loop_run(loop); |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 | return 0; |
|
d260f3b61831
The start of a ui for unit testing
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 | } |