packaging: Bump to 1.17
[platform/upstream/ofono.git] / unit / test-sms-root.c
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include <glib.h>
32 #include <glib/gprintf.h>
33
34 #include "util.h"
35 #include "smsutil.h"
36
37 static const char *assembly_pdu1 = "038121F340048155550119906041001222048C0500"
38                                         "031E0301041804420430043A002C002004100"
39                                         "43B0435043A04410430043D04340440002000"
40                                         "200441043B044304480430043B00200437043"
41                                         "000200434043204350440044C044E00200020"
42                                         "04380020002004320441043500200431043E0"
43                                         "43B044C044804350020043F04400435043804"
44                                         "41043F043E043B043D044F043B0441044F002"
45                                         "000200433043D0435";
46 static int assembly_pdu_len1 = 155;
47
48 static const char *assembly_pdu2 = "038121F340048155550119906041001222048C0500"
49                                         "031E03020432043E043C002E000A041D04300"
50                                         "43A043E043D04350446002C0020043D043500"
51                                         "200432002004410438043B043004450020043"
52                                         "40430043B043504350020044204350440043F"
53                                         "04350442044C002C0020043E043D002004410"
54                                         "44204400435043C043804420435043B044C04"
55                                         "3D043E002004320431043504360430043B002"
56                                         "004320020043A043E";
57 static int assembly_pdu_len2 = 155;
58
59 static const char *assembly_pdu3 = "038121F340048155550119906041001222044A0500"
60                                         "031E0303043C043D043004420443002C00200"
61                                         "43F043E043704300431044B0432000A043404"
62                                         "3004360435002C002004470442043E0020002"
63                                         "00431044B043B0020043D04300433002E";
64 static int assembly_pdu_len3 = 89;
65
66 static void test_serialize_assembly(void)
67 {
68         unsigned char pdu[176];
69         long pdu_len;
70         struct sms sms;
71         struct sms_assembly *assembly = sms_assembly_new("1234");
72         guint16 ref;
73         guint8 max;
74         guint8 seq;
75         GSList *l;
76
77         decode_hex_own_buf(assembly_pdu1, -1, &pdu_len, 0, pdu);
78         sms_decode(pdu, pdu_len, FALSE, assembly_pdu_len1, &sms);
79
80         sms_extract_concatenation(&sms, &ref, &max, &seq);
81         l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
82                                         &sms.deliver.oaddr, ref, max, seq);
83
84         if (g_test_verbose()) {
85                 g_print("Ref: %u\n", ref);
86                 g_print("Max: %u\n", max);
87                 g_print("From: %s\n",
88                                 sms_address_to_string(&sms.deliver.oaddr));
89         }
90
91         g_assert(g_slist_length(assembly->assembly_list) == 1);
92         g_assert(l == NULL);
93
94         decode_hex_own_buf(assembly_pdu2, -1, &pdu_len, 0, pdu);
95         sms_decode(pdu, pdu_len, FALSE, assembly_pdu_len2, &sms);
96
97         sms_extract_concatenation(&sms, &ref, &max, &seq);
98         l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
99                                         &sms.deliver.oaddr, ref, max, seq);
100         g_assert(l == NULL);
101
102         sms_assembly_free(assembly);
103
104         assembly = sms_assembly_new("1234");
105
106         decode_hex_own_buf(assembly_pdu3, -1, &pdu_len, 0, pdu);
107         sms_decode(pdu, pdu_len, FALSE, assembly_pdu_len3, &sms);
108
109         sms_extract_concatenation(&sms, &ref, &max, &seq);
110         l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
111                                         &sms.deliver.oaddr, ref, max, seq);
112
113         g_assert(l != NULL);
114
115         sms_assembly_free(assembly);
116 }
117
118 int main(int argc, char **argv)
119 {
120         g_test_init(&argc, &argv, NULL);
121
122         g_test_add_func("/testsms/Test SMS Assembly Serialize",
123                         test_serialize_assembly);
124
125         return g_test_run();
126 }