24
|
1 |
// Copyright (c) 2002-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 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@test
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include "WapProtSuiteStepBase.h"
|
|
22 |
|
|
23 |
#include <Gsmumsg.h>
|
|
24 |
#include <gsmubuf.h>
|
|
25 |
|
|
26 |
#include "smspver.h"
|
|
27 |
#include "WapProtSuiteDefs.h"
|
|
28 |
#include "wap_sock.h"
|
|
29 |
#include "smsstacktestconsts.h"
|
|
30 |
|
|
31 |
TVerdict CWapProtSuiteStepBase::doTestStepPreambleL()
|
|
32 |
/**
|
|
33 |
* @return - TVerdict
|
|
34 |
* Implementation of CTestStep base class virtual
|
|
35 |
* Do all initialisation common to derived classes in here.
|
|
36 |
*/
|
|
37 |
{
|
|
38 |
//base class preamble - marks the heap
|
|
39 |
CSmsBaseTestStep::doTestStepPreambleL();
|
|
40 |
|
|
41 |
return TestStepResult();
|
|
42 |
}
|
|
43 |
|
|
44 |
TVerdict CWapProtSuiteStepBase::doTestStepPostambleL()
|
|
45 |
{
|
|
46 |
//base class postamble - unmarks the heap
|
|
47 |
CSmsBaseTestStep::doTestStepPostambleL();
|
|
48 |
|
|
49 |
return TestStepResult();
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
Set up and open socket
|
|
54 |
*/
|
|
55 |
void CWapProtSuiteStepBase::SetupWapSocketL()
|
|
56 |
{
|
|
57 |
SetupWapSocketL(iSocket, iWapAddr, KWapPort);
|
|
58 |
}
|
|
59 |
|
|
60 |
void CWapProtSuiteStepBase::SetupWapSocketL(RSocket& aSocket, TWapAddr& aWapAddr, const TDesC& aPort, TBool aNewStyleClient)
|
|
61 |
{
|
|
62 |
OpenSocketL(iSocketServer, aSocket);
|
|
63 |
|
|
64 |
//Read port and SC number from ini file
|
|
65 |
ReadWapPortSettingsL(aWapAddr, aPort);
|
|
66 |
|
|
67 |
if (aNewStyleClient)
|
|
68 |
{
|
|
69 |
// Indicating to the protocol that it's a new client
|
|
70 |
INFO_PRINTF1(_L("Socket set option for indicating new client"));
|
|
71 |
TInt ret = aSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0);
|
|
72 |
TESTCHECKL(ret, KErrNone, "Indicating to the protocol that it's a new client")
|
|
73 |
}
|
|
74 |
|
|
75 |
// Bind
|
|
76 |
TInt ret = aSocket.Bind(aWapAddr);
|
|
77 |
TESTCHECKL(ret, KErrNone, "Socket bind");
|
|
78 |
|
|
79 |
TProtocolDesc desc;
|
|
80 |
aSocket.Info(desc);
|
|
81 |
INFO_PRINTF2(_L("Protocol name: %S"), &desc.iName);
|
|
82 |
|
|
83 |
TTimeIntervalMicroSeconds32 InitPause=9000000; //Required Pause to Allow SMSStack to Complete its Async Init
|
|
84 |
User::After(InitPause); //call to the TSY and finish its StartUp.
|
|
85 |
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
Setup a socket for receiving status repots
|
|
90 |
*/
|
|
91 |
void CWapProtSuiteStepBase::SetupStatusReportSocketL()
|
|
92 |
{
|
|
93 |
// Open the socket for receiving status reports
|
|
94 |
OpenSocketL(iSocketServer, iStatusReportSocket, KSMSAddrFamily, KSMSDatagramProtocol);
|
|
95 |
|
|
96 |
//Bind to the socket
|
|
97 |
iSmsAddr.SetSmsAddrFamily(ESmsAddrStatusReport);
|
|
98 |
TInt ret=iStatusReportSocket.Bind(iSmsAddr);
|
|
99 |
TESTCHECKL(ret, KErrNone, "Status Report Socket bind");
|
|
100 |
|
|
101 |
TProtocolDesc desc;
|
|
102 |
iStatusReportSocket.Info(desc);
|
|
103 |
INFO_PRINTF2(_L("Protocol name: %S"), &desc.iName);
|
|
104 |
|
|
105 |
TTimeIntervalMicroSeconds32 InitPause=9000000; //Required Pause to Allow SMSStack to Complete its Async Init
|
|
106 |
User::After(InitPause); //call to the TSY and finish its StartUp.
|
|
107 |
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
Get WAP Address from INI file
|
|
112 |
*/
|
|
113 |
void CWapProtSuiteStepBase::ReadWapPortSettingsL(TWapAddr& aWapAddr, const TDesC& aPort)
|
|
114 |
{
|
|
115 |
//Local vars
|
|
116 |
TPtrC16 telNumber;
|
|
117 |
TInt port;
|
|
118 |
|
|
119 |
//Read Port and SC number from INI file
|
|
120 |
User::LeaveIfError(GetStringFromConfig(ConfigSection(),KSCNumber,telNumber));
|
|
121 |
User::LeaveIfError(GetIntFromConfig(ConfigSection(), aPort, port));
|
|
122 |
|
|
123 |
aWapAddr.SetWapPort(TWapPortNumber(port));
|
|
124 |
TBuf8<100> scNumber;
|
|
125 |
scNumber.Copy(telNumber);
|
|
126 |
TPtrC8 scAddr(scNumber);
|
|
127 |
aWapAddr.SetWapAddress(scAddr);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
Get the coding of the message
|
|
132 |
*/
|
|
133 |
void CWapProtSuiteStepBase::SetCodingSchemeL()
|
|
134 |
{
|
|
135 |
TInt dataCoding;
|
|
136 |
TInt err = KErrNone;
|
|
137 |
|
|
138 |
//Get the port number from the ini file
|
|
139 |
GetIntFromConfig(ConfigSection(),_L("dataCoding"), dataCoding);
|
|
140 |
|
|
141 |
if(dataCoding==8)
|
|
142 |
{
|
|
143 |
err = iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS);
|
|
144 |
}
|
|
145 |
else
|
|
146 |
{
|
|
147 |
err = iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms7BitDCS);
|
|
148 |
}
|
|
149 |
|
|
150 |
TESTCHECKL(err, KErrNone, "Setting Data Coding Scheme");
|
|
151 |
}
|
|
152 |
|
|
153 |
void CWapProtSuiteStepBase::SetMessageTypeL()
|
|
154 |
{
|
|
155 |
TInt err = KErrNone;
|
|
156 |
TPtrC messageType;
|
|
157 |
|
|
158 |
//Get the type of message
|
|
159 |
GetStringFromConfig(ConfigSection(),_L("type"), messageType);
|
|
160 |
|
|
161 |
//Set the message type to WapDatagram
|
|
162 |
if(messageType.Compare(_L("Datagram")) == 0)
|
|
163 |
{
|
|
164 |
err = iSocket.SetOpt(KWapSmsOptionWapDatagram,KWapSmsOptionLevel);
|
|
165 |
}
|
|
166 |
//The creation of the message will set the type to SMART by default
|
|
167 |
// else
|
|
168 |
// User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionSmartMessage,KWapSmsOptionLevel));
|
|
169 |
|
|
170 |
TESTCHECKL(err, KErrNone, "Setting Message Type");
|
|
171 |
}
|
|
172 |
|
|
173 |
/**
|
|
174 |
Used to check the CSmsMessage, will also print details of values in CSmsMessage
|
|
175 |
*/
|
|
176 |
void CWapProtSuiteStepBase::CheckSmsMessageL(CSmsMessage& aSmsmessagebuf, TPtrC8& aScnumber)
|
|
177 |
{
|
|
178 |
TPtrC toFromAddress = aSmsmessagebuf.ToFromAddress();
|
|
179 |
TBuf<0x10> date;
|
|
180 |
TBuf<0x10> timestring;
|
|
181 |
TTime time = aSmsmessagebuf.Time();
|
|
182 |
time.FormatL(date,(_L("%D%M%Y%/0%1%/1%2%/2%3%/3")));
|
|
183 |
TDateTime dateTime(time.DateTime());
|
|
184 |
INFO_PRINTF2(_L("Value for toFromAddress: %S"), &toFromAddress);
|
|
185 |
INFO_PRINTF2(_L("Value for date: %S"), &date);
|
|
186 |
INFO_PRINTF5(_L("TimeStamp=%02d:%02d:%02d.%06d"), dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond());
|
|
187 |
HBufC16* scnumber16 = HBufC16::NewLC(aScnumber.Length());
|
|
188 |
TPtr16 scnumber16mod = scnumber16->Des();
|
|
189 |
scnumber16mod.Copy(aScnumber);
|
|
190 |
INFO_PRINTF2(_L("Value for Service Centre number: %S"), &scnumber16mod);
|
|
191 |
TESTL(scnumber16mod.Compare(aSmsmessagebuf.ServiceCenterAddress())==0);
|
|
192 |
CleanupStack::PopAndDestroy(scnumber16);
|
|
193 |
}
|
|
194 |
|
|
195 |
/**
|
|
196 |
Used to make call to get message parameters length via Ioctl
|
|
197 |
*/
|
|
198 |
TInt CWapProtSuiteStepBase::GetMessageParameterLengthL(RSocket& aSock)
|
|
199 |
{
|
|
200 |
TRequestStatus getParamStatus;
|
|
201 |
TPckgBuf<TInt> paramLength;
|
|
202 |
|
|
203 |
// Get the length of the message parameter value
|
|
204 |
INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParametersLength"));
|
|
205 |
aSock.Ioctl(KSOGetMessageParametersLength, getParamStatus, ¶mLength, KSolWapProv);
|
|
206 |
User::WaitForRequest(getParamStatus);
|
|
207 |
INFO_PRINTF1(_L("KSOGetMessageParametersLength on Ioctl completed"));
|
|
208 |
TESTL(getParamStatus.Int()==KErrNone);
|
|
209 |
|
|
210 |
// Return the message parameter length
|
|
211 |
return paramLength();
|
|
212 |
}
|
|
213 |
|
|
214 |
/**
|
|
215 |
Used to make call to get message parameters via Ioctl
|
|
216 |
*/
|
|
217 |
void CWapProtSuiteStepBase::GetMessageParameterL(RSocket& aSock, TPtr8& aParameterStorePtr)
|
|
218 |
{
|
|
219 |
TRequestStatus getParamStatus;
|
|
220 |
|
|
221 |
INFO_PRINTF1(_L("Getting message parameter..."));
|
|
222 |
aSock.Ioctl(KSOGetMessageParameters, getParamStatus, &aParameterStorePtr, KSolWapProv);
|
|
223 |
User::WaitForRequest(getParamStatus);
|
|
224 |
TESTCHECK(getParamStatus.Int(), KErrNone, "Getting message parameter");
|
|
225 |
}
|
|
226 |
|
|
227 |
/**
|
|
228 |
Used to internalise the TDes8 and check the resultant CSmsMessage
|
|
229 |
*/
|
|
230 |
void CWapProtSuiteStepBase::InternaliseSmsDataAndCheckL(TDes8& aBuffer, TPtrC8& aScnumber)
|
|
231 |
{
|
|
232 |
CSmsMessage* smsMessageBuf = NULL;
|
|
233 |
|
|
234 |
RDesReadStream reader(aBuffer);
|
|
235 |
reader.PushL();
|
|
236 |
|
|
237 |
RFs rFs;
|
|
238 |
User::LeaveIfError(rFs.Connect());
|
|
239 |
CleanupClosePushL(rFs);
|
|
240 |
|
|
241 |
smsMessageBuf = CSmsMessage::NewL(rFs, CSmsPDU::ESmsStatusReport, CSmsBuffer::NewL());
|
|
242 |
CleanupStack::PushL(smsMessageBuf);
|
|
243 |
smsMessageBuf->InternalizeWithoutBufferL(reader);
|
|
244 |
|
|
245 |
INFO_PRINTF1(_L("Check the contents of the internalized sms message"));
|
|
246 |
CheckSmsMessageL(*smsMessageBuf, aScnumber);
|
|
247 |
|
|
248 |
CleanupStack::PopAndDestroy(3, &reader); // reader, rFs, smsMessageBuf
|
|
249 |
}
|
|
250 |
|
|
251 |
void CWapProtSuiteStepBase::OpenSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TUint aAddrFamily,TUint aProtocol)
|
|
252 |
{
|
|
253 |
OpenSocketLC(aSocketServer, aSocket, aAddrFamily, aProtocol);
|
|
254 |
CleanupStack::Pop(&aSocket);
|
|
255 |
}
|
|
256 |
|
|
257 |
void CWapProtSuiteStepBase::OpenSocketLC(RSocketServ& aSocketServer, RSocket& aSocket, TUint aAddrFamily, TUint aProtocol)
|
|
258 |
{
|
|
259 |
TInt error = aSocket.Open(aSocketServer,aAddrFamily,KSockDatagram,aProtocol);
|
|
260 |
if(error != KErrNone)
|
|
261 |
{
|
|
262 |
//If error == KErrNone, do nothing.
|
|
263 |
//If error == KErrServerBusy, change the leave code to "84" to imply the failure otherwise the failed step will be started again.
|
|
264 |
//Any other errors will leave with the error code.
|
|
265 |
if(error == KErrServerBusy)
|
|
266 |
{
|
|
267 |
error = TEST_ERROR_CODE;
|
|
268 |
ERR_PRINTF2(_L("Open socket failed - error is KErrServerBusy, changing to TEST_ERROR_CODE (=%d)"), error);
|
|
269 |
}
|
|
270 |
else
|
|
271 |
{
|
|
272 |
ERR_PRINTF2(_L("Open socket failed - error=%d"), error);
|
|
273 |
}
|
|
274 |
User::Leave(error);
|
|
275 |
}
|
|
276 |
CleanupClosePushL(aSocket);
|
|
277 |
}
|
|
278 |
|
|
279 |
void CWapProtSuiteStepBase::ReceiveWapMessageFromSocket(TInt aLength, TPtrC& aData)
|
|
280 |
{
|
|
281 |
// Receiving a message, length of which should be requested prior to calling
|
|
282 |
// this method from the socket and supplied thought aLength parameter
|
|
283 |
|
|
284 |
TRequestStatus status;
|
|
285 |
TWapAddr recvWapAddr;
|
|
286 |
HBufC8* recvBuf = HBufC8::NewLC(aLength);
|
|
287 |
TPtr8 recvPtr = recvBuf->Des();
|
|
288 |
|
|
289 |
INFO_PRINTF1(_L("Receiving a message from the socket..."));
|
|
290 |
iSocket.RecvFrom(recvPtr, recvWapAddr, 0, status);
|
|
291 |
User::WaitForRequest(status);
|
|
292 |
TESTCHECKL(status.Int(), KErrNone, "Receiving a message");
|
|
293 |
|
|
294 |
TBuf8<300> data;
|
|
295 |
data.Copy(aData);
|
|
296 |
TESTCHECK(recvPtr.Compare(data), 0, "Checking the received message matched expected");
|
|
297 |
|
|
298 |
// Confirm the receipt of the message to the client
|
|
299 |
INFO_PRINTF1(_L("Setting Socket option for indicating receipt of the message..."));
|
|
300 |
TInt ret = iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0);
|
|
301 |
TESTCHECKL(ret, KErrNone, "Setting Socket option for indicating receipt of the message");
|
|
302 |
CleanupStack::PopAndDestroy(recvBuf);
|
|
303 |
}
|
|
304 |
|
|
305 |
void CWapProtSuiteStepBase::ReceiveWapMessage(TPtrC& aData)
|
|
306 |
{
|
|
307 |
TRequestStatus ioctlStatus;
|
|
308 |
TPckgBuf<TInt> length;
|
|
309 |
|
|
310 |
INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
|
|
311 |
iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
|
|
312 |
User::WaitForRequest(ioctlStatus);
|
|
313 |
TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the length of the incoming message");
|
|
314 |
|
|
315 |
// Check if reported length is correct
|
|
316 |
TESTCHECK(length(), aData.Length(), "Check if reported length is correct");
|
|
317 |
|
|
318 |
ReceiveWapMessageFromSocket(length(), aData);
|
|
319 |
}
|
|
320 |
|
|
321 |
void CWapProtSuiteStepBase::SendWapMessage(TPtrC& aData)
|
|
322 |
{
|
|
323 |
TRequestStatus status;
|
|
324 |
TBuf8<300> data;
|
|
325 |
data.Copy(aData);
|
|
326 |
|
|
327 |
INFO_PRINTF1(_L("Sending a message..."));
|
|
328 |
iSocket.SendTo(data, iWapAddr, 0, status);
|
|
329 |
User::WaitForRequest(status);
|
|
330 |
TESTCHECKL(status.Int(), KErrNone, "Sending a message");
|
|
331 |
}
|