author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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" |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#include "OstTraceDefinitions.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#include "PBASE-T_USBDI-0490Traces.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY, this ); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CONSTRUCTL_ENTRY, this ); |
0 | 69 |
BaseBulkConstructL(); |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY_DUP01, this ); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_ENTRY, this ); |
0 | 83 |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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. |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step"); |
0 | 129 |
TestFailed(KErrUnknown); |
130 |
break; |
|
131 |
} |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_ENTRY, this ); |
0 | 138 |
Cancel(); |
139 |
||
140 |
TInt err(KErrNone); |
|
141 |
TBuf<256> msg; |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
} |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
} |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_EXIT, this ); |
0 | 216 |
} |
217 |
||
218 |
void CUT_PBASE_T_USBDI_0490::DeviceInsertedL(TUint aDeviceHandle) |
|
219 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_EXIT_DUP01, this ); |
0 | 252 |
} |
253 |
||
254 |
} //end namespace |