aboutsummaryrefslogtreecommitdiffstats
path: root/Tests.st
blob: 480bfc2b0206f97e4d645848e5c34fee99b14689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
TestCase subclass: GSM0808Test [
    testLAI [
        | lai res |
        res := #(16r72 16rF4 16r80) asByteArray.
        lai := LAI generateLAI: 274 mnc: 8.

        self assert: lai = res.
    ]

    testCellIE [
        | ie res msg |

        res := #(5 8 0 114 244 128 32 18 117 48) asByteArray.
        msg := Osmo.MessageBuffer new.

        ie := GSMCellIdentifier initWith: 274 mnc: 8 lac: 8210 ci: 30000.
        ie writeOn: msg.

        self assert: msg asByteArray = res.

        ie := GSMCellIdentifier parseFrom: res.
        self assert: ie mcc = 274.
        self assert: ie mnc = 8.
        self assert: ie lac = 8210.
        self assert: ie ci = 30000.
    ]

    testLayer3IE [
        | ie res msg |

        res := #(23 3 1 2 3) asByteArray.
        msg := Osmo.MessageBuffer new.
        ie := GSMLayer3Info initWith: #(1 2 3) asByteArray.
        ie writeOn: msg.

        self assert: msg asByteArray = res.

        ie := GSMLayer3Info parseFrom: res.
        self assert: ie data = #(1 2 3) asByteArray.
    ]

    testComplL3 [
        | msg buf ie res |
        msg := IEMessage initWith: GSM0808Helper msgComplL3.

        msg addIe: (GSMCellIdentifier initWith: 274 mnc: 8 lac: 8210 ci: 30000).
        msg addIe: (GSMLayer3Info initWith: #(1 2 3) asByteArray).

        buf := Osmo.MessageBuffer new.
        msg writeOn: buf.

        res := #(16r57 16r05 16r08 16r00 16r72 16rF4 16r80 16r20 16r12
                 16r75 16r30 16r17 16r03 16r01 16r02 16r03) asByteArray.
        self assert: buf asByteArray = res
    ]

    testIEDecoding [
        | inp res |
        inp := #(16r57 16r05 16r08 16r00 16r72 16rF4 16r80 16r20 16r12
                 16r75 16r30 16r17 16r03 16r01 16r02 16r03) asByteArray.

        res := IEMessage decode: inp with: GSM0808IE.
        self assert: res type = GSM0808Helper msgComplL3.
        self assert: res ies size = 2.
    ]
]

TestCase subclass: BSSAPTest [
    testPrependManagment [
        | msg |
        msg := Osmo.MessageBuffer new.
        msg putByteArray: #(1 2 3) asByteArray.

        BSSAPHelper prependManagement: msg.
        self assert: msg asByteArray = #(0 3 1 2 3) asByteArray.
    ]

    testManagment [
        | man |

        man := BSSAPManagement initWith: #(1 2 3) asByteArray.
        self assert: man toMessage asByteArray = #(0 3 1 2 3) asByteArray.
    ]

    testParseManagement [
        | man |

        man := BSSAPMessage decode: #(0 3 1 2 3) asByteArray.
        self assert: (man isKindOf: BSSAPManagement).
        self assert: man data = #(1 2 3) asByteArray.
    ]

    testPrependDTAP [
        | msg |
        msg := Osmo.MessageBuffer new.
        msg putByteArray: #(1 2 3) asByteArray.

        BSSAPHelper prependDTAP: msg dlci: 0.
        self assert: msg asByteArray = #(1 0 3 1 2 3) asByteArray.
    ]
]

TestCase subclass: GSM48Test [
    testKeySeqLu [
        | gsm msg |
        msg := Osmo.MessageBuffer new.
        gsm := GSM48KeySeqLuType createDefault.
        gsm writeOnDirect: msg.

        self assert: msg asByteArray = #(16r70) asByteArray
    ]

    testLai [
        | gsm msg |
        msg := Osmo.MessageBuffer new.
        gsm := GSM48Lai createDefault.
        gsm mcc: 202; mnc: 5; lac: 65534.
        gsm writeOnDirect: msg.

        self assert: msg asByteArray = #(16r02 16rF2 16r50 16rFF 16rFE) asByteArray.
    ]

    testCM1 [
        | gsm msg |
        msg := Osmo.MessageBuffer new.
        gsm := GSM48Classmark1 createDefault.
        gsm writeOnDirect: msg.

        self assert: msg asByteArray = #(16r33) asByteArray
    ]

    testMI [
        | gsm msg |
        msg := Osmo.MessageBuffer new.
        gsm := GSM48MIdentity createDefault.
        gsm imsi: '274080000004780'.
        gsm writeOnDirect: msg.

        self assert: msg asByteArray = #(8 41 71 128 0 0 0 116 8) asByteArray.
    ]

    testLU [
        | gsm msg |

        msg := Osmo.MessageBuffer new.
        gsm := LocationUpdatingRequest new.
        (gsm lai) mcc: 202; mnc: 5; lac: 65534.
        (gsm mi) imsi: '666105400273888'.
        gsm writeOn: msg.

        self assert: msg asByteArray = #(5 8 112 2 242 80 255 254 51 8 105 102 1 69 0 114 131 136) asByteArray.
    ]
]

TestCase subclass: TestMessages [
    testLU [
        | sccp handler |

        handler := SCCPHadler new.
        sccp := MessageTests createLU: handler.
        self assert: sccp = #(1 154 2 0 2 2 4 2 66 254 15 32 0 30 87 5 8 0 114 244 128 16 3 156 64 23 17 5 8 112 0 240 0 0 0 51 7 97 102 102 102 102 102 246 0 ) asByteArray.
    ]

    testMsgParser [
        | msg bssap bssmap |

        msg := MSGParser parse: #(1 154 2 0 2 2 4 2 66 254 15 32 0 30 87
                                  5 8 0 114 244 128 16 3 156 64 23 17 5 8
                                  112 0 240 0 0 0 51 7 97 102 102 102 102
                                  102 246 0 ) asByteArray.
        self assert: (msg isKindOf: Osmo.SCCPConnectionRequest).

        bssap := msg data.
        self assert: (bssap isKindOf: BSSAPManagement).

        bssmap := bssap data.
        self assert: (bssmap isKindOf: IEMessage).
    ]
]