/
test_mms_codec.c
95 lines (89 loc) · 2.22 KB
/
test_mms_codec.c
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
/*
* Copyright (C) 2013-2014 Jolla Ltd.
*
* 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 "mms_log.h"
#include "mms_codec.h"
#define DATA_DIR "data/"
static
gboolean
test_file(
const char* file)
{
GError* error = NULL;
char* path = g_strconcat(DATA_DIR, file, NULL);
GMappedFile* map = g_mapped_file_new(path, FALSE, &error);
g_free(path);
if (map) {
struct mms_message* msg = g_new0(struct mms_message, 1);
const void* data = g_mapped_file_get_contents(map);
const gsize length = g_mapped_file_get_length(map);
gboolean ok = mms_message_decode(data, length, msg);
g_mapped_file_unref(map);
mms_message_free(msg);
if (ok) {
MMS_INFO("OK: %s", file);
return TRUE;
}
MMS_ERR("Failed to decode %s", file);
} else {
MMS_ERR("%s", error->message);
g_error_free(error);
}
return FALSE;
}
static
gboolean
test_files(
const char* files[],
int count)
{
int i;
gboolean ok = TRUE;
for (i=0; i<count; i++) {
if (!test_file(files[i])) {
ok = FALSE;
}
}
return ok;
}
int main(int argc, char* argv[])
{
const char* mms_files[] = {
"m-acknowledge.ind",
"m-notification_1.ind",
"m-notification_2.ind",
"m-notification_3.ind",
"m-delivery.ind",
"m-read-orig.ind",
"m-retrieve_1.conf",
"m-retrieve_2.conf",
"m-retrieve_3.conf",
"m-notifyresp.ind",
"m-read-rec.ind",
"m-send.conf"
};
mms_log_stdout_timestamp = FALSE;
mms_log_default.level = MMS_LOGLEVEL_INFO;
if (test_files(mms_files, G_N_ELEMENTS(mms_files))) {
return 0;
} else {
return 1;
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/