sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @file PBASE-T_USBDI-0474.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-0474.h"
|
sl@0
|
20 |
#include "testpolicy.h"
|
sl@0
|
21 |
#include "modelleddevices.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
namespace NUnitTesting_USBDI
|
sl@0
|
25 |
{
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0474");
|
sl@0
|
28 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0474,TBool> CUT_PBASE_T_USBDI_0474::iFunctor(KTestCaseId);
|
sl@0
|
29 |
|
sl@0
|
30 |
CUT_PBASE_T_USBDI_0474* CUT_PBASE_T_USBDI_0474::NewL(TBool aHostRole)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CUT_PBASE_T_USBDI_0474* self = new (ELeave) CUT_PBASE_T_USBDI_0474(aHostRole);
|
sl@0
|
33 |
CleanupStack::PushL(self);
|
sl@0
|
34 |
self->ConstructL();
|
sl@0
|
35 |
CleanupStack::Pop(self);
|
sl@0
|
36 |
return self;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
CUT_PBASE_T_USBDI_0474::CUT_PBASE_T_USBDI_0474(TBool aHostRole)
|
sl@0
|
41 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
sl@0
|
42 |
iCaseStep(EInProgress)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
|
sl@0
|
47 |
void CUT_PBASE_T_USBDI_0474::ConstructL()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iTestDevice = new RUsbDeviceB(this);
|
sl@0
|
50 |
BaseConstructL();
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
CUT_PBASE_T_USBDI_0474::~CUT_PBASE_T_USBDI_0474()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
LOG_FUNC
|
sl@0
|
57 |
Cancel();
|
sl@0
|
58 |
|
sl@0
|
59 |
iUsbInterface0.Close();
|
sl@0
|
60 |
|
sl@0
|
61 |
delete iClientAction;
|
sl@0
|
62 |
delete iActorFDF;
|
sl@0
|
63 |
if(!IsHost() && iTestDevice)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
iTestDevice->Close();
|
sl@0
|
66 |
}
|
sl@0
|
67 |
delete iTestDevice;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
void CUT_PBASE_T_USBDI_0474::ExecuteHostTestCaseL()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
LOG_FUNC
|
sl@0
|
74 |
|
sl@0
|
75 |
iActorFDF = CActorFDF::NewL(*this);
|
sl@0
|
76 |
iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0);
|
sl@0
|
77 |
iActorFDF->Monitor();
|
sl@0
|
78 |
TimeoutIn(30);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
void CUT_PBASE_T_USBDI_0474::ExecuteDeviceTestCaseL()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
LOG_FUNC
|
sl@0
|
85 |
|
sl@0
|
86 |
iTestDevice->OpenL(TestCaseId());
|
sl@0
|
87 |
iTestDevice->SubscribeToReports(iStatus);
|
sl@0
|
88 |
SetActive();
|
sl@0
|
89 |
iTestDevice->SoftwareConnect();
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
void CUT_PBASE_T_USBDI_0474::HostDoCancel()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
LOG_FUNC
|
sl@0
|
96 |
|
sl@0
|
97 |
// Cancel the test step timeout
|
sl@0
|
98 |
|
sl@0
|
99 |
CancelTimeout();
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
void CUT_PBASE_T_USBDI_0474::DeviceDoCancel()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
LOG_FUNC
|
sl@0
|
106 |
|
sl@0
|
107 |
// Cancel the device
|
sl@0
|
108 |
|
sl@0
|
109 |
iTestDevice->CancelSubscriptionToReports();
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
void CUT_PBASE_T_USBDI_0474::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
LOG_FUNC
|
sl@0
|
115 |
Cancel();
|
sl@0
|
116 |
TInt err(KErrNone);
|
sl@0
|
117 |
|
sl@0
|
118 |
// Validate that device is as expected
|
sl@0
|
119 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
sl@0
|
120 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
// Incorrect device for this test case
|
sl@0
|
123 |
|
sl@0
|
124 |
RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
sl@0
|
125 |
KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
|
sl@0
|
126 |
|
sl@0
|
127 |
// Start the connection timeout again
|
sl@0
|
128 |
|
sl@0
|
129 |
TimeoutIn(30);
|
sl@0
|
130 |
return;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
// Check tree now
|
sl@0
|
134 |
TUsbGenericDescriptor deviceDesc = testDevice.DeviceDescriptor();
|
sl@0
|
135 |
TUsbGenericDescriptor configDesc = testDevice.ConfigurationDescriptor();
|
sl@0
|
136 |
|
sl@0
|
137 |
// Check tree now
|
sl@0
|
138 |
CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceB")) == KErrNone);
|
sl@0
|
139 |
|
sl@0
|
140 |
// Inform client device test case successful
|
sl@0
|
141 |
TUint32 token0;
|
sl@0
|
142 |
err = testDevice.Device().GetTokenForInterface(0,token0);
|
sl@0
|
143 |
if(err != KErrNone)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
|
sl@0
|
146 |
return TestFailed(err);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
err = iUsbInterface0.Open(token0); // Default interface setting 0
|
sl@0
|
149 |
if(err != KErrNone)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0);
|
sl@0
|
152 |
return TestFailed(err);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
iCaseStep = EPassed;
|
sl@0
|
156 |
TTestCasePassed request;
|
sl@0
|
157 |
iClientAction->SendRequest(request,this);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
|
sl@0
|
161 |
void CUT_PBASE_T_USBDI_0474::DeviceRemovedL(TUint aDeviceHandle)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
LOG_FUNC
|
sl@0
|
164 |
|
sl@0
|
165 |
// The test device should not be removed until the test case has passed
|
sl@0
|
166 |
// so this test case has not completed, and state this event as an error
|
sl@0
|
167 |
|
sl@0
|
168 |
TestFailed(KErrDisconnected);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
|
sl@0
|
172 |
void CUT_PBASE_T_USBDI_0474::BusErrorL(TInt aError)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
LOG_FUNC
|
sl@0
|
175 |
|
sl@0
|
176 |
// This test case handles no failiures on the bus
|
sl@0
|
177 |
|
sl@0
|
178 |
TestFailed(aError);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
|
sl@0
|
182 |
void CUT_PBASE_T_USBDI_0474::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
sl@0
|
183 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
LOG_FUNC
|
sl@0
|
186 |
Cancel();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CUT_PBASE_T_USBDI_0474::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
LOG_FUNC
|
sl@0
|
192 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
sl@0
|
193 |
|
sl@0
|
194 |
if(iCaseStep == EPassed)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
TestPassed();
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
if(iCaseStep == EFailed)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
TestFailed(KErrCompletion);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
|
sl@0
|
206 |
void CUT_PBASE_T_USBDI_0474::HostRunL()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
LOG_FUNC
|
sl@0
|
209 |
|
sl@0
|
210 |
// Obtain the completion code
|
sl@0
|
211 |
TInt completionCode(iStatus.Int());
|
sl@0
|
212 |
|
sl@0
|
213 |
if(completionCode == KErrNone)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
// Action timeout
|
sl@0
|
216 |
RDebug::Printf("<Error> Action timeout");
|
sl@0
|
217 |
TestFailed(KErrTimedOut);
|
sl@0
|
218 |
}
|
sl@0
|
219 |
else
|
sl@0
|
220 |
{
|
sl@0
|
221 |
RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
|
sl@0
|
222 |
TestFailed(completionCode);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
void CUT_PBASE_T_USBDI_0474::DeviceRunL()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
LOG_FUNC
|
sl@0
|
229 |
|
sl@0
|
230 |
// Disconnect the device
|
sl@0
|
231 |
|
sl@0
|
232 |
iTestDevice->SoftwareDisconnect();
|
sl@0
|
233 |
|
sl@0
|
234 |
// Complete the test case request
|
sl@0
|
235 |
|
sl@0
|
236 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|