summaryrefslogtreecommitdiffstats
path: root/tests/gsm23003
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-10-04 03:15:47 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2017-10-05 19:44:28 +0200
commit9cd1e7417e76c98094a502131af779145a77c7b9 (patch)
treebe447dced7f7e891271c8f88b3b8b738db4a2357 /tests/gsm23003
parentee497f245e78929ddb69ba1f06d27bcc886f6597 (diff)
add osmo_imsi_str_valid() and osmo_msisdn_str_valid()
Add GSM23003_IMSI_MIN_DIGITS definition. Add regression test gsm23003_test.c to test the two new functions. Will be used by OsmoHLR to validate VTY and CTRL input. Change-Id: I1e94f5b0717b947d2a7a7d36bacdf04a75cb3522
Diffstat (limited to 'tests/gsm23003')
-rw-r--r--tests/gsm23003/gsm23003_test.c124
-rw-r--r--tests/gsm23003/gsm23003_test.ok42
2 files changed, 166 insertions, 0 deletions
diff --git a/tests/gsm23003/gsm23003_test.c b/tests/gsm23003/gsm23003_test.c
new file mode 100644
index 00000000..682f1626
--- /dev/null
+++ b/tests/gsm23003/gsm23003_test.c
@@ -0,0 +1,124 @@
+/*
+ * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+
+#include <osmocom/gsm/gsm23003.h>
+#include <osmocom/core/utils.h>
+
+#define BOOL_STR(b) ((b)? "true" : "false")
+
+static struct {
+ const char *imsi;
+ bool expect_ok;
+} test_imsis[] = {
+ { "", false },
+ { " ", false },
+ { "1", false },
+ { "123", false },
+ { "12345", false },
+ { "123456", true },
+ { "1234567", true },
+ { "1234567890123", true },
+ { "123456789012345", true },
+ { "000000000000000", true },
+ { "999999999999999", true },
+ { "1234567890123456", false },
+ { "a23456789012345", false },
+ { "1234567b9012345", false },
+ { "12345678901234c", false },
+ { "123456789 01234", false },
+ { "1234567\n123456", false },
+ { "123456\t123456", false },
+ { "123456\r123456", false },
+};
+
+bool test_valid_imsi()
+{
+ int i;
+ bool pass = true;
+ bool ok = true;
+ printf("----- %s\n", __func__);
+
+ for (i = 0; i < ARRAY_SIZE(test_imsis); i++) {
+ ok = osmo_imsi_str_valid(test_imsis[i].imsi);
+ pass = pass && (ok == test_imsis[i].expect_ok);
+ printf("%2d: expect=%s result=%s imsi='%s'\n",
+ i, BOOL_STR(test_imsis[i].expect_ok), BOOL_STR(ok),
+ test_imsis[i].imsi);
+ }
+ return pass;
+}
+
+static struct {
+ const char *msisdn;
+ bool expect_ok;
+} test_msisdns[] = {
+ { "", false },
+ { " ", false },
+ { "1", true },
+ { "123", true },
+ { "12345", true },
+ { "123456", true },
+ { "1234567", true },
+ { "1234567890123", true },
+ { "123456789012345", true },
+ { "000000000000000", true },
+ { "999999999999999", true },
+ { "1234567890123456", false },
+ { "a23456789012345", false },
+ { "1234567b9012345", false },
+ { "12345678901234c", false },
+ { "123456789 01234", false },
+ { "1234567\n123456", false },
+ { "123456\t123456", false },
+ { "123456\r123456", false },
+};
+
+bool test_valid_msisdn()
+{
+ int i;
+ bool pass = true;
+ bool ok = true;
+ printf("----- %s\n", __func__);
+
+ for (i = 0; i < ARRAY_SIZE(test_msisdns); i++) {
+ ok = osmo_msisdn_str_valid(test_msisdns[i].msisdn);
+ pass = pass && (ok == test_msisdns[i].expect_ok);
+ printf("%2d: expect=%s result=%s msisdn='%s'\n",
+ i, BOOL_STR(test_msisdns[i].expect_ok), BOOL_STR(ok),
+ test_msisdns[i].msisdn);
+ }
+ return pass;
+}
+
+int main(int argc, char **argv)
+{
+ bool pass = true;
+
+ pass = pass && test_valid_imsi();
+ pass = pass && test_valid_msisdn();
+
+ OSMO_ASSERT(pass);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/gsm23003/gsm23003_test.ok b/tests/gsm23003/gsm23003_test.ok
new file mode 100644
index 00000000..777451a8
--- /dev/null
+++ b/tests/gsm23003/gsm23003_test.ok
@@ -0,0 +1,42 @@
+----- test_valid_imsi
+ 0: expect=false result=false imsi=''
+ 1: expect=false result=false imsi=' '
+ 2: expect=false result=false imsi='1'
+ 3: expect=false result=false imsi='123'
+ 4: expect=false result=false imsi='12345'
+ 5: expect=true result=true imsi='123456'
+ 6: expect=true result=true imsi='1234567'
+ 7: expect=true result=true imsi='1234567890123'
+ 8: expect=true result=true imsi='123456789012345'
+ 9: expect=true result=true imsi='000000000000000'
+10: expect=true result=true imsi='999999999999999'
+11: expect=false result=false imsi='1234567890123456'
+12: expect=false result=false imsi='a23456789012345'
+13: expect=false result=false imsi='1234567b9012345'
+14: expect=false result=false imsi='12345678901234c'
+15: expect=false result=false imsi='123456789 01234'
+16: expect=false result=false imsi='1234567
+123456'
+17: expect=false result=false imsi='123456 123456'
+18: expect=false result=false imsi='123456 123456'
+----- test_valid_msisdn
+ 0: expect=false result=false msisdn=''
+ 1: expect=false result=false msisdn=' '
+ 2: expect=true result=true msisdn='1'
+ 3: expect=true result=true msisdn='123'
+ 4: expect=true result=true msisdn='12345'
+ 5: expect=true result=true msisdn='123456'
+ 6: expect=true result=true msisdn='1234567'
+ 7: expect=true result=true msisdn='1234567890123'
+ 8: expect=true result=true msisdn='123456789012345'
+ 9: expect=true result=true msisdn='000000000000000'
+10: expect=true result=true msisdn='999999999999999'
+11: expect=false result=false msisdn='1234567890123456'
+12: expect=false result=false msisdn='a23456789012345'
+13: expect=false result=false msisdn='1234567b9012345'
+14: expect=false result=false msisdn='12345678901234c'
+15: expect=false result=false msisdn='123456789 01234'
+16: expect=false result=false msisdn='1234567
+123456'
+17: expect=false result=false msisdn='123456 123456'
+18: expect=false result=false msisdn='123456 123456'