aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Test.st
blob: a8372e26092b8b133468a8777029c67cb3589baa (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
"
 (C) 2010 by Holger Hans Peter Freyther
 All Rights Reserved

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
"

PackageLoader fileInPackage: 'SUnit'.

TestCase subclass: HLRTest [
    <category: 'OsmoMSC-Tests'>

    testHLRFind [
        | hlr sub |
        hlr := HLRLocalCollection new.
        hlr addSubscriber: '123456'.
        hlr addSubscriber: '345677'.

        self deny: (hlr findSubscriberByIMSI: '123456') isNil.
        self deny: (hlr findSubscriberByIMSI: '345677') isNil.
        self assert: (hlr findSubscriberByIMSI: '432432') isNil.

        sub := hlr findSubscriberByIMSI: '123456'.
        self assert: sub imsi = '123456'.
    ]
]

HLRResolver subclass: HLRDummyResolver [
    <category: 'OsmoMSC-Tests'>

    insertSubscriber: aIMSI [ ^ true ]
]

TestCase subclass: VLRTest [
    <category: 'OsmoMSC-Tests'>

    testVLRFind [
        | vlr sub1 sub2 |
        vlr := VLRLocalCollection initWith: HLRDummyResolver new.
        self assert: (vlr insertSubscriber: '123456').

        sub1 := vlr findSubscriberByIMSI: '123456' ifAbsent: [2342].
        self assert: sub1 imsi = '123456'.
        self assert: sub1 tmsi isNil.

        sub2 := vlr findSubscriberByTMSI: 2342 ifAbsent: [true].
        self assert: (sub2 isKindOf: True).

        sub1 instVarNamed: #tmsi put: 2342.
        sub2 := vlr findSubscriberByTMSI: 2342 ifAbsent: [false].
        self assert: sub1 = sub2.
    ]
]

TestCase subclass: BSCConfigTest [
    <category: 'OsmoMSC-Tests'>
    <comment: 'I will test the BSCConfig'>

    testConfigItem [
        | item1 item2 addr |
        addr := Sockets.SocketAddress byName: '127.0.0.1'.
        item1 := BSCConfigItem initWith: '127.0.0.1' name: 'test1'.
        item2 := BSCConfigItem initWith: addr name: 'test2'.

        self assert: item1 name = 'test1'.
        self assert: item1 peer = addr.
        self assert: item1 lac = -1.
        self deny: item1 connected.

        self assert: item2 name = 'test2'.
        self assert: item2 peer = addr.
        self assert: item2 lac = -1.
        self deny: item2 connected.
    ]

    testConfig [
        | cfg |

        "Test that adding stuff again is refused"

        cfg := BSCConfig new.
        self shouldnt:
            [cfg addBSC: '127.0.0.1' withName: 'abc1' andLac: 2311 sendOsmoRSIP: false]
            raise: Exception description: 'Simply adding it'.
        self should:
            [cfg addBSC: '127.0.0.1' withName: 'abc2' andLac: 1123 sendOsmoRSIP: false]
            raise: Exception description: 'Same IP is forbidden'.
        self should:
            [cfg addBSC: '127.0.0.2' withName: 'abc3' andLac: 2311 sendOsmoRSIP: false]
            raise: Exception description: 'Different IP same lac'.
        self shouldnt:
            [cfg addBSC: '127.0.0.2' withName: 'abc4' andLac: 1123 sendOsmoRSIP: false]
            raise: Exception description: 'Different IP, different lac'.

        self assert: cfg bscList size = 2 description: 'Two BSCs should be registered'.


        cfg removeBSC: '127.0.0.1'.
        self assert: cfg bscList size = 1 description: 'One BSC should be gone'.
        cfg removeBSCByLac: 1123.
        self assert: cfg bscList size = 0 description: 'All BSCsshould be removed'.
    ]
]

TestCase subclass: BSCListenerTest [
    <category: 'OsmoMSC-Tests'>
    <comment: 'Test some basic socket functionality'>

    testListenAndStop [
        | listener res |
        listener := BSCListener initWith: '127.0.0.1' port: 9245 handler: nil.

        'Will attempt to stop the connection' printNl.
        [(Delay forSeconds: 2) wait. listener stop] fork.
        res := listener serve.
        self deny: res.

        "Test that it will work again"
        'Will attempt to stop the connection2' printNl.
        listener start.
        [(Delay forSeconds: 2) wait. listener stop] fork.
        res := listener serve.
        self deny: res.
    ]

    testListenOnDeadSocket [
        | listener res |
        listener := BSCListener initWith: '127.0.0.1' port: 9245 handler: nil.
        listener stop.
        res := listener serve.
        self deny: res.
    ]
]

TestCase subclass: MSCBSCConnectionHandlerTest [
    <category: 'OsmoMSC-Tests'>
    <comment: 'I should test the feature that each config can only
    be connected once but that is not done yet. It requires some work
    on socket code. TODO!!!'>

    testOnlyOnce [
"
        | msc socket bsc |
        msc := MSCApplication new.
        msc bscConfig addBSC: '127.0.0.1' withName: 'foo' andLac: 4711.
        bsc := msc bscConfig bscList first.

        socket := DummySocket new.
        socket instVarNamed: #peer put: bsc peer.
        socket instVarNamed: #closed put: false.
"
    ]
]

TestCase subclass: BSCIPAConnectionTest [
    <category: 'OsmoMSC-Tests'>
    <comment: 'I just do some simple smoke testing here'>

    testSmoke [
        | ipa |
        ipa := BSCIPAConnection
                createOn: 'hi' writeStream
                withConfig: (BSCConfigItem initWith: '0.0.0.0' name: 'foo')
                msc: nil.
    ]
]