blob: 79349ad20afe4368c4e7a15be985b26ff955be1d [file] [log] [blame]
Neels Hofmeyrd20f93a2020-02-24 22:42:22 +01001/* Copyright 2020 sysmocom s.f.m.c. GmbH
2 * SPDX-License-Identifier: Apache-2.0 */
3package org.osmocom.IMSIPseudo;
4import org.osmocom.IMSIPseudo.*;
5
6public class Test {
7 private static byte nibble2hex(byte nibble)
8 {
9 nibble = (byte)(nibble & 0xf);
10 if (nibble < 0xa)
11 return (byte)('0' + nibble);
12 else
13 return (byte)('a' + nibble - 0xa);
14 }
15
16 private static byte[] hexdump(byte data[])
17 {
18 byte res[] = new byte[(byte)(data.length*2)];
19 for (byte i = 0; i < data.length; i++) {
20 res[(byte)(i*2)] = nibble2hex((byte)(data[i] >> 4));
21 res[(byte)(i*2 + 1)] = nibble2hex(data[i]);
22 }
23 return res;
24 }
25
26 private static String hexdumpStr(byte data[])
27 {
28 return new String(hexdump(data));
29 }
30
Neels Hofmeyr483f5a42020-02-25 03:06:12 +010031 private static final String[] imsis = {
32 "123456",
33 "1234567",
34 "12345678",
35 "123456789",
36 "1234567890",
37 "12345678901",
38 "123456789012",
39 "1234567890123",
40 "12345678901234",
41 "123456789012345",
42 "1234567890123456",
43 };
44
45 private static void test_str2mi2str()
46 {
47 for (int i = 0; i < imsis.length; i++) {
48 byte str[] = imsis[i].getBytes();
49 byte mi[] = MobileIdentity.str2mi(str, MobileIdentity.MI_IMSI, (byte)9);
50 byte str_from_mi[] = MobileIdentity.mi2str(mi);
51 System.out.print("IMSI " + new String(str) + " --> MI " + hexdumpStr(mi) + " --> IMSI "
52 + new String(str_from_mi));
53 if (Bytes.equals(str, str_from_mi))
54 System.out.println(" (ok)");
55 else
56 System.out.println(" ERROR!");
57 }
58 }
59
Neels Hofmeyrb5ca3122020-02-25 03:26:23 +010060 private static void test_toStr()
61 {
62 byte nr = -128;
63 while (true) {
64 System.out.println("" + nr + " = '" + new String(Bytes.toStr(nr)) + "'");
65 if (nr == 127)
66 break;
67 nr++;
68 }
69 }
70
Neels Hofmeyrd20f93a2020-02-24 22:42:22 +010071 public static void main(String args[]){
Neels Hofmeyr483f5a42020-02-25 03:06:12 +010072 test_str2mi2str();
Neels Hofmeyrb5ca3122020-02-25 03:26:23 +010073 test_toStr();
Neels Hofmeyrd20f93a2020-02-24 22:42:22 +010074 }
75}