253
|
1 |
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "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 |
// @file PBASE-T_USBDI-0490.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0490.h"
|
|
20 |
#include "testpolicy.h"
|
|
21 |
#include "modelleddevices.h"
|
253
|
22 |
#include "OstTraceDefinitions.h"
|
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
24 |
#include "PBASE-T_USBDI-0490Traces.h"
|
|
25 |
#endif
|
0
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
namespace NUnitTesting_USBDI
|
|
31 |
{
|
|
32 |
_LIT8(KPayloadPattern,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 52bytes
|
|
33 |
|
|
34 |
const TUint KBulkTransferSize = 52;
|
|
35 |
const TInt KBulkTransferInId = 1<<0;
|
|
36 |
const TInt KBulkTransferOutId = 1<<1;
|
|
37 |
|
|
38 |
const TInt KUnexpectedTransferID = -101;
|
|
39 |
const TInt KUndefinedStep = -102;
|
|
40 |
|
|
41 |
|
|
42 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0490");
|
|
43 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0490,TBool> CUT_PBASE_T_USBDI_0490::iFunctor(KTestCaseId);
|
|
44 |
|
|
45 |
CUT_PBASE_T_USBDI_0490* CUT_PBASE_T_USBDI_0490::NewL(TBool aHostRole)
|
|
46 |
{
|
253
|
47 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_NEWL_ENTRY, aHostRole );
|
0
|
48 |
CUT_PBASE_T_USBDI_0490* self = new (ELeave) CUT_PBASE_T_USBDI_0490(aHostRole);
|
|
49 |
CleanupStack::PushL(self);
|
|
50 |
self->ConstructL();
|
|
51 |
CleanupStack::Pop(self);
|
253
|
52 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_NEWL_EXIT, ( TUint )( self ) );
|
0
|
53 |
return self;
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
CUT_PBASE_T_USBDI_0490::CUT_PBASE_T_USBDI_0490(TBool aHostRole)
|
|
58 |
: CBaseBulkTestCase(KTestCaseId,aHostRole),
|
|
59 |
iCaseStep(EInProgress)
|
|
60 |
{
|
253
|
61 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY, this );
|
|
62 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_EXIT, this );
|
0
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
void CUT_PBASE_T_USBDI_0490::ConstructL()
|
|
67 |
{
|
253
|
68 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CONSTRUCTL_ENTRY, this );
|
0
|
69 |
BaseBulkConstructL();
|
253
|
70 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CONSTRUCTL_EXIT, this );
|
0
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
CUT_PBASE_T_USBDI_0490::~CUT_PBASE_T_USBDI_0490()
|
|
75 |
{
|
253
|
76 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY_DUP01, this );
|
|
77 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_EXIT_DUP01, this );
|
0
|
78 |
}
|
|
79 |
|
|
80 |
void CUT_PBASE_T_USBDI_0490::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
81 |
{
|
253
|
82 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
83 |
|
253
|
84 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
85 |
|
|
86 |
if(aCompletionCode != KErrNone)
|
|
87 |
{
|
|
88 |
if(iCaseStep == EFailed)
|
|
89 |
{// ignore error, nad catch the TestFailed method called further down.
|
253
|
90 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***");
|
0
|
91 |
}
|
|
92 |
else
|
|
93 |
{
|
|
94 |
TBuf<256> msg;
|
|
95 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
96 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP02, msg);
|
0
|
97 |
iCaseStep = EFailed;
|
|
98 |
TTestCaseFailed request(aCompletionCode,msg);
|
|
99 |
iControlEp0->SendRequest(request,this);
|
253
|
100 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
101 |
return;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
|
105 |
switch(iCaseStep)
|
|
106 |
{
|
|
107 |
// Test case passed
|
|
108 |
case EPassed:
|
|
109 |
TestPassed();
|
|
110 |
break;
|
|
111 |
|
|
112 |
// Test case failed
|
|
113 |
case EFailed:
|
|
114 |
TestFailed(KErrCompletion);
|
|
115 |
break;
|
|
116 |
|
|
117 |
case ETransferOut:
|
253
|
118 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data");
|
0
|
119 |
iOutTransfer[0]->TransferOut(KPayloadPattern);
|
|
120 |
break;
|
|
121 |
|
|
122 |
case ETransferIn:
|
253
|
123 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data");
|
0
|
124 |
iInTransfer[0]->TransferIn(KBulkTransferSize);
|
|
125 |
break;
|
|
126 |
|
|
127 |
default:
|
253
|
128 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step");
|
0
|
129 |
TestFailed(KErrUnknown);
|
|
130 |
break;
|
|
131 |
}
|
253
|
132 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
|
0
|
133 |
}
|
|
134 |
|
|
135 |
void CUT_PBASE_T_USBDI_0490::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
|
136 |
{
|
253
|
137 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
138 |
Cancel();
|
|
139 |
|
|
140 |
TInt err(KErrNone);
|
|
141 |
TBuf<256> msg;
|
253
|
142 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
0
|
143 |
|
|
144 |
switch(iCaseStep)
|
|
145 |
{
|
|
146 |
case ETransferOut:
|
|
147 |
{
|
|
148 |
if(aCompletionCode != KErrNone)
|
|
149 |
{
|
|
150 |
err = KErrCorrupt;
|
|
151 |
msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
|
|
152 |
break;
|
|
153 |
}
|
|
154 |
if(aTransferId != KBulkTransferOutId)
|
|
155 |
{
|
|
156 |
err = KUnexpectedTransferID;
|
|
157 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
|
|
158 |
err, KBulkTransferOutId, aTransferId);
|
|
159 |
break;
|
|
160 |
}
|
253
|
161 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP01, "Try to receive back sent data");
|
0
|
162 |
iCaseStep = ETransferIn;
|
|
163 |
TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
|
|
164 |
iControlEp0->SendRequest(request,this);
|
|
165 |
}
|
|
166 |
break;
|
|
167 |
|
|
168 |
case ETransferIn:
|
|
169 |
{
|
|
170 |
if(aCompletionCode != KErrNone)
|
|
171 |
{
|
|
172 |
err = KErrCorrupt;
|
|
173 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
|
|
174 |
break;
|
|
175 |
}
|
|
176 |
if(aTransferId != KBulkTransferInId)
|
|
177 |
{
|
|
178 |
err = KUnexpectedTransferID;
|
|
179 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
|
|
180 |
err, KBulkTransferInId, aTransferId);
|
|
181 |
break;
|
|
182 |
}
|
|
183 |
// Compare the data to what is expected
|
|
184 |
if(ValidateData(iInTransfer[0]->DataPolled(), KPayloadPattern, KBulkTransferSize) == EFalse)
|
|
185 |
{
|
|
186 |
err = KErrCompletion; //indicates data validation failure
|
|
187 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
|
|
188 |
break;
|
|
189 |
}
|
|
190 |
if(err == KErrNone)
|
|
191 |
{
|
|
192 |
// Comparison is a match
|
253
|
193 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP02, "Comparison for IN transfer is a match");
|
0
|
194 |
iCaseStep = EPassed;
|
|
195 |
TTestCasePassed request;
|
|
196 |
iControlEp0->SendRequest(request,this);
|
|
197 |
break;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
break;
|
|
201 |
|
|
202 |
default:
|
|
203 |
err = KUndefinedStep;
|
|
204 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
|
|
205 |
break;
|
|
206 |
}
|
|
207 |
|
|
208 |
if(err!=KErrNone)
|
|
209 |
{
|
253
|
210 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP03, msg);
|
0
|
211 |
iCaseStep = EFailed;
|
|
212 |
TTestCaseFailed request(err,msg);
|
|
213 |
return iControlEp0->SendRequest(request,this);
|
|
214 |
}
|
253
|
215 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_EXIT, this );
|
0
|
216 |
}
|
|
217 |
|
|
218 |
void CUT_PBASE_T_USBDI_0490::DeviceInsertedL(TUint aDeviceHandle)
|
|
219 |
{
|
253
|
220 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_ENTRY, this );
|
0
|
221 |
Cancel();
|
|
222 |
|
|
223 |
if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
|
|
224 |
// Prepare for response from control transfer to client
|
|
225 |
{
|
|
226 |
iCaseStep = EFailed;
|
|
227 |
}
|
|
228 |
|
|
229 |
// Create the bulk transfers
|
|
230 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
|
|
231 |
iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
|
|
232 |
|
|
233 |
// Initialise the descriptors for transfer
|
253
|
234 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL, "Initialising the transfer descriptors");
|
0
|
235 |
TInt err = iUsbInterface1.InitialiseTransferDescriptors();
|
|
236 |
if(err != KErrNone)
|
|
237 |
{
|
|
238 |
TBuf<256> msg;
|
|
239 |
msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
|
253
|
240 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_DUP01, msg);
|
0
|
241 |
iCaseStep = EFailed;
|
|
242 |
TTestCaseFailed request(err,msg);
|
|
243 |
iControlEp0->SendRequest(request,this);
|
253
|
244 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_EXIT, this );
|
0
|
245 |
return;
|
|
246 |
}
|
|
247 |
|
|
248 |
iCaseStep = ETransferOut;
|
|
249 |
TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
|
|
250 |
iControlEp0->SendRequest(request,this);
|
253
|
251 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
252 |
}
|
|
253 |
|
|
254 |
} //end namespace
|