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