4daf003abf87d9e7a5098f379f5e3b5bbd1ac473
[osmocom-bb.git] / tests / sms / sms_test.c
1 /*
2  * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
3  * (C) 2010 by Nico Golde <nico@ngolde.de>
4  * All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
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 along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <osmocore/msgb.h>
27 #include <osmocore/gsm_utils.h>
28
29 int main(int argc, char** argv)
30 {
31         printf("SMS testing\n");
32         struct msgb *msg;
33         uint8_t *sms;
34         uint8_t i;
35
36         /* test 7-bit coding/decoding */
37         const char *input = "test text";
38         uint8_t length;
39         uint8_t coded[256];
40         char result[256];
41
42         length = gsm_7bit_encode(coded, input);
43         gsm_7bit_decode(result, coded, length);
44         if (strcmp(result, input) != 0) {
45                 printf("7 Bit coding failed... life sucks\n");
46                 printf("Wanted: '%s' got '%s'\n", input, result);
47                 return -1;
48         }
49
50         memset(coded, 0, sizeof(coded));
51         memset(result, 0, sizeof(coded));
52         input = strdup("!$ a more#^- complicated test@@?_\%! case");
53         length = gsm_7bit_encode(coded, input);
54         gsm_7bit_decode(result, coded, length);
55         if (strcmp(result, input) != 0) {
56                 printf("7 Bit coding failed... life sucks\n");
57                 printf("Wanted: '%s' got '%s'\n", input, result);
58                 return -2;
59         }
60
61         return 0;
62 }