blob: a408b73d2e66c5456662579b663fe82bc884816a [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 },
Neels Hofmeyr4b7c7912017-10-07 04:45:01 +020053 { NULL, false },
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +020054};
55
56bool test_valid_imsi()
57{
58 int i;
59 bool pass = true;
60 bool ok = true;
61 printf("----- %s\n", __func__);
62
63 for (i = 0; i < ARRAY_SIZE(test_imsis); i++) {
64 ok = osmo_imsi_str_valid(test_imsis[i].imsi);
65 pass = pass && (ok == test_imsis[i].expect_ok);
66 printf("%2d: expect=%s result=%s imsi='%s'\n",
67 i, BOOL_STR(test_imsis[i].expect_ok), BOOL_STR(ok),
68 test_imsis[i].imsi);
69 }
70 return pass;
71}
72
73static struct {
74 const char *msisdn;
75 bool expect_ok;
76} test_msisdns[] = {
77 { "", false },
78 { " ", false },
79 { "1", true },
80 { "123", true },
81 { "12345", true },
82 { "123456", true },
83 { "1234567", true },
84 { "1234567890123", true },
85 { "123456789012345", true },
86 { "000000000000000", true },
87 { "999999999999999", true },
88 { "1234567890123456", false },
89 { "a23456789012345", false },
90 { "1234567b9012345", false },
91 { "12345678901234c", false },
92 { "123456789 01234", false },
93 { "1234567\n123456", false },
94 { "123456\t123456", false },
95 { "123456\r123456", false },
Neels Hofmeyr4b7c7912017-10-07 04:45:01 +020096 { NULL, false },
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +020097};
98
99bool test_valid_msisdn()
100{
101 int i;
102 bool pass = true;
103 bool ok = true;
104 printf("----- %s\n", __func__);
105
106 for (i = 0; i < ARRAY_SIZE(test_msisdns); i++) {
107 ok = osmo_msisdn_str_valid(test_msisdns[i].msisdn);
108 pass = pass && (ok == test_msisdns[i].expect_ok);
109 printf("%2d: expect=%s result=%s msisdn='%s'\n",
110 i, BOOL_STR(test_msisdns[i].expect_ok), BOOL_STR(ok),
111 test_msisdns[i].msisdn);
112 }
113 return pass;
114}
115
116int main(int argc, char **argv)
117{
118 bool pass = true;
119
120 pass = pass && test_valid_imsi();
121 pass = pass && test_valid_msisdn();
122
123 OSMO_ASSERT(pass);
124
125 return EXIT_SUCCESS;
126}