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)
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
20 from gsmd_common
import GsmdCommon
23 class NetworkTests(GsmdCommon
):
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")
46 def test_Register(self
):
47 self
.ipc
.Network_Register()
48 data
= [ ("read","AT+COPS=0,0"),
50 ("write",'+CREG: 1,1'),
51 ("ensure_reply_set",True)] #Make sure we get some reply
53 self
.queryCurrentOperator("Operator")
54 self
.signalStrength(20)
55 data
= [ ("ensure_signal",("NetworkStatus",
56 {"provider" : "Operator",
59 ("ensure_reply_set",True)] #Ensure that reply is set
62 def test_Register_Fail(self
):
63 self
.ipc
.Network_Register()
64 data
= [ ("read","AT+COPS=0,0"),
66 ("ensure_error_set",True)] #Ensure that error is set
69 def networkRegistrationStatus(self
,status
):
70 data
= [("read","AT+CREG?") ]
74 data
= [("write","+CREG: 0,"+str(status
)),
77 data
= [("write","ERROR")]
81 def queryCurrentOperator(self
,name
):
82 data
= [("read","AT+COPS?")] #Ensure that error is set
86 data
= [ ("write",'+COPS: 1,0,"'+name
+'"'),
89 data
= [("write","ERROR") ]
95 def signalStrength(self
,strength
):
96 data
= [("read","AT+CSQ")]
99 if strength
!= "ERROR":
100 data
= [ ("write",'+CSQ: '+str(strength
)+',0'),
103 data
= [("write","ERROR")]
108 def status_handler(self
,provider
,status
,strength
):
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
))]
119 self
.queryCurrentOperator(name
)
120 self
.signalStrength(20)
121 data
= [("ensure_signal",("NetworkStatus",
123 "registration" : str(status
),
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})]
143 #Ensure that values are cached
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})]
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
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
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
175 def test_ListProviders(self
):
176 '''Test listing providers
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")])]
190 def test_ListProviders_Fail(self
):
191 '''Test failing to list providers'''
192 self
.ipc
.Network_ListProviders()
193 data
= [ ("read",'AT+COPS=?'),
195 ("ensure_reply_set",False),
196 ("ensure_error_set",True)]
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")
209 assert DBUS.got_modemctrl_modemStatus(0)
211 DBUS.modemctrl.queryModemStatus()
212 write_reply(port,"+CPAS: 1")
213 assert DBUS.got_modemctrl_modemStatus(1)
216 DBUS.modemctrl.queryModemStatus()
217 write_reply(port,"+CPAS: 3")
219 assert DBUS.got_modemctrl_modemStatus(3)
222 DBUS.modemctrl.queryModemStatus()
223 write_reply(port,"+CPAS: 4")
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
238 assert DBUS.got_modemctrl_setDateTimeResp (1);
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))