Skip to content

Latest commit

 

History

History
839 lines (797 loc) · 23.8 KB

test_retrieve.c

File metadata and controls

839 lines (797 loc) · 23.8 KB
 
Feb 17, 2014
Feb 17, 2014
1
/*
Jun 19, 2017
Jun 19, 2017
2
* Copyright (C) 2013-2017 Jolla Ltd.
Jan 16, 2015
Jan 16, 2015
3
* Contact: Slava Monich <slava.monich@jolla.com>
Feb 17, 2014
Feb 17, 2014
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
Mar 13, 2016
Mar 13, 2016
18
#include "test_transfer_list.h"
Mar 11, 2016
Mar 11, 2016
19
#include "test_util.h"
Feb 17, 2014
Feb 17, 2014
20
21
#include "mms_codec.h"
Feb 17, 2014
Feb 17, 2014
22
#include "mms_file_util.h"
Feb 17, 2014
Feb 17, 2014
23
24
#include "mms_lib_log.h"
#include "mms_lib_util.h"
May 12, 2014
May 12, 2014
25
#include "mms_settings.h"
Feb 17, 2014
Feb 17, 2014
26
27
#include "mms_dispatcher.h"
Sep 29, 2016
Sep 29, 2016
28
#include <gutil_macros.h>
Jul 13, 2016
Jul 13, 2016
29
#include <gutil_log.h>
Feb 17, 2014
Feb 17, 2014
30
31
32
33
34
35
36
37
#include <libsoup/soup-status.h>
#define RET_OK (0)
#define RET_ERR (1)
#define RET_TIMEOUT (2)
#define MMS_MESSAGE_TYPE_NONE (0)
Jun 19, 2017
Jun 19, 2017
38
39
#define DATA_DIR "data/"
#define LOCALHOST "127.0.0.1"
Feb 17, 2014
Feb 17, 2014
40
Jan 29, 2015
Jan 29, 2015
41
42
#define TEST_TIMEOUT (10) /* seconds */
Mar 14, 2014
Mar 14, 2014
43
44
45
46
47
48
typedef struct test_part_desc {
const char* content_type;
const char* content_id;
const char* file_name;
} TestPartDesc;
Feb 17, 2014
Feb 17, 2014
49
50
51
52
53
54
55
typedef struct test_desc {
const char* name;
const char* dir;
const char* ni_file;
const char* rc_file;
unsigned int status;
const char* content_type;
Feb 17, 2014
Feb 17, 2014
56
const char* attic_file;
Feb 17, 2014
Feb 17, 2014
57
58
MMS_RECEIVE_STATE expected_state;
enum mms_message_type reply_msg;
Mar 14, 2014
Mar 14, 2014
59
60
const TestPartDesc* parts;
unsigned int nparts;
Jun 19, 2017
Jun 19, 2017
61
const char* proxy;
Feb 17, 2014
Feb 17, 2014
62
63
64
int flags;
#define TEST_PUSH_HANDLING_FAILURE_OK (0x01)
May 12, 2014
May 12, 2014
65
66
#define TEST_DEFER_RECEIVE (0x02)
#define TEST_REJECT_RECEIVE (0x04)
Jul 5, 2014
Jul 5, 2014
67
68
#define TEST_CONNECTION_FAILURE (0x08)
#define TEST_OFFLINE (0x10)
Sep 11, 2014
Sep 11, 2014
69
#define TEST_CANCEL_RECEIVED (0x20)
Feb 17, 2014
Feb 17, 2014
70
71
72
73
74
} TestDesc;
typedef struct test {
const TestDesc* desc;
Feb 17, 2014
Feb 17, 2014
75
const MMSConfig* config;
Feb 17, 2014
Feb 17, 2014
76
77
78
79
80
81
82
83
MMSDispatcherDelegate delegate;
MMSConnMan* cm;
MMSHandler* handler;
MMSDispatcher* disp;
GMappedFile* notification_ind;
GMappedFile* retrieve_conf;
GMainLoop* loop;
guint timeout_id;
Mar 11, 2016
Mar 11, 2016
84
gulong msgreceived_id;
Feb 17, 2014
Feb 17, 2014
85
86
87
88
TestHttp* http;
int ret;
} Test;
Mar 27, 2014
Mar 27, 2014
89
static const TestPartDesc retrieve_success1_parts [] = {
Mar 14, 2014
Mar 14, 2014
90
91
92
93
94
95
96
97
98
99
100
101
102
{ "application/smil;charset=utf-8", "<0>", "0.smil" },
{ "text/plain;charset=utf-8", "<text_0011.txt>", "text_0011.txt" },
{ "image/jpeg", "<131200181.jpg>", "131200181.jpg" },
{ "text/plain;charset=utf-8", "<text_0021.txt>", "text_0021.txt" },
{ "image/jpeg", "<140100041.jpg>", "140100041.jpg" }
};
static const TestPartDesc retrieve_success2_parts [] = {
{ "image/jpeg", "<2014_03_.jpg>", "2014_03_.jpg" },
{ "text/plain;charset=utf-8", "<Test_mms.txt>", "Test_mms.txt" },
{ "application/smil;charset=utf-8", "<332047400>", "332047400" },
};
Mar 27, 2014
Mar 27, 2014
103
104
105
106
107
108
static const TestPartDesc retrieve_success3_parts [] = {
{ "application/smil;charset=utf-8", "<0>", "0" },
{ "image/jpeg", "<1>", "1.jpg" },
{ "text/plain;charset=utf-8", "<2>", "text_001.txt" }
};
Jan 16, 2015
Jan 16, 2015
109
110
111
112
113
114
static const TestPartDesc retrieve_transfer_encoding_parts [] = {
{ "application/smil;charset=utf-8", "<smil>", "smil" },
{ "image/jpeg", "<1.jpg>", "1.jpg" },
{ "text/plain;charset=utf-8", "<2.txt>", "2.txt" }
};
Apr 4, 2014
Apr 4, 2014
115
116
117
118
119
static const TestPartDesc retrieve_invalid_subject [] = {
{ "application/smil;charset=us-ascii", "<start>", "smil.smi" },
{ "image/jpeg", "<1>", "1" }
};
Mar 14, 2014
Mar 14, 2014
120
121
122
#define TEST_PARTS(parts) parts, G_N_ELEMENTS(parts)
#define TEST_PARTS_NONE NULL, 0
Feb 17, 2014
Feb 17, 2014
123
124
static const TestDesc retrieve_tests[] = {
{
Mar 27, 2014
Mar 27, 2014
125
"Success1",
Feb 17, 2014
Feb 17, 2014
126
127
128
129
130
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
Feb 17, 2014
Feb 17, 2014
131
NULL,
Feb 17, 2014
Feb 17, 2014
132
133
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
Mar 27, 2014
Mar 27, 2014
134
TEST_PARTS(retrieve_success1_parts),
Jun 19, 2017
Jun 19, 2017
135
"0127.000.000.001",
Feb 17, 2014
Feb 17, 2014
136
0
Mar 27, 2014
Mar 27, 2014
137
138
139
},{
"Success2", /* Generated by Nokia C6 (Symbian "Belle") */
NULL,
Feb 17, 2014
Feb 17, 2014
140
141
142
143
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
Feb 17, 2014
Feb 17, 2014
144
NULL,
Feb 17, 2014
Feb 17, 2014
145
146
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
Mar 27, 2014
Mar 27, 2014
147
TEST_PARTS(retrieve_success2_parts),
Jun 19, 2017
Jun 19, 2017
148
"127.0.0.001",
Mar 27, 2014
Mar 27, 2014
149
0
Feb 17, 2014
Feb 17, 2014
150
},{
Mar 27, 2014
Mar 27, 2014
151
"Success3", /* Generated by Nokia N9 */
Mar 14, 2014
Mar 14, 2014
152
153
154
155
156
157
158
159
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
Mar 27, 2014
Mar 27, 2014
160
TEST_PARTS(retrieve_success3_parts),
Jun 19, 2017
Jun 19, 2017
161
LOCALHOST,
Mar 14, 2014
Mar 14, 2014
162
0
Jan 16, 2015
Jan 16, 2015
163
164
165
166
167
168
169
170
171
172
173
},{
"QuotedPrintable", /* quoted-printable transfer encoding for text */
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_transfer_encoding_parts),
Jun 19, 2017
Jun 19, 2017
174
LOCALHOST,
Jan 16, 2015
Jan 16, 2015
175
176
177
178
179
180
181
182
183
184
185
186
0
},{
"Base64", /* Base64 transfer encoding for text */
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_transfer_encoding_parts),
Jun 19, 2017
Jun 19, 2017
187
LOCALHOST,
Jan 16, 2015
Jan 16, 2015
188
0
Apr 4, 2014
Apr 4, 2014
189
190
191
192
193
194
195
196
197
198
199
},{
"InvalidSubject",
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_invalid_subject),
Jun 19, 2017
Jun 19, 2017
200
LOCALHOST,
Apr 4, 2014
Apr 4, 2014
201
0
Mar 27, 2014
Mar 27, 2014
202
203
204
205
206
207
208
209
210
211
212
},{
"DeferSuccess",
"Success1",
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success1_parts),
Jun 19, 2017
Jun 19, 2017
213
LOCALHOST,
Mar 27, 2014
Mar 27, 2014
214
TEST_DEFER_RECEIVE
Sep 11, 2014
Sep 11, 2014
215
216
217
218
219
220
221
222
223
224
225
},{
"CancelReceive",
"Success1",
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success1_parts),
Jun 19, 2017
Jun 19, 2017
226
LOCALHOST,
Sep 11, 2014
Sep 11, 2014
227
TEST_DEFER_RECEIVE | TEST_CANCEL_RECEIVED
Mar 14, 2014
Mar 14, 2014
228
},{
May 12, 2014
May 12, 2014
229
"Expired1",
Feb 17, 2014
Feb 17, 2014
230
231
232
233
234
NULL,
"m-notification.ind",
NULL,
SOUP_STATUS_NOT_FOUND,
NULL,
Feb 17, 2014
Feb 17, 2014
235
NULL,
Feb 17, 2014
Feb 17, 2014
236
237
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
238
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
239
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
240
0
May 12, 2014
May 12, 2014
241
242
243
244
245
246
247
248
249
250
251
},{
"Expired2",
NULL,
"m-notification.ind",
NULL,
SOUP_STATUS_OK,
NULL,
NULL,
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NOTIFYRESP_IND,
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
252
LOCALHOST,
May 12, 2014
May 12, 2014
253
TEST_REJECT_RECEIVE
Feb 17, 2014
Feb 17, 2014
254
255
256
257
258
259
260
},{
"SoonExpired",
NULL,
"m-notification.ind",
NULL,
SOUP_STATUS_TRY_AGAIN,
NULL,
Feb 17, 2014
Feb 17, 2014
261
NULL,
Feb 17, 2014
Feb 17, 2014
262
263
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
264
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
265
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
266
0
Jul 5, 2014
Jul 5, 2014
267
268
269
270
271
272
273
274
275
276
277
},{
"Offline",
NULL,
"m-notification.ind",
NULL,
0,
NULL,
NULL,
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
278
LOCALHOST,
Jul 5, 2014
Jul 5, 2014
279
280
281
282
283
284
285
286
287
288
289
290
TEST_OFFLINE
},{
"Timeout",
NULL,
"m-notification.ind",
NULL,
0,
NULL,
NULL,
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
291
LOCALHOST,
Jul 5, 2014
Jul 5, 2014
292
TEST_CONNECTION_FAILURE
Feb 17, 2014
Feb 17, 2014
293
294
295
296
297
298
299
},{
"NotAllowed",
NULL,
"m-notification.ind",
"not-allowed.html",
SOUP_STATUS_BAD_REQUEST,
"text/html",
Feb 17, 2014
Feb 17, 2014
300
NULL,
Feb 17, 2014
Feb 17, 2014
301
302
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
303
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
304
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
305
306
307
308
309
310
311
312
0
},{
"NotFound",
NULL,
"m-notification.ind",
"not-found.html",
SOUP_STATUS_NOT_FOUND,
"text/html",
Feb 17, 2014
Feb 17, 2014
313
NULL,
Feb 17, 2014
Feb 17, 2014
314
315
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
316
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
317
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
318
0
May 8, 2014
May 8, 2014
319
320
321
322
323
324
325
326
327
328
329
},{
"MessageNotFound",
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
330
LOCALHOST,
May 8, 2014
May 8, 2014
331
0
Feb 17, 2014
Feb 17, 2014
332
333
334
335
336
337
338
},{
"GarbageRetrieve",
NULL,
"m-notification.ind",
"garbage",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
Feb 17, 2014
Feb 17, 2014
339
NULL,
Feb 17, 2014
Feb 17, 2014
340
341
MMS_RECEIVE_STATE_DECODING_ERROR,
MMS_MESSAGE_TYPE_NOTIFYRESP_IND,
Mar 14, 2014
Mar 14, 2014
342
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
343
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
344
345
346
347
348
349
350
351
0
},{
"GarbagePush",
NULL,
"garbage",
NULL,
0,
NULL,
Feb 17, 2014
Feb 17, 2014
352
"000/push.pdu",
Feb 17, 2014
Feb 17, 2014
353
354
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
355
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
356
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
357
358
359
360
361
362
363
364
TEST_PUSH_HANDLING_FAILURE_OK
},{
"UnsupportedPush",
NULL,
"unsupported",
NULL,
0,
NULL,
Feb 17, 2014
Feb 17, 2014
365
"000/push.pdu",
Feb 17, 2014
Feb 17, 2014
366
367
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NONE,
Mar 14, 2014
Mar 14, 2014
368
TEST_PARTS_NONE,
Jun 19, 2017
Jun 19, 2017
369
LOCALHOST,
Feb 17, 2014
Feb 17, 2014
370
371
372
373
TEST_PUSH_HANDLING_FAILURE_OK
}
};
Jan 16, 2015
Jan 16, 2015
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
static
gboolean
test_files_equal(
const char* path1,
const char* path2)
{
gboolean equal = FALSE;
if (path1 && path2) {
GError* error = NULL;
GMappedFile* f1 = g_mapped_file_new(path1, FALSE, &error);
if (f1) {
GMappedFile* f2 = g_mapped_file_new(path2, FALSE, &error);
if (f2) {
const gsize size = g_mapped_file_get_length(f1);
if (g_mapped_file_get_length(f2) == size) {
const void* data1 = g_mapped_file_get_contents(f1);
const void* data2 = g_mapped_file_get_contents(f2);
equal = !memcmp(data1, data2, size);
}
g_mapped_file_unref(f2);
}
g_mapped_file_unref(f1);
}
}
if (!equal) {
Jul 13, 2016
Jul 13, 2016
399
GERR("%s is not identical to %s", path1, path2);
Jan 16, 2015
Jan 16, 2015
400
401
402
403
}
return equal;
}
Mar 14, 2014
Mar 14, 2014
404
405
406
407
408
409
410
411
412
413
static
int
test_validate_parts(
Test* test)
{
const TestDesc* desc = test->desc;
MMSMessage* msg = mms_handler_test_get_received_message(test->handler,NULL);
if (!desc->nparts && (!msg || !g_slist_length(msg->parts))) {
return RET_OK;
} else {
Jan 16, 2015
Jan 16, 2015
414
const char* dir = desc->dir ? desc->dir : desc->name;
Mar 14, 2014
Mar 14, 2014
415
416
417
418
419
420
const unsigned int nparts = g_slist_length(msg->parts);
if (desc->nparts == nparts) {
const TestPartDesc* expect = test->desc->parts;
GSList* list = msg->parts;
while (list) {
const MMSMessagePart* part = list->data;
Jan 16, 2015
Jan 16, 2015
421
422
423
char* sample = g_strconcat(DATA_DIR, dir, "/parts/",
expect->file_name, NULL);
const gboolean match = test_files_equal(part->file, sample);
Mar 14, 2014
Mar 14, 2014
424
const char* fname;
Jan 16, 2015
Jan 16, 2015
425
Mar 14, 2014
Mar 14, 2014
426
427
428
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
fname = g_basename(part->file);
G_GNUC_END_IGNORE_DEPRECATIONS;
Jan 16, 2015
Jan 16, 2015
429
430
431
432
433
434
435
g_free(sample);
if (!match) {
/* Message message is printed by test_files_equal */
return RET_ERR;
}
Mar 14, 2014
Mar 14, 2014
436
if (strcmp(expect->content_type, part->content_type)) {
Jul 13, 2016
Jul 13, 2016
437
GERR("Content type mismatch: expected %s, got %s",
Mar 14, 2014
Mar 14, 2014
438
439
440
441
expect->content_type, part->content_type);
return RET_ERR;
}
if (strcmp(expect->file_name, fname)) {
Jul 13, 2016
Jul 13, 2016
442
GERR("File name mismatch: expected %s, got %s",
Mar 14, 2014
Mar 14, 2014
443
444
445
446
expect->file_name, fname);
return RET_ERR;
}
if (!part->content_id) {
Jul 13, 2016
Jul 13, 2016
447
GERR("Missing content id");
Mar 14, 2014
Mar 14, 2014
448
449
450
return RET_ERR;
}
if (strcmp(expect->content_id, part->content_id)) {
Jul 13, 2016
Jul 13, 2016
451
GERR("Content-ID mismatch: expected %s, got %s",
Mar 14, 2014
Mar 14, 2014
452
453
454
expect->content_id, part->content_id);
return RET_ERR;
}
Jan 16, 2015
Jan 16, 2015
455
list = list->next;
Mar 14, 2014
Mar 14, 2014
456
457
458
459
expect++;
}
return RET_OK;
}
Jul 13, 2016
Jul 13, 2016
460
GERR("%u parts expected, got %u", desc->nparts, nparts);
Mar 14, 2014
Mar 14, 2014
461
462
463
464
return RET_ERR;
}
}
Feb 17, 2014
Feb 17, 2014
465
466
467
468
469
static
void
test_finish(
Test* test)
{
Feb 17, 2014
Feb 17, 2014
470
471
const TestDesc* desc = test->desc;
const char* name = desc->name;
Feb 17, 2014
Feb 17, 2014
472
473
474
if (test->ret == RET_OK) {
MMS_RECEIVE_STATE state;
state = mms_handler_test_receive_state(test->handler, NULL);
Feb 17, 2014
Feb 17, 2014
475
if (state != desc->expected_state) {
Feb 17, 2014
Feb 17, 2014
476
test->ret = RET_ERR;
Jul 13, 2016
Jul 13, 2016
477
GERR("%s state %d, expected %d", name, state,
Feb 17, 2014
Feb 17, 2014
478
desc->expected_state);
Feb 17, 2014
Feb 17, 2014
479
480
481
482
483
484
} else {
const void* resp_data = NULL;
gsize resp_len = 0;
GBytes* reply = test_http_get_post_data(test->http);
if (reply) resp_data = g_bytes_get_data(reply, &resp_len);
if (resp_len > 0) {
Feb 17, 2014
Feb 17, 2014
485
if (desc->reply_msg) {
Feb 17, 2014
Feb 17, 2014
486
487
MMSPdu* pdu = g_new0(MMSPdu, 1);
if (mms_message_decode(resp_data, resp_len, pdu)) {
Mar 14, 2014
Mar 14, 2014
488
489
490
if (pdu->type == desc->reply_msg) {
test->ret = test_validate_parts(test);
} else {
Feb 17, 2014
Feb 17, 2014
491
test->ret = RET_ERR;
Jul 13, 2016
Jul 13, 2016
492
GERR("%s reply %u, expected %u", name,
Feb 17, 2014
Feb 17, 2014
493
pdu->type, desc->reply_msg);
Feb 17, 2014
Feb 17, 2014
494
495
496
}
} else {
test->ret = RET_ERR;
Jul 13, 2016
Jul 13, 2016
497
GERR("%s can't decode reply message", name);
Feb 17, 2014
Feb 17, 2014
498
499
500
501
}
mms_message_free(pdu);
} else {
test->ret = RET_ERR;
Jul 13, 2016
Jul 13, 2016
502
GERR("%s expects no reply", name);
Feb 17, 2014
Feb 17, 2014
503
}
Feb 17, 2014
Feb 17, 2014
504
} else if (desc->reply_msg) {
Feb 17, 2014
Feb 17, 2014
505
test->ret = RET_ERR;
Jul 13, 2016
Jul 13, 2016
506
GERR("%s expects reply", name);
Feb 17, 2014
Feb 17, 2014
507
508
509
}
}
}
Feb 17, 2014
Feb 17, 2014
510
511
512
513
514
if (test->ret == RET_OK && desc->attic_file) {
const char* dir = desc->dir ? desc->dir : desc->name;
char* f1 = g_strconcat(DATA_DIR, dir, "/", desc->ni_file, NULL);
char* f2 = g_strconcat(test->config->root_dir, "/" MMS_ATTIC_DIR "/",
desc->attic_file, NULL);
Jan 16, 2015
Jan 16, 2015
515
if (test_files_equal(f1, f2)) {
Feb 17, 2014
Feb 17, 2014
516
517
char* dir = g_path_get_dirname(f2);
remove(f2);
Feb 17, 2014
Feb 17, 2014
518
rmdir(dir);
Feb 17, 2014
Feb 17, 2014
519
520
521
522
523
524
525
g_free(dir);
} else {
test->ret = RET_ERR;
}
g_free(f1);
g_free(f2);
}
Jul 13, 2016
Jul 13, 2016
526
GINFO("%s: %s", (test->ret == RET_OK) ? "OK" : "FAILED", name);
Feb 17, 2014
Feb 17, 2014
527
mms_handler_test_reset(test->handler);
Mar 11, 2016
Mar 11, 2016
528
g_signal_handler_disconnect(test->handler, test->msgreceived_id);
Feb 17, 2014
Feb 17, 2014
529
530
531
532
533
534
535
536
537
g_main_loop_quit(test->loop);
}
static
void
test_done(
MMSDispatcherDelegate* delegate,
MMSDispatcher* dispatcher)
{
Sep 29, 2016
Sep 29, 2016
538
Test* test = G_CAST(delegate,Test,delegate);
Feb 17, 2014
Feb 17, 2014
539
540
541
542
543
544
545
546
547
548
549
550
551
if (!mms_handler_test_receive_pending(test->handler, NULL)) {
test_finish(test);
}
}
static
gboolean
test_timeout(
gpointer data)
{
Test* test = data;
test->timeout_id = 0;
test->ret = RET_TIMEOUT;
Jul 13, 2016
Jul 13, 2016
552
GINFO("%s TIMEOUT", test->desc->name);
Feb 17, 2014
Feb 17, 2014
553
554
555
556
557
558
if (test->http) test_http_close(test->http);
mms_connman_test_close_connection(test->cm);
mms_dispatcher_cancel(test->disp, NULL);
return FALSE;
}
Sep 11, 2014
Sep 11, 2014
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
static
gboolean
test_notify(
MMSHandler* handler,
const char* imsi,
const char* from,
const char* subject,
time_t expiry,
GBytes* data,
void* param)
{
Test* test = param;
return !(test->desc->flags & TEST_REJECT_RECEIVE);
}
typedef struct test_cancel_msg {
MMSDispatcher* disp;
MMSMessage* msg;
} TestCancelMsg;
static
gboolean
test_cancel_msg_proc(
void* param)
{
TestCancelMsg* cancel = param;
Jul 13, 2016
Jul 13, 2016
585
GVERBOSE("Cancelling message %s", cancel->msg->id);
Sep 11, 2014
Sep 11, 2014
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
mms_dispatcher_cancel(cancel->disp, cancel->msg->id);
mms_dispatcher_unref(cancel->disp);
mms_message_unref(cancel->msg);
g_free(cancel);
return FALSE;
}
static
void
test_msgreceived(
MMSHandler* handler,
MMSMessage* msg,
void* param)
{
Test* test = param;
if (test->desc->flags & TEST_CANCEL_RECEIVED) {
TestCancelMsg* cancel = g_new(TestCancelMsg,1);
cancel->disp = mms_dispatcher_ref(test->disp);
cancel->msg = mms_message_ref(msg);
g_idle_add_full(G_PRIORITY_HIGH, test_cancel_msg_proc, cancel, NULL);
}
}
Feb 17, 2014
Feb 17, 2014
609
610
611
612
613
static
gboolean
test_init(
Test* test,
const MMSConfig* config,
Jan 29, 2015
Jan 29, 2015
614
615
const TestDesc* desc,
gboolean debug)
Feb 17, 2014
Feb 17, 2014
616
617
618
619
620
621
622
{
gboolean ok = FALSE;
GError* error = NULL;
const char* dir = desc->dir ? desc->dir : desc->name;
char* ni = g_strconcat(DATA_DIR, dir, "/", desc->ni_file, NULL);
char* rc = desc->rc_file ? g_strconcat(DATA_DIR, dir, "/",
desc->rc_file, NULL) : NULL;
Jul 13, 2016
Jul 13, 2016
623
GDEBUG(">>>>>>>>>> %s <<<<<<<<<<", desc->name);
Feb 17, 2014
Feb 17, 2014
624
memset(test, 0, sizeof(*test));
Feb 17, 2014
Feb 17, 2014
625
test->config = config;
Feb 17, 2014
Feb 17, 2014
626
627
628
629
test->notification_ind = g_mapped_file_new(ni, FALSE, &error);
if (test->notification_ind) {
if (rc) test->retrieve_conf = g_mapped_file_new(rc, FALSE, &error);
if (test->retrieve_conf || !rc) {
May 12, 2014
May 12, 2014
630
MMSSettings* settings = mms_settings_default_new(config);
Mar 13, 2016
Mar 13, 2016
631
MMSTransferList* transfers = mms_transfer_list_test_new();
Feb 17, 2014
Feb 17, 2014
632
633
634
635
g_mapped_file_ref(test->notification_ind);
test->desc = desc;
test->cm = mms_connman_test_new();
test->handler = mms_handler_test_new();
Mar 13, 2016
Mar 13, 2016
636
637
test->disp = mms_dispatcher_new(settings, test->cm, test->handler,
transfers);
Feb 17, 2014
Feb 17, 2014
638
test->loop = g_main_loop_new(NULL, FALSE);
Jan 29, 2015
Jan 29, 2015
639
640
641
642
if (!debug) {
test->timeout_id = g_timeout_add_seconds(TEST_TIMEOUT,
test_timeout, test);
}
Feb 17, 2014
Feb 17, 2014
643
644
test->delegate.fn_done = test_done;
mms_dispatcher_set_delegate(test->disp, &test->delegate);
Jul 5, 2014
Jul 5, 2014
645
646
647
if (!(desc->flags & TEST_CONNECTION_FAILURE)) {
test->http = test_http_new(test->retrieve_conf,
test->desc->content_type, test->desc->status);
Jun 19, 2017
Jun 19, 2017
648
649
mms_connman_test_set_proxy(test->cm, desc->proxy,
test_http_get_port(test->http));
Jul 5, 2014
Jul 5, 2014
650
651
652
653
}
if (desc->flags & TEST_OFFLINE) {
mms_connman_test_set_offline(test->cm, TRUE);
}
Feb 17, 2014
Feb 17, 2014
654
655
656
if (desc->flags & TEST_DEFER_RECEIVE) {
mms_handler_test_defer_receive(test->handler, test->disp);
}
Sep 11, 2014
Sep 11, 2014
657
mms_handler_test_set_prenotify_fn(test->handler, test_notify, test);
Mar 11, 2016
Mar 11, 2016
658
659
660
test->msgreceived_id =
mms_handler_test_add_msgreceived_fn(test->handler,
test_msgreceived, test);
Mar 13, 2016
Mar 13, 2016
661
mms_transfer_list_unref(transfers);
May 12, 2014
May 12, 2014
662
mms_settings_unref(settings);
Feb 17, 2014
Feb 17, 2014
663
664
665
test->ret = RET_ERR;
ok = TRUE;
} else {
Jul 13, 2016
Jul 13, 2016
666
GERR("%s", GERRMSG(error));
Feb 17, 2014
Feb 17, 2014
667
668
669
670
g_error_free(error);
}
g_mapped_file_unref(test->notification_ind);
} else {
Jul 13, 2016
Jul 13, 2016
671
GERR("%s", GERRMSG(error));
Feb 17, 2014
Feb 17, 2014
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
g_error_free(error);
}
g_free(ni);
g_free(rc);
return ok;
}
static
void
test_finalize(
Test* test)
{
if (test->timeout_id) {
g_source_remove(test->timeout_id);
test->timeout_id = 0;
}
if (test->http) {
test_http_close(test->http);
test_http_unref(test->http);
}
mms_connman_test_close_connection(test->cm);
mms_connman_unref(test->cm);
mms_handler_unref(test->handler);
mms_dispatcher_unref(test->disp);
g_main_loop_unref(test->loop);
g_mapped_file_unref(test->notification_ind);
if (test->retrieve_conf) g_mapped_file_unref(test->retrieve_conf);
}
static
int
test_retrieve_once(
const MMSConfig* config,
Jan 29, 2015
Jan 29, 2015
705
706
const TestDesc* desc,
gboolean debug)
Feb 17, 2014
Feb 17, 2014
707
708
{
Test test;
Jan 29, 2015
Jan 29, 2015
709
if (test_init(&test, config, desc, debug)) {
Feb 19, 2014
Feb 19, 2014
710
GError* error = NULL;
Feb 17, 2014
Feb 17, 2014
711
712
713
GBytes* push = g_bytes_new_static(
g_mapped_file_get_contents(test.notification_ind),
g_mapped_file_get_length(test.notification_ind));
Feb 19, 2014
Feb 19, 2014
714
715
if (mms_dispatcher_handle_push(test.disp, "TestConnection",
push, &error)) {
Feb 17, 2014
Feb 17, 2014
716
717
718
719
if (mms_dispatcher_start(test.disp)) {
test.ret = RET_OK;
g_main_loop_run(test.loop);
} else {
Jul 13, 2016
Jul 13, 2016
720
GINFO("%s FAILED", desc->name);
Feb 17, 2014
Feb 17, 2014
721
722
}
} else {
Feb 19, 2014
Feb 19, 2014
723
g_error_free(error);
Feb 17, 2014
Feb 17, 2014
724
725
if (desc->flags & TEST_PUSH_HANDLING_FAILURE_OK) {
test.ret = RET_OK;
Feb 17, 2014
Feb 17, 2014
726
test_finish(&test);
Feb 17, 2014
Feb 17, 2014
727
} else {
Jul 13, 2016
Jul 13, 2016
728
GINFO("%s FAILED", desc->name);
Feb 17, 2014
Feb 17, 2014
729
730
731
732
733
734
735
736
737
738
739
740
741
742
}
}
g_bytes_unref(push);
test_finalize(&test);
return test.ret;
} else {
return RET_ERR;
}
}
static
int
test_retrieve(
const MMSConfig* config,
Jan 29, 2015
Jan 29, 2015
743
744
const char* name,
gboolean debug)
Feb 17, 2014
Feb 17, 2014
745
746
747
748
749
750
751
{
int i, ret;
if (name) {
const TestDesc* found = NULL;
for (i=0, ret = RET_ERR; i<G_N_ELEMENTS(retrieve_tests); i++) {
const TestDesc* test = retrieve_tests + i;
if (!strcmp(test->name, name)) {
Jan 29, 2015
Jan 29, 2015
752
ret = test_retrieve_once(config, test, debug);
Feb 17, 2014
Feb 17, 2014
753
754
755
756
found = test;
break;
}
}
Jul 13, 2016
Jul 13, 2016
757
if (!found) GERR("No such test: %s", name);
Feb 17, 2014
Feb 17, 2014
758
759
} else {
for (i=0, ret = RET_OK; i<G_N_ELEMENTS(retrieve_tests); i++) {
Jan 29, 2015
Jan 29, 2015
760
761
int status = test_retrieve_once(config, retrieve_tests + i, debug);
if (ret == RET_OK && status != RET_OK) ret = status;
Feb 17, 2014
Feb 17, 2014
762
763
764
765
766
767
768
}
}
return ret;
}
int main(int argc, char* argv[])
{
May 12, 2014
May 12, 2014
769
770
771
int ret = RET_ERR;
gboolean keep_temp = FALSE;
gboolean verbose = FALSE;
Jan 29, 2015
Jan 29, 2015
772
gboolean debug = FALSE;
May 12, 2014
May 12, 2014
773
774
775
776
777
778
779
GError* error = NULL;
GOptionContext* options;
GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
{ "keep", 'k', 0, G_OPTION_ARG_NONE, &keep_temp,
"Keep temporary files", NULL },
Jan 29, 2015
Jan 29, 2015
780
781
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
"Disable timeout for debugging", NULL },
May 12, 2014
May 12, 2014
782
783
{ NULL }
};
Feb 17, 2014
Feb 17, 2014
784
May 12, 2014
May 12, 2014
785
786
options = g_option_context_new("[TEST] - MMS retrieve test");
g_option_context_add_main_entries(options, entries, NULL);
Jul 5, 2014
Jul 5, 2014
787
if (g_option_context_parse(options, &argc, &argv, &error)) {
Mar 11, 2016
Mar 11, 2016
788
const char* test = "test_retrieve";
May 12, 2014
May 12, 2014
789
MMSConfig config;
Mar 11, 2016
Mar 11, 2016
790
TestDirs dirs;
May 12, 2014
May 12, 2014
791
Mar 11, 2016
Mar 11, 2016
792
mms_lib_init(argv[0]);
Jul 13, 2016
Jul 13, 2016
793
gutil_log_set_type(GLOG_TYPE_STDOUT, test);
May 12, 2014
May 12, 2014
794
if (verbose) {
Jul 13, 2016
Jul 13, 2016
795
gutil_log_default.level = GLOG_LEVEL_VERBOSE;
May 12, 2014
May 12, 2014
796
} else {
Jul 13, 2016
Jul 13, 2016
797
798
gutil_log_timestamp = FALSE;
gutil_log_default.level = GLOG_LEVEL_INFO;
May 12, 2014
May 12, 2014
799
800
801
mms_task_http_log.level =
mms_task_decode_log.level =
mms_task_retrieve_log.level =
Jul 13, 2016
Jul 13, 2016
802
mms_task_notification_log.level = GLOG_LEVEL_NONE;
May 12, 2014
May 12, 2014
803
804
}
Mar 11, 2016
Mar 11, 2016
805
806
807
808
809
810
811
test_dirs_init(&dirs, test);
mms_lib_default_config(&config);
config.root_dir = dirs.root;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
config.attic_enabled = TRUE;
Jul 5, 2014
Jul 5, 2014
812
if (argc < 2) {
Feb 23, 2015
Feb 23, 2015
813
ret = test_retrieve(&config, NULL, debug);
Jul 5, 2014
Jul 5, 2014
814
815
816
} else {
int i;
for (i=1, ret = RET_OK; i<argc; i++) {
Jan 29, 2015
Jan 29, 2015
817
int test_status = test_retrieve(&config, argv[i], debug);
Jul 5, 2014
Jul 5, 2014
818
819
820
821
if (ret == RET_OK && test_status != RET_OK) ret = test_status;
}
}
Mar 11, 2016
Mar 11, 2016
822
test_dirs_cleanup(&dirs, !keep_temp);
Feb 23, 2015
Feb 23, 2015
823
mms_lib_deinit();
Feb 17, 2014
Feb 17, 2014
824
} else {
Jul 13, 2016
Jul 13, 2016
825
fprintf(stderr, "%s\n", GERRMSG(error));
May 12, 2014
May 12, 2014
826
g_error_free(error);
Feb 27, 2014
Feb 27, 2014
827
ret = RET_ERR;
Feb 17, 2014
Feb 17, 2014
828
}
May 12, 2014
May 12, 2014
829
g_option_context_free(options);
Feb 27, 2014
Feb 27, 2014
830
return ret;
Feb 17, 2014
Feb 17, 2014
831
832
833
834
835
836
837
838
839
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/