blob: 682f1626203f26aac340c3635daa923c4876c37f [file] [log] [blame]
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +02001/*
2 * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
3 * All Rights Reserved
4 *
5 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <stdio.h>
24
25#include <osmocom/gsm/gsm23003.h>
26#include <osmocom/core/utils.h>
27
28#define BOOL_STR(b) ((b)? "true" : "false")
29
30static struct {
31 const char *imsi;
32 bool expect_ok;
33} test_imsis[] = {
34 { "", false },
35 { " ", false },
36 { "1", false },
37 { "123", false },
38 { "12345", false },
39 { "123456", true },
40 { "1234567", true },
41 { "1234567890123", true },
42 { "123456789012345", true },
43 { "000000000000000", true },
44 { "999999999999999", true },
45 { "1234567890123456", false },
46 { "a23456789012345", false },
47 { "1234567b9012345", false },
48 { "12345678901234c", false },
49 { "123456789 01234", false },
50 { "1234567\n123456", false },
51 { "123456\t123456", false },
52 { "123456\r123456", false },
53};
54
55bool test_valid_imsi()
56{
57 int i;
58 bool pass = true;
59 bool ok = true;
60 printf("----- %s\n", __func__);
61
62 for (i = 0; i < ARRAY_SIZE(test_imsis); i++) {
63 ok = osmo_imsi_str_valid(test_imsis[i].imsi);
64 pass = pass && (ok == test_imsis[i].expect_ok);
65 printf("%2d: expect=%s result=%s imsi='%s'\n",
66 i, BOOL_STR(test_imsis[i].expect_ok), BOOL_STR(ok),
67 test_imsis[i].imsi);
68 }
69 return pass;
70}
71
72static struct {
73 const char *msisdn;
74 bool expect_ok;
75} test_msisdns[] = {
76 { "", false },
77 { " ", false },
78 { "1", true },
79 { "123", true },
80 { "12345", true },
81 { "123456", true },
82 { "1234567", true },
83 { "1234567890123", true },
84 { "123456789012345", true },
85 { "000000000000000", true },
86 { "999999999999999", true },
87 { "1234567890123456", false },
88 { "a23456789012345", false },
89 { "1234567b9012345", false },
90 { "12345678901234c", false },
91 { "123456789 01234", false },
92 { "1234567\n123456", false },
93 { "123456\t123456", false },
94 { "123456\r123456", false },
95};
96
97bool test_valid_msisdn()
98{
99 int i;
100 bool pass = true;
101 bool ok = true;
102 printf("----- %s\n", __func__);
103
104 for (i = 0; i < ARRAY_SIZE(test_msisdns); i++) {
105 ok = osmo_msisdn_str_valid(test_msisdns[i].msisdn);
106 pass = pass && (ok == test_msisdns[i].expect_ok);
107 printf("%2d: expect=%s result=%s msisdn='%s'\n",
108 i, BOOL_STR(test_msisdns[i].expect_ok), BOOL_STR(ok),
109 test_msisdns[i].msisdn);
110 }
111 return pass;
112}
113
114int main(int argc, char **argv)
115{
116 bool pass = true;
117
118 pass = pass && test_valid_imsi();
119 pass = pass && test_valid_msisdn();
120
121 OSMO_ASSERT(pass);
122
123 return EXIT_SUCCESS;
124}