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-0494.cpp |
|
15 |
// @internalComponent |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include "PBASE-T_USBDI-0494.h" |
|
20 |
#include "testpolicy.h" |
|
21 |
#include "modelleddevices.h" |
|
22 |
#include "testliterals.h" |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#include "OstTraceDefinitions.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#ifdef OST_TRACE_COMPILER_IN_USE |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
#include "PBASE-T_USBDI-0494Traces.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
26 |
#endif |
0 | 27 |
|
28 |
||
29 |
||
30 |
||
31 |
namespace NUnitTesting_USBDI |
|
32 |
{ |
|
33 |
const TUint KBulkTransferSize = 1024*512; //512kB |
|
34 |
const TUint KBulkNumReadBytes = 1024*600; //600kB |
|
35 |
const TUint KBulkTransferMaxSize = KBulkNumReadBytes+KBulkTransferSize; |
|
36 |
const TInt KBulkTranferInId = 1<<0; |
|
37 |
const TInt KBulkTranferOutId = 1<<1; |
|
38 |
||
39 |
const TInt KUnexpectedTransferID = -101; |
|
40 |
const TInt KUndefinedStep = -102; |
|
41 |
||
42 |
||
43 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0494"); |
|
44 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0494,TBool> CUT_PBASE_T_USBDI_0494::iFunctor(KTestCaseId); |
|
45 |
||
46 |
CUT_PBASE_T_USBDI_0494* CUT_PBASE_T_USBDI_0494::NewL(TBool aHostRole) |
|
47 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_NEWL_ENTRY, aHostRole ); |
0 | 49 |
CUT_PBASE_T_USBDI_0494* self = new (ELeave) CUT_PBASE_T_USBDI_0494(aHostRole); |
50 |
CleanupStack::PushL(self); |
|
51 |
self->ConstructL(); |
|
52 |
CleanupStack::Pop(self); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_NEWL_EXIT, ( TUint )( self ) ); |
0 | 54 |
return self; |
55 |
} |
|
56 |
||
57 |
||
58 |
CUT_PBASE_T_USBDI_0494::CUT_PBASE_T_USBDI_0494(TBool aHostRole) |
|
59 |
: CBaseBulkTestCase(KTestCaseId,aHostRole), |
|
60 |
iCaseStep(EInProgress) |
|
61 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_ENTRY, this ); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_EXIT, this ); |
0 | 64 |
} |
65 |
||
66 |
||
67 |
void CUT_PBASE_T_USBDI_0494::ConstructL() |
|
68 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_CONSTRUCTL_ENTRY, this ); |
0 | 70 |
BaseBulkConstructL(); |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CONSTRUCTL_EXIT, this ); |
0 | 72 |
} |
73 |
||
74 |
||
75 |
CUT_PBASE_T_USBDI_0494::~CUT_PBASE_T_USBDI_0494() |
|
76 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_ENTRY_DUP01, this ); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_EXIT_DUP01, this ); |
0 | 79 |
} |
80 |
||
81 |
void CUT_PBASE_T_USBDI_0494::Ep0TransferCompleteL(TInt aCompletionCode) |
|
82 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_ENTRY, this ); |
0 | 84 |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
0 | 86 |
|
87 |
if(aCompletionCode != KErrNone) |
|
88 |
{ |
|
89 |
if(iCaseStep == EFailed) |
|
90 |
{// 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
|
91 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***"); |
0 | 92 |
} |
93 |
else |
|
94 |
{ |
|
95 |
TBuf<256> msg; |
|
96 |
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
|
97 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP02, msg); |
0 | 98 |
iCaseStep = EFailed; |
99 |
TTestCaseFailed request(aCompletionCode,msg); |
|
100 |
iControlEp0->SendRequest(request,this); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_EXIT, this ); |
0 | 102 |
return; |
103 |
} |
|
104 |
} |
|
105 |
||
106 |
switch(iCaseStep) |
|
107 |
{ |
|
108 |
// Test case passed |
|
109 |
case EPassed: |
|
110 |
TestPassed(); |
|
111 |
break; |
|
112 |
||
113 |
// Test case failed |
|
114 |
case EFailed: |
|
115 |
TestFailed(KErrCompletion); |
|
116 |
break; |
|
117 |
||
118 |
case ETransferOut: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data"); |
0 | 120 |
iOutTransfer[0]->TransferOut(KLiteralEnglish8(), KBulkTransferSize, ETrue); |
121 |
break; |
|
122 |
||
123 |
case ETransferIn: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data"); |
0 | 125 |
iInTransfer[0]->TransferIn(KBulkNumReadBytes); //require completion using ZLP |
126 |
break; |
|
127 |
||
128 |
default: |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step"); |
0 | 130 |
TestFailed(KErrUnknown); |
131 |
break; |
|
132 |
} |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this ); |
0 | 134 |
} |
135 |
||
136 |
void CUT_PBASE_T_USBDI_0494::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) |
|
137 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_ENTRY, this ); |
0 | 139 |
Cancel(); |
140 |
||
141 |
TInt err(KErrNone); |
|
142 |
TBuf<256> msg; |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode); |
0 | 144 |
|
145 |
switch(iCaseStep) |
|
146 |
{ |
|
147 |
case ETransferOut: |
|
148 |
{ |
|
149 |
if(aCompletionCode != KErrNone) |
|
150 |
{ |
|
151 |
err = KErrCorrupt; |
|
152 |
msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode); |
|
153 |
break; |
|
154 |
} |
|
155 |
||
156 |
if(aTransferId != KBulkTranferOutId) |
|
157 |
{ |
|
158 |
err = KUnexpectedTransferID; |
|
159 |
msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"), |
|
160 |
err, KBulkTranferOutId, aTransferId); |
|
161 |
break; |
|
162 |
} |
|
163 |
||
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP01, "Try to receive back sent data"); |
0 | 165 |
iCaseStep = ETransferIn; |
166 |
TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1) |
|
167 |
iControlEp0->SendRequest(request,this); |
|
168 |
} |
|
169 |
break; |
|
170 |
||
171 |
case ETransferIn: |
|
172 |
{ |
|
173 |
if(aCompletionCode != KErrNone) |
|
174 |
{ |
|
175 |
err = KErrCorrupt; |
|
176 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode); |
|
177 |
break; |
|
178 |
} |
|
179 |
||
180 |
if(aTransferId != KBulkTranferInId) |
|
181 |
{ |
|
182 |
err = KUnexpectedTransferID; |
|
183 |
msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"), |
|
184 |
err, KBulkTranferInId, aTransferId); |
|
185 |
break; |
|
186 |
} |
|
187 |
||
188 |
// Compare the data to what is expected |
|
189 |
if(ValidateData(iInTransfer[0]->DataPolled(), KLiteralEnglish8(), KBulkTransferSize) == EFalse) |
|
190 |
{ |
|
191 |
err = KErrCompletion; //indicates data validation failure |
|
192 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); |
|
193 |
break; |
|
194 |
} |
|
195 |
||
196 |
if(err == KErrNone) |
|
197 |
{ |
|
198 |
// Comparison is a match |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP02, "Comparison for IN transfer is a match"); |
0 | 200 |
iCaseStep = EPassed; |
201 |
TTestCasePassed request; |
|
202 |
iControlEp0->SendRequest(request,this); |
|
203 |
} |
|
204 |
} |
|
205 |
break; |
|
206 |
||
207 |
default: |
|
208 |
err = KUndefinedStep; |
|
209 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep); |
|
210 |
break; |
|
211 |
} |
|
212 |
||
213 |
if(err!=KErrNone) |
|
214 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP03, msg); |
0 | 216 |
iCaseStep = EFailed; |
217 |
TTestCaseFailed request(err,msg); |
|
218 |
return iControlEp0->SendRequest(request,this); |
|
219 |
} |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_EXIT, this ); |
0 | 221 |
} |
222 |
||
223 |
void CUT_PBASE_T_USBDI_0494::DeviceInsertedL(TUint aDeviceHandle) |
|
224 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_ENTRY, this ); |
0 | 226 |
Cancel(); |
227 |
||
228 |
if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError) |
|
229 |
// Prepare for response from control transfer to client |
|
230 |
{ |
|
231 |
iCaseStep = EFailed; |
|
232 |
} |
|
233 |
||
234 |
// Create the bulk transfers |
|
235 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferInId); |
|
236 |
iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferOutId); |
|
237 |
||
238 |
// Initialise the descriptors for transfer |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL, "Initialising the transfer descriptors"); |
0 | 240 |
TInt err = iUsbInterface1.InitialiseTransferDescriptors(); |
241 |
if(err != KErrNone) |
|
242 |
{ |
|
243 |
TBuf<256> msg; |
|
244 |
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
|
245 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_DUP01, msg); |
0 | 246 |
iCaseStep = EFailed; |
247 |
TTestCaseFailed request(err,msg); |
|
248 |
iControlEp0->SendRequest(request,this); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_EXIT, this ); |
0 | 250 |
return; |
251 |
} |
|
252 |
||
253 |
iCaseStep = ETransferOut; |
|
254 |
TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP ??FIXME |
|
255 |
iControlEp0->SendRequest(request,this); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_EXIT_DUP01, this ); |
0 | 257 |
} |
258 |
||
259 |
} //end namespace |