1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
#include <glib.h>
#include "defines.h"
#include "server.h"
#include "citrix-server.h"
#include "rdp-server.h"
#include "uccs-server.h"
static gboolean
no_fatal_warnings (const gchar * log_domain, GLogLevelFlags level, const gchar * message, gpointer userdata)
{
if (level & (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG)) {
return FALSE;
}
return TRUE;
}
static void
state_signal (Server * server, ServerState newstate, gboolean * signaled)
{
*signaled = TRUE;
return;
}
static void
test_update_signal (void)
{
g_test_log_set_fatal_handler(no_fatal_warnings, NULL);
GKeyFile * keyfile = g_key_file_new();
const gchar * groupname = CONFIG_SERVER_PREFIX " Server Name";
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_NAME, "My Server");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_URI, "http://my.domain.com");
g_key_file_set_string(keyfile, groupname, CONFIG_UCCS_NETWORK, CONFIG_UCCS_NETWORK_NONE);
Server * server = NULL;
server = server_new_from_keyfile(keyfile, groupname);
g_assert(server != NULL);
g_assert(g_strcmp0(server->name, "My Server") == 0);
g_assert(g_strcmp0(server->uri, "http://my.domain.com") == 0);
UccsServer * userver = UCCS_SERVER(server);
g_assert(userver != NULL);
gboolean signaled = FALSE;
g_signal_connect(G_OBJECT(server), SERVER_SIGNAL_STATE_CHANGED, G_CALLBACK(state_signal), &signaled);
if (server->state == SERVER_STATE_ALLGOOD) {
signaled = FALSE;
uccs_server_set_exec(userver, "thisshouldnotexist");
g_assert(signaled);
g_assert(server->state == SERVER_STATE_UNAVAILABLE);
}
signaled = FALSE;
uccs_server_set_exec(userver, "ls");
g_assert(signaled);
g_assert(server->state == SERVER_STATE_ALLGOOD);
return;
}
static void
test_uccs_domains (void)
{
g_test_log_set_fatal_handler(no_fatal_warnings, NULL);
GKeyFile * keyfile = g_key_file_new();
const gchar * groupname = CONFIG_SERVER_PREFIX " Server Name";
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_NAME, "My Server");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_URI, "http://my.domain.com");
Server * server = NULL;
server = server_new_from_keyfile(keyfile, groupname);
g_assert(server != NULL);
g_assert(g_strcmp0(server->name, "My Server") == 0);
g_assert(g_strcmp0(server->uri, "http://my.domain.com") == 0);
GVariant * domains = server_cached_domains(server);
g_assert(domains != NULL);
g_assert(g_variant_is_of_type(domains, G_VARIANT_TYPE_ARRAY));
g_variant_ref_sink(domains);
g_variant_unref(domains);
g_object_unref(server);
g_key_file_unref(keyfile);
return;
}
static void
test_uccs_exec (void)
{
g_test_log_set_fatal_handler(no_fatal_warnings, NULL);
GKeyFile * keyfile = g_key_file_new();
const gchar * groupname = CONFIG_SERVER_PREFIX " Server Name";
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_NAME, "My Server");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_URI, "http://my.domain.com");
g_key_file_set_string(keyfile, groupname, CONFIG_UCCS_EXEC, "ls");
Server * server = NULL;
server = server_new_from_keyfile(keyfile, groupname);
g_assert(server != NULL);
g_assert(g_strcmp0(server->name, "My Server") == 0);
g_assert(g_strcmp0(server->uri, "http://my.domain.com") == 0);
g_assert(g_strcmp0(UCCS_SERVER(server)->exec, "/bin/ls") == 0);
g_object_unref(server);
g_key_file_unref(keyfile);
return;
}
typedef struct _type_data_t type_data_t;
struct _type_data_t {
GType type;
const gchar * name;
const gchar * config_type;
};
type_data_t type_data[3] = {
{0, "ica", CONFIG_SERVER_TYPE_ICA},
{0, "freerdp", CONFIG_SERVER_TYPE_RDP},
{0, "uccs", CONFIG_SERVER_TYPE_UCCS}
};
/*
static void
type_data_dump (type_data_t * data)
{
g_debug("Type data: %X", data);
g_debug(" type: %d", data->type);
g_debug(" name: %s", data->name);
g_debug(" c. type: %s", data->config_type);
}
*/
static gboolean
fatal_func (const gchar * log_domain, GLogLevelFlags level, const gchar * message, gpointer userdata)
{
return FALSE;
}
static void
test_object_variant (gconstpointer data)
{
g_test_log_set_fatal_handler(fatal_func, NULL);
type_data_t * typedata = (type_data_t *)data;
Server * server = g_object_new(typedata->type, NULL);
g_assert(server != NULL);
g_assert(IS_SERVER(server));
server->name = g_strdup("My Name");
server->uri = g_strdup("http://mysite.loves.testing.com");
GVariant * variant = server_get_variant(server);
g_assert(g_variant_n_children(variant) == 6);
GVariant * child = g_variant_get_child_value(variant, 0);
g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING));
g_assert(g_strcmp0(g_variant_get_string(child, NULL), typedata->name) == 0);
g_variant_unref(child);
child = g_variant_get_child_value(variant, 1);
g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING));
g_assert(g_strcmp0(g_variant_get_string(child, NULL), "My Name") == 0);
g_variant_unref(child);
child = g_variant_get_child_value(variant, 2);
g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING));
g_assert(g_strcmp0(g_variant_get_string(child, NULL), "http://mysite.loves.testing.com") == 0);
g_variant_unref(child);
g_variant_ref_sink(variant);
g_variant_unref(variant);
g_object_unref(G_OBJECT(server));
return;
}
static void
test_object_keyfile_basics (gconstpointer data)
{
g_test_log_set_fatal_handler(fatal_func, NULL);
type_data_t * typedata = (type_data_t *)data;
Server * server = NULL;
server = server_new_from_keyfile(NULL, NULL);
g_assert(server == NULL);
GKeyFile * keyfile = g_key_file_new();
server = server_new_from_keyfile(keyfile, NULL);
g_assert(server == NULL);
server = server_new_from_keyfile(keyfile, CONFIG_SERVER_PREFIX " Server Name");
g_assert(server == NULL);
gchar * groupname = g_strdup_printf("%s %s", CONFIG_SERVER_PREFIX, "Server Name");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_NAME, "My Server");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_URI, "http://my.domain.com");
g_key_file_set_string(keyfile, groupname, CONFIG_SERVER_TYPE, typedata->config_type);
g_key_file_set_string(keyfile, groupname, "dumbledorf", "Bad data, don't screw up!");
server = server_new_from_keyfile(keyfile, CONFIG_SERVER_PREFIX " Server Name");
g_assert(server != NULL);
g_assert(g_strcmp0(server->name, "My Server") == 0);
g_assert(g_strcmp0(server->uri, "http://my.domain.com") == 0);
g_assert(typedata->type == G_OBJECT_TYPE(server));
g_object_unref(server);
g_free(groupname);
g_key_file_unref(keyfile);
return;
}
static void
test_object_creation (gconstpointer data)
{
g_test_log_set_fatal_handler(no_fatal_warnings, NULL);
type_data_t * typedata = (type_data_t *)data;
Server * server = g_object_new(typedata->type, NULL);
g_assert(server != NULL);
g_assert(IS_SERVER(server));
g_object_unref(G_OBJECT(server));
return;
}
/* Build the test suite */
static void
test_objects_suite (void)
{
/* Here because they might require code to create the type so can't be
statically defined in the global */
type_data[0].type = CITRIX_SERVER_TYPE;
type_data[1].type = RDP_SERVER_TYPE;
type_data[2].type = UCCS_SERVER_TYPE;
g_test_add_data_func ("/server/object/creation/citrix", &type_data[0], test_object_creation);
g_test_add_data_func ("/server/object/creation/rdp", &type_data[1], test_object_creation);
g_test_add_data_func ("/server/object/creation/uccs", &type_data[2], test_object_creation);
g_test_add_data_func ("/server/object/keyfile/citrix", &(type_data[0]), test_object_keyfile_basics);
g_test_add_data_func ("/server/object/keyfile/rdp", &(type_data[1]), test_object_keyfile_basics);
g_test_add_data_func ("/server/object/keyfile/uccs", &(type_data[2]), test_object_keyfile_basics);
g_test_add_data_func ("/server/object/variant/citrix", &(type_data[0]), test_object_variant);
g_test_add_data_func ("/server/object/variant/rdp", &(type_data[1]), test_object_variant);
g_test_add_data_func ("/server/object/variant/uccs", &(type_data[2]), test_object_variant);
g_test_add_func ("/server/uccs/exec", test_uccs_exec);
g_test_add_func ("/server/uccs/domains", test_uccs_domains);
g_test_add_func ("/server/uccs/signal", test_update_signal);
return;
}
gint
main (gint argc, gchar * argv[])
{
g_type_init();
g_test_init(&argc, &argv, NULL);
/* Test suites */
test_objects_suite();
return g_test_run ();
}
|