packaging: Bump to 1.17
[platform/upstream/ofono.git] / unit / test-common.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 <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <assert.h>
30 #include <glib.h>
31
32 #include <ofono/types.h>
33
34 #include "common.h"
35
36 static const char *invalid_strings[] = {
37         "33",
38         "*",
39         "**",
40         "***",
41         "*****",
42         "******",
43         "#",
44         "##",
45         "###",
46         "####",
47         "#####",
48         "*#",
49         "**#",
50         "****#",
51         "*****#",
52         "**#",
53         "*#",
54         "##",
55         "*04*98*0000*00000*00000#",
56         NULL
57 };
58
59 static void test_invalid(void)
60 {
61         char *sc;
62         char *sia;
63         char *sib;
64         char *sic;
65         char *sid;
66         char *dn;
67         int type;
68
69         char *str;
70         int i;
71         gboolean ret;
72
73         for (i = 0; invalid_strings[i]; i++) {
74                 if (g_test_verbose())
75                         g_print("%s...\n", invalid_strings[i]);
76
77                 str = strdup(invalid_strings[i]);
78
79                 ret = parse_ss_control_string(str, &type, &sc,
80                                                 &sia, &sib, &sic, &sid, &dn);
81                 if (ret == TRUE && strlen(sid))
82                         ret = FALSE;
83
84                 g_assert(ret == FALSE);
85
86                 free(str);
87         }
88 }
89
90 static const char *valid_strings[] = {
91         "*31#",
92         "*31#+55555",
93         "#31#",
94         "#31#+55555",
95         "*21*+55555*10*20#",
96         "*21*+55555*10#",
97         "*21**20#",
98         "*21*+55555#",
99         "*21**10*20#",
100         "*21**10#",
101         "*21***20#",
102         "*21#",
103         "**21#",
104         "*#21#",
105         "#21#",
106         "##21#",
107         NULL
108 };
109
110 static void test_valid(void)
111 {
112         char *sc;
113         char *sia;
114         char *sib;
115         char *sic;
116         char *sid;
117         char *dn;
118         int type;
119         gboolean ret;
120
121         char *str;
122         int i;
123
124         for (i = 0; valid_strings[i]; i++) {
125                 if (g_test_verbose())
126                         g_print("%s...", valid_strings[i]);
127
128                 str = strdup(valid_strings[i]);
129
130                 ret = parse_ss_control_string(str, &type, &sc,
131                                                 &sia, &sib, &sic, &sid, &dn);
132                 if (strlen(sid))
133                         ret = FALSE;
134
135                 g_assert(ret == TRUE);
136
137                 if (g_test_verbose())
138                         g_print("parsed as: %d, %s, %s, %s, %s, %s\n",
139                                         type, sc, sia, sib, sic, dn);
140
141                 free(str);
142         }
143 }
144
145 static const char *valid_apns[] = {
146         "wap.cingular",
147         "vodafone.co.uk",
148         "vodafone.com",
149         NULL
150 };
151
152 static const char *invalid_apns[] = {
153         ".",
154         "..",
155         "f..f",
156         "foo.bar.#",
157         "",
158         NULL
159 };
160
161 static void test_apn(void)
162 {
163         int i;
164         gboolean res;
165
166         for (i = 0; valid_apns[i]; i++) {
167                 if (g_test_verbose())
168                         g_print("Test Valid:%s\n", valid_apns[i]);
169
170                 res = is_valid_apn(valid_apns[i]);
171
172                 g_assert(res == TRUE);
173         }
174
175         for (i = 0; invalid_apns[i]; i++) {
176                 if (g_test_verbose())
177                         g_print("Test Invalid:%s\n", invalid_apns[i]);
178
179                 res = is_valid_apn(invalid_apns[i]);
180
181                 g_assert(res == FALSE);
182         }
183 }
184
185 int main(int argc, char **argv)
186 {
187         g_test_init(&argc, &argv, NULL);
188
189         g_test_add_func("/testutil/Invalid", test_invalid);
190         g_test_add_func("/testutil/Valid", test_valid);
191         g_test_add_func("/testutil/APN", test_apn);
192
193         return g_test_run();
194 }