|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Author Julia Blumin |
|
15 // Date March 2000 |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <e32hal.h> |
|
21 #include <f32fsys.h> |
|
22 #include <s32file.h> |
|
23 #include <barsc.h> |
|
24 |
|
25 #include <e32uid.h> |
|
26 |
|
27 //#include <prsreg.h> |
|
28 //#include <smdef.h> |
|
29 #include "WapWatcher.h" |
|
30 |
|
31 #include <es_sock.h> |
|
32 #include <e32test.h> |
|
33 #include "gsmubuf.h" |
|
34 #include "gsmumsg.h" |
|
35 #include "smsuaddr.h" |
|
36 #include "smsustrm.h" |
|
37 #include "MsvTestUtilsBase.h" |
|
38 #include "BioTestUtils.h" |
|
39 |
|
40 #include "WapSocketWatcher.h" |
|
41 |
|
42 |
|
43 |
|
44 #include "cmstd.h" |
|
45 |
|
46 _LIT(KTelephoneNumber,"+447747065443"); |
|
47 //_LIT(KTelephoneNumber,"+447771656004"); |
|
48 //_LIT(KTelephoneNumber,"+44802258765"); |
|
49 _LIT(KServiceCenterAddress,"+44385016005"); |
|
50 |
|
51 RTest test(_L("Wap Watcher.dll Harness")); |
|
52 |
|
53 RSocketServ gSS; |
|
54 RSocket gSocket; |
|
55 |
|
56 //---------------------------------------------------------------------------------------- |
|
57 TFileName theLogName; |
|
58 RFile theLog; |
|
59 RFs theFs; |
|
60 RTest gTest(_L("WapWatcher Test Harness")); |
|
61 CBioTestUtils *theUtils; |
|
62 //---------------------------------------------------------------------------------------- |
|
63 |
|
64 |
|
65 const TUid KTestUid = {0x10001270}; |
|
66 const TUid KTestUid1 = {0x10220108}; |
|
67 const TUid KTestUid2 = {0x10220109}; |
|
68 |
|
69 |
|
70 void TestScheduler::Error( TInt anError ) const |
|
71 { |
|
72 User::Leave( anError ); |
|
73 } |
|
74 |
|
75 //---------------------------------------------------------------------------------------- |
|
76 LOCAL_C void InitTestUtils() |
|
77 //---------------------------------------------------------------------------------------- |
|
78 { |
|
79 testUtils = CBioTestUtils::NewLC(gTest,ETuCleanMessageFolder); |
|
80 gTest.Start(_L("CBIODatabase")); |
|
81 gTest.Console()->ClearScreen(); |
|
82 } |
|
83 |
|
84 //---------------------------------------------------------------------------------------- |
|
85 LOCAL_C void CloseTestUtils() |
|
86 //---------------------------------------------------------------------------------------- |
|
87 { |
|
88 testUtils->TestHarnessCompleted(); |
|
89 CleanupStack::PopAndDestroy(testUtils); |
|
90 gTest.End(); |
|
91 gTest.Close(); |
|
92 } |
|
93 |
|
94 |
|
95 |
|
96 //---------------------------------------------------------------------------------------- |
|
97 LOCAL_C void SetupSchedulerL() |
|
98 //---------------------------------------------------------------------------------------- |
|
99 { |
|
100 CActiveScheduler::Install(new(ELeave)CActiveScheduler); |
|
101 User::LeaveIfError(theFs.Connect()); |
|
102 |
|
103 TFileName logName; |
|
104 theLogName.Copy(RProcess().FileName()); |
|
105 TInt start = theLogName.LocateReverse('\\'); |
|
106 TInt end = theLogName.LocateReverse('.'); |
|
107 theLogName = theLogName.Mid(start + 1, end - start - 1); |
|
108 |
|
109 // create the log filename |
|
110 theLogName.Insert(0, _L("C:\\")); |
|
111 #if defined(__WINS__) |
|
112 theLogName.Append(_L(".WINS.")); |
|
113 #else |
|
114 theLogName.Append(_L(".MARM.")); |
|
115 #endif |
|
116 #if defined(_UNICODE) |
|
117 theLogName.Append(_L("UNICODE.")); |
|
118 #else |
|
119 theLogName.Append(_L("ASCII.")); |
|
120 #endif |
|
121 #if defined(_DEBUG) |
|
122 theLogName.Append(_L("DEB.")); |
|
123 #else |
|
124 theLogName.Append(_L("REL.")); |
|
125 #endif |
|
126 theLogName.Append(_L("LOG")); |
|
127 |
|
128 // create the logfile |
|
129 User::LeaveIfError(theLog.Replace(theFs, theLogName, EFileWrite|EFileShareExclusive)); |
|
130 TBuf8<256> text; |
|
131 text.Copy(theLogName); |
|
132 theLog.Write(text); |
|
133 theLog.Write(_L8("\nTest results\n")); |
|
134 } |
|
135 |
|
136 LOCAL_C void CloseScheduler() |
|
137 { |
|
138 theLog.Write(_L8("Tests completed\n")); |
|
139 test.Printf(_L("Results saved in %S"), &theLogName); |
|
140 |
|
141 theLog.Close(); |
|
142 theFs.Close(); |
|
143 |
|
144 delete CActiveScheduler::Current(); |
|
145 } |
|
146 |
|
147 |
|
148 LOCAL_C void OpenEsock() |
|
149 { |
|
150 RSocketServ gSS; |
|
151 test.Start(_L("Opening socket server")); |
|
152 TRAPD(ret,gSS.Connect()); |
|
153 test(ret==KErrNone); |
|
154 |
|
155 |
|
156 test.Next(_L("Finding protocols")); |
|
157 |
|
158 TProtocolDesc protoInfo; |
|
159 TProtocolName protocolname=KSmsDatagram; |
|
160 ret=gSS.FindProtocol(protocolname,protoInfo); |
|
161 if(ret!=KErrNone) |
|
162 { |
|
163 test.Printf(_L("Dummy protocol not loaded")); |
|
164 test(EFalse); |
|
165 } |
|
166 |
|
167 test.Next(_L("Making sockets")); |
|
168 TUint numProtocols; |
|
169 test(gSS.NumProtocols(numProtocols)==KErrNone); |
|
170 test.Printf(_L("Loaded %d protocols\n"),numProtocols); |
|
171 // ret=gSS.GetProtocolInfo(1,protoInfo); |
|
172 // test(ret==KErrNone); |
|
173 |
|
174 test.Printf(_L("Creating Family: %d,Sock: %d,protocol: %d\n\r"),protoInfo.iAddrFamily,protoInfo.iSockType,protoInfo.iProtocol); |
|
175 ret=gSocket.Open(gSS,protoInfo.iAddrFamily,protoInfo.iSockType,protoInfo.iProtocol); |
|
176 if (ret!=KErrNone) |
|
177 test.Printf(_L("Failed %d\n\r"),ret); |
|
178 test(ret==KErrNone); |
|
179 |
|
180 test.Printf(_L("created %s socket OK\n"),protoInfo.iName.PtrZ()); |
|
181 } |
|
182 |
|
183 LOCAL_C void CloseEsock() |
|
184 { |
|
185 test.Next(_L("Closing socket")); |
|
186 gSocket.Close(); |
|
187 |
|
188 test.Next(_L("Closing ESOCK")); |
|
189 gSS.Close(); |
|
190 } |
|
191 |
|
192 |
|
193 |
|
194 //---------------------------------------------------------------------------------------- |
|
195 LOCAL_C void SendMessage() |
|
196 //---------------------------------------------------------------------------------------- |
|
197 { |
|
198 // |
|
199 // Sending message |
|
200 // |
|
201 |
|
202 TSmsAddr smsaddr; |
|
203 smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly); |
|
204 TRAPD(ret, gSocket.Bind(smsaddr)); |
|
205 test(ret==KErrNone); |
|
206 |
|
207 User::After(10000000); |
|
208 |
|
209 test.Next(_L("Sending message")); |
|
210 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
211 CSmsMessage* smsmessage=CSmsMessage::NewL(CSmsPDU::ESmsSubmit,buffer); |
|
212 CleanupStack::PushL(smsmessage); |
|
213 smsmessage->SetToFromAddressL(KTelephoneNumber); |
|
214 smsmessage->SmsPDU().SetServiceCenterAddressL(KServiceCenterAddress); |
|
215 |
|
216 buffer->InsertL(0,_L("Dis ees a message\n")); |
|
217 |
|
218 CSmsSubmit& submit=(CSmsSubmit&) smsmessage->SmsPDU(); |
|
219 submit.SetStatusReportRequest(EFalse); |
|
220 // submit.SetStatusReportRequest(ETrue); |
|
221 submit.SetValidityPeriod(TTimeIntervalMinutes(30)); |
|
222 |
|
223 RSmsSocketWriteStream writestream(gSocket); |
|
224 writestream << *smsmessage; |
|
225 writestream.CommitL(); |
|
226 |
|
227 TPckgBuf<TUint> sbuf; |
|
228 TRequestStatus status; |
|
229 gSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
230 User::WaitForRequest(status); |
|
231 User::LeaveIfError(status.Int()); |
|
232 |
|
233 |
|
234 delete smsmessage; |
|
235 } |
|
236 |
|
237 //---------------------------------------------------------------------------------------- |
|
238 LOCAL_C void CreateDestroySocketWatcher(TInt aTestNumber) |
|
239 //---------------------------------------------------------------------------------------- |
|
240 { |
|
241 testUtils->TestStart(aTestNumber, _L("Create/Destroy Sock Watchers")); |
|
242 // reserve some space on the cleanup stack |
|
243 /* for (TInt ii=0;ii<1000;++ii) |
|
244 CleanupStack::PushL(&ii); |
|
245 CleanupStack::Pop(1000); |
|
246 |
|
247 |
|
248 CWapWatcher* WapWatcher1 = CWapWatcher::NewL(theFs, log); |
|
249 delete SocketWatcher1; |
|
250 |
|
251 __UHEAP_RESET; |
|
252 __UHEAP_MARK; |
|
253 CWapWatcher* WapWatcher2 = CWapWatcher::NewL(theFs, log); |
|
254 delete SocketWatcher2; |
|
255 __UHEAP_MARKEND; |
|
256 */ |
|
257 testUtils->TestFinish(aTestNumber,0 ); |
|
258 } |
|
259 |
|
260 //---------------------------------------------------------------------------------------- |
|
261 LOCAL_C void StartWatchers(TInt aTestNumber) |
|
262 //---------------------------------------------------------------------------------------- |
|
263 { |
|
264 testUtils->TestStart(aTestNumber, _L("Starting Watchers")); |
|
265 |
|
266 |
|
267 CWatcher* watcher = NULL; |
|
268 |
|
269 SetupSchedulerL(); |
|
270 CWatcherWait* wait = CWatcherWait::NewLC(); |
|
271 |
|
272 |
|
273 // Create the watcher |
|
274 TRAPD(error, watcher = CWatcher::NewL(CActive::EPriorityStandard)); |
|
275 if (error) |
|
276 { |
|
277 testUtils->TestFinish(aTestNumber,error ); |
|
278 return; |
|
279 } |
|
280 |
|
281 CleanupStack::PushL(watcher); |
|
282 |
|
283 // Make sure watcher starts |
|
284 test.Start(_L("Waiting for SMS Messages")); |
|
285 |
|
286 wait->Start(); |
|
287 watcher->Start(wait->iStatus); |
|
288 |
|
289 // Just Start and wait... |
|
290 CActiveScheduler::Start(); |
|
291 |
|
292 testUtils->WriteComment(_L("Started Watchers")); |
|
293 |
|
294 //TestWatcherL(); |
|
295 theLog.Write(_L8("Test 1 OK\n")); |
|
296 |
|
297 |
|
298 // Close the watcher |
|
299 watcher->Cancel(); |
|
300 test(wait->iStatus.Int() == KErrCancel); |
|
301 test.End(); |
|
302 |
|
303 CleanupStack::PopAndDestroy(2); // watcher, wait |
|
304 CloseScheduler(); |
|
305 |
|
306 testUtils->TestFinish(aTestNumber,0 ); |
|
307 } |
|
308 |
|
309 |
|
310 //---------------------------------------------------------------------------------------- |
|
311 LOCAL_C void doMainL() |
|
312 //---------------------------------------------------------------------------------------- |
|
313 { |
|
314 TInt aTestNumber = 1; |
|
315 InitTestUtils(); |
|
316 |
|
317 test.Start(_L("Create/Destroy Socket Watcher")); |
|
318 CreateDestroySocketWatcher(aTestNumber++); |
|
319 |
|
320 test.Next(_L("Start Watchers")); |
|
321 //SendMessage(); |
|
322 StartWatchers(aTestNumber++); |
|
323 |
|
324 CloseTestUtils(); |
|
325 } |
|
326 |
|
327 |
|
328 |
|
329 //---------------------------------------------------------------------------------------- |
|
330 GLDEF_C TInt E32Main() |
|
331 //---------------------------------------------------------------------------------------- |
|
332 { |
|
333 __UHEAP_MARK; |
|
334 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
335 TRAPD(ret,doMainL()); |
|
336 test(ret==KErrNone); |
|
337 delete theCleanup; |
|
338 |
|
339 __UHEAP_MARKEND; |
|
340 return(KErrNone); |
|
341 } |