summaryrefslogtreecommitdiffstats
path: root/tests/gsm23003
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gsm23003')
-rw-r--r--tests/gsm23003/gsm23003_test.c42
-rw-r--r--tests/gsm23003/gsm23003_test.ok12
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/gsm23003/gsm23003_test.c b/tests/gsm23003/gsm23003_test.c
index 79965cfb..eac5a115 100644
--- a/tests/gsm23003/gsm23003_test.c
+++ b/tests/gsm23003/gsm23003_test.c
@@ -118,6 +118,47 @@ bool test_valid_msisdn()
return pass;
}
+static struct {
+ bool with_15th_digit;
+ const char *imei;
+ bool expect_ok;
+} test_imeis[] = {
+ /* without 15th digit */
+ {false, "12345678901234", true},
+ {false, "1234567890123", false},
+ {false, "123456789012345", false},
+
+ /* with 15th digit: valid */
+ {true, "357613004448485", true},
+ {true, "357805023984447", true},
+ {true, "352936001349777", true},
+ {true, "357663017768551", true},
+
+ /* with 15th digit: invalid */
+ {true, "357613004448480", false},
+ {true, "357613004448405", false},
+ {true, "357613004448085", false},
+
+ { NULL, false, false },
+};
+
+bool test_valid_imei()
+{
+ int i;
+ bool pass = true;
+ bool ok = true;
+ printf("----- %s\n", __func__);
+
+ for (i = 0; i < ARRAY_SIZE(test_imeis); i++) {
+ ok = osmo_imei_str_valid(test_imeis[i].imei, test_imeis[i].with_15th_digit);
+ pass = pass && (ok == test_imeis[i].expect_ok);
+ printf("%2d: expect=%s result=%s imei='%s' with_15th_digit=%s\n",
+ i, BOOL_STR(test_imeis[i].expect_ok), BOOL_STR(ok),
+ test_imeis[i].imei, test_imeis[i].with_15th_digit ? "true" : "false");
+ }
+ return pass;
+}
+
struct test_mnc_from_str_result {
int rc;
uint16_t mnc;
@@ -248,6 +289,7 @@ int main(int argc, char **argv)
pass = pass && test_valid_imsi();
pass = pass && test_valid_msisdn();
+ pass = pass && test_valid_imei();
pass = pass && test_mnc_from_str();
pass = pass && test_gummei_name();
pass = pass && test_domain_gen();
diff --git a/tests/gsm23003/gsm23003_test.ok b/tests/gsm23003/gsm23003_test.ok
index c64f515c..2f7c37fe 100644
--- a/tests/gsm23003/gsm23003_test.ok
+++ b/tests/gsm23003/gsm23003_test.ok
@@ -42,6 +42,18 @@
17: expect=false result=false msisdn='123456 123456'
18: expect=false result=false msisdn='123456 123456'
19: expect=false result=false msisdn='(null)'
+----- test_valid_imei
+ 0: expect=true result=true imei='12345678901234' with_15th_digit=false
+ 1: expect=false result=false imei='1234567890123' with_15th_digit=false
+ 2: expect=false result=false imei='123456789012345' with_15th_digit=false
+ 3: expect=true result=true imei='357613004448485' with_15th_digit=true
+ 4: expect=true result=true imei='357805023984447' with_15th_digit=true
+ 5: expect=true result=true imei='352936001349777' with_15th_digit=true
+ 6: expect=true result=true imei='357663017768551' with_15th_digit=true
+ 7: expect=false result=false imei='357613004448480' with_15th_digit=true
+ 8: expect=false result=false imei='357613004448405' with_15th_digit=true
+ 9: expect=false result=false imei='357613004448085' with_15th_digit=true
+10: expect=false result=false imei='(null)' with_15th_digit=false
----- test_mnc_from_str
0: "0" rc=0 mnc=0 mnc_3_digits=0 pass
1: "00" rc=0 mnc=0 mnc_3_digits=0 pass