Fixed network Status signal signature
[gsmd2.git] / test / network_unit.py
blobc4dfc195615d8b5841e853c3bff4413c54cf2dc3
1 # Copyright(C) 2007,2008 Ixonos Plc
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Boston, MA 02111.
17 # Written by Matti Katila, Yi Zheng, Vesa Pikki and Heikki Paajanen
19 import unittest,time
20 from gsmd_common import GsmdCommon
21 import unittest
23 class NetworkTests(GsmdCommon):
24 '''
25 def test_RegisterWithProvider(self):
26 self.fail("Test not implemented")
27 def test_RegisterWithProvider_Fail(self):
28 self.fail("Test not implemented")
30 def test_GetSubscriberNumbers(self):
31 self.fail("Test not implemented")
32 def test_GetSubscriberNumbers_Fail(self):
33 self.fail("Test not implemented")
35 def test_GetCountryCode(self):
36 self.fail("Test not implemented")
37 def test_GetCountryCode_Fail(self):
38 self.fail("Test not implemented")
40 def test_GetHomeCountryCode(self):
41 self.fail("Test not implemented")
42 def test_GetHomeCountryCode_Fail(self):
43 self.fail("Test not implemented")
44 '''
46 def test_Register(self):
47 self.ipc.Network_Register()
48 data = [ ("read","AT+COPS=0,0"),
49 ("write","OK"),
50 ("write",'+CREG: 1,1'),
51 ("ensure_reply_set",True)] #Make sure we get some reply
52 self.perform(data)
53 self.queryCurrentOperator("Operator")
54 self.signalStrength(20)
55 data = [ ("ensure_signal",("NetworkStatus",
56 {"provider" : "Operator",
57 "registration" : "1",
58 "strength" : 20})),
59 ("ensure_reply_set",True)] #Ensure that reply is set
60 self.perform(data)
62 def test_Register_Fail(self):
63 self.ipc.Network_Register()
64 data = [ ("read","AT+COPS=0,0"),
65 ("write","ERROR"),
66 ("ensure_error_set",True)] #Ensure that error is set
67 self.perform(data)
69 def networkRegistrationStatus(self,status):
70 data = [("read","AT+CREG?") ]
71 self.perform(data)
73 if status != "ERROR":
74 data = [("write","+CREG: 0,"+str(status)),
75 ("write","OK")]
76 else:
77 data = [("write","ERROR")]
79 self.perform(data)
81 def queryCurrentOperator(self,name):
82 data = [("read","AT+COPS?")] #Ensure that error is set
83 self.perform(data)
85 if name != "ERROR":
86 data = [ ("write",'+COPS: 1,0,"'+name+'"'),
87 ("write","OK")]
88 else:
89 data = [("write","ERROR") ]
91 self.perform(data)
95 def signalStrength(self,strength):
96 data = [("read","AT+CSQ")]
97 self.perform(data)
99 if strength != "ERROR":
100 data = [ ("write",'+CSQ: '+str(strength)+',0'),
101 ("write","OK")]
102 else:
103 data = [("write","ERROR")]
105 self.perform(data)
108 def status_handler(self,provider,status,strength):
109 if self.debug:
110 print "Provider: ",provider
111 print "Status: ",status
112 print "Strength: ",strength
113 self.reply = (provider,status,strength)
114 self.reply_event.set()
116 def write_status(self,status,name):
117 data = [("write","+CREG: "+str(status))]
118 self.perform(data)
119 self.queryCurrentOperator(name)
120 self.signalStrength(20)
121 data = [("ensure_signal",("NetworkStatus",
122 {"provider" : name,
123 "registration" : str(status),
124 "strength" : 20}))]
125 self.perform(data)
129 def test_Status(self):
130 self.write_status(1,"FI 2G")
134 def test_GetStatus(self):
135 self.ipc.Network_GetStatus()
136 self.networkRegistrationStatus(1)
137 self.queryCurrentOperator("FI 2G")
138 self.signalStrength(20)
139 data = [ ("ensure_error_set",False), #Ensure we don't have an error reply
140 ("ensure_reply",{"provider" : "FI 2G","registration" : "1","strength" : 20})]
141 self.perform(data)
143 #Ensure that values are cached
144 self.reset()
145 self.ipc.Network_GetStatus()
146 self.signalStrength(20)
147 data = [ ("ensure_error_set",False), #Ensure we don't have an error reply
148 ("ensure_reply",{"provider" : "FI 2G","registration" : "1","strength" : 20})]
149 self.perform(data)
151 def test_GetStatus_Fail(self):
152 self.ipc.Network_GetStatus()
153 self.networkRegistrationStatus("ERROR")
154 data = [("ensure_error_set",True)] #Ensure that error is set
155 self.perform(data)
157 def test_GetStatus_Fail2(self):
158 self.ipc.Network_GetStatus()
159 self.networkRegistrationStatus(1)
160 self.queryCurrentOperator("ERROR")
161 data = [("ensure_error_set",True)] #Ensure that error is set
162 self.perform(data)
165 def test_GetStatus_Fail3(self):
166 self.ipc.Network_GetStatus()
167 self.networkRegistrationStatus(1)
168 self.queryCurrentOperator("FI 2G")
169 self.signalStrength("ERROR")
170 data = [("ensure_error_set",True)] #Ensure that error is set
171 self.perform(data)
175 def test_ListProviders(self):
176 '''Test listing providers
178 Sample output
179 AT+COPS=?
181 +COPS: (2,"FI SONERA",,"24491"),(3,"FI 2G",,"24412"),(3,"FI RADIOLINJA",,"24405"),(3,"FI 07",,"24407"),,(0-4),(0,2)
184 self.ipc.Network_ListProviders()
185 data = [ ("read",'AT+COPS=?'),
186 ("write",'+COPS: (2,"FI SONERA",,"24491"),(3,"FI 2G",,"24412"),(3,"FI RADIOLINJA",,"24405"),(3,"FI 07",,"24407"),,(0-4),(0,2)'),
187 ("ensure_reply",[(0,"2","FI SONERA", "24491"),(1,"3","FI 2G", "24412"),(2,"3","FI RADIOLINJA", "24405"),(3,"3","FI 07", "24407")])]
188 self.perform(data)
190 def test_ListProviders_Fail(self):
191 '''Test failing to list providers'''
192 self.ipc.Network_ListProviders()
193 data = [ ("read",'AT+COPS=?'),
194 ("write",'ERROR'),
195 ("ensure_reply_set",False),
196 ("ensure_error_set",True)]
197 self.perform(data)
202 def test_modemStatus():
203 DBUS = dbus_thread.get_instance().dbus
204 DBUS.modemctrl.queryModemStatus()
205 atcmd = readline(port)
206 assert atcmd == "AT+CPAS", 'got '+atcmd
207 write_reply(port,"+CPAS: 0")
208 writeOK(port)
209 assert DBUS.got_modemctrl_modemStatus(0)
210 DBUS.clear()
211 DBUS.modemctrl.queryModemStatus()
212 write_reply(port,"+CPAS: 1")
213 assert DBUS.got_modemctrl_modemStatus(1)
215 DBUS.clear()
216 DBUS.modemctrl.queryModemStatus()
217 write_reply(port,"+CPAS: 3")
218 writeOK(port)
219 assert DBUS.got_modemctrl_modemStatus(3)
221 DBUS.clear()
222 DBUS.modemctrl.queryModemStatus()
223 write_reply(port,"+CPAS: 4")
224 writeOK(port)
225 assert DBUS.got_modemctrl_modemStatus(4)
232 def test_date_time ():
233 DBUS = dbus_thread.get_instance().dbus
234 DBUS.modemctrl.setDateTime("02/09/07,22:30:00+00")
235 atcmd = readline (port)
236 assert atcmd == 'AT+CCLK="02/09/07,22:30:00+00"', 'got '+atcmd
237 writeOK (port)
238 assert DBUS.got_modemctrl_setDateTimeResp (1);
239 #read back
240 DBUS.clear()
241 DBUS.modemctrl.queryDateTime()
242 atcmd = readline (port)
243 assert atcmd == 'AT+CCLK?', 'got '+ atcmd
244 write_reply (port, '+CCLK: "02/09/07,22:30:25"')
245 assert DBUS.got_modemctrl_dateTime ("02/09/07,22:30:25");
248 if __name__ == "__main__":
249 unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))