253
|
1 |
// Copyright (c) 2000-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 |
// e32test/usb/t_usb_device/src/apitests.cpp
|
|
15 |
// USB Test Program T_USB_DEVICE, functional part.
|
|
16 |
// Device-side part, to work against T_USB_HOST running on the host.
|
253
|
17 |
//
|
0
|
18 |
//
|
|
19 |
|
|
20 |
#include "general.h" // CActiveControl, CActiveRW
|
|
21 |
#include "config.h"
|
|
22 |
#include "usblib.h" // Helpers
|
253
|
23 |
#include "OstTraceDefinitions.h"
|
|
24 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
25 |
#include "apitestsTraces.h"
|
|
26 |
#endif
|
|
27 |
|
0
|
28 |
|
|
29 |
extern RTest test;
|
|
30 |
extern TBool gVerbose;
|
|
31 |
extern TBool gSkip;
|
|
32 |
extern TBool gTempTest;
|
|
33 |
|
|
34 |
_LIT16(KString_one, "Arbitrary String Descriptor Test String 1");
|
|
35 |
_LIT16(KString_two, "Another Arbitrary String Descriptor Test String");
|
|
36 |
|
|
37 |
void SetupDescriptors(LDDConfigPtr aLddPtr,RDEVCLIENT* aPort, TUint16 aPid = 0)
|
|
38 |
{
|
|
39 |
// === Device Descriptor
|
|
40 |
test.Start(_L("Set up descriptors"));
|
|
41 |
|
|
42 |
test.Next(_L("GetDeviceDescriptorSize"));
|
|
43 |
TInt deviceDescriptorSize = 0;
|
|
44 |
aPort->GetDeviceDescriptorSize(deviceDescriptorSize);
|
|
45 |
test_Equal(KUsbDescSize_Device,static_cast<TUint>(deviceDescriptorSize));
|
|
46 |
|
|
47 |
test.Next(_L("GetDeviceDescriptor"));
|
|
48 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
|
49 |
TInt r = aPort->GetDeviceDescriptor(deviceDescriptor);
|
|
50 |
test_KErrNone(r);
|
|
51 |
|
|
52 |
test.Next(_L("SetDeviceDescriptor"));
|
|
53 |
const TInt KUsbSpecOffset = 2;
|
|
54 |
const TInt KUsbDevClass = 4;
|
|
55 |
const TInt KUsbDevSubClass = 5;
|
|
56 |
const TInt KUsbDevProtocol = 6;
|
|
57 |
const TInt KUsbVendorIdOffset = 8;
|
|
58 |
const TInt KUsbProductIdOffset = 10;
|
|
59 |
const TInt KUsbDevReleaseOffset = 12;
|
|
60 |
// Change the USB spec number
|
|
61 |
deviceDescriptor[KUsbSpecOffset] = LoByte(aLddPtr->iSpec);
|
|
62 |
deviceDescriptor[KUsbSpecOffset+1] = HiByte(aLddPtr->iSpec);
|
|
63 |
// Change the Device Class, SubClass and Protocol to zero so that they are not device specific
|
|
64 |
// and diferent clases can used on different interfaces
|
|
65 |
deviceDescriptor[KUsbDevClass] = 0;
|
|
66 |
deviceDescriptor[KUsbDevSubClass] = 0;
|
|
67 |
deviceDescriptor[KUsbDevProtocol] = 0;
|
|
68 |
// Change the device vendor ID (VID)
|
|
69 |
deviceDescriptor[KUsbVendorIdOffset] = LoByte(aLddPtr->iVid); // little endian!
|
|
70 |
deviceDescriptor[KUsbVendorIdOffset+1] = HiByte(aLddPtr->iVid);
|
|
71 |
// Change the device product ID (PID)
|
|
72 |
if (aPid != 0)
|
253
|
73 |
{
|
0
|
74 |
deviceDescriptor[KUsbProductIdOffset] = LoByte(aPid); // little endian!
|
253
|
75 |
deviceDescriptor[KUsbProductIdOffset+1] = HiByte(aPid);
|
0
|
76 |
}
|
|
77 |
else
|
|
78 |
{
|
|
79 |
deviceDescriptor[KUsbProductIdOffset] = LoByte(aLddPtr->iPid); // little endian!
|
253
|
80 |
deviceDescriptor[KUsbProductIdOffset+1] = HiByte(aLddPtr->iPid);
|
0
|
81 |
}
|
|
82 |
// Change the device release number
|
|
83 |
deviceDescriptor[KUsbDevReleaseOffset] = LoByte(aLddPtr->iRelease); // little endian!
|
|
84 |
deviceDescriptor[KUsbDevReleaseOffset+1] = HiByte(aLddPtr->iRelease);
|
|
85 |
r = aPort->SetDeviceDescriptor(deviceDescriptor);
|
|
86 |
test_KErrNone(r);
|
|
87 |
|
|
88 |
if (!gSkip)
|
|
89 |
{
|
|
90 |
test.Next(_L("GetDeviceDescriptor()"));
|
|
91 |
TBuf8<KUsbDescSize_Device> descriptor2;
|
|
92 |
r = aPort->GetDeviceDescriptor(descriptor2);
|
|
93 |
test_KErrNone(r);
|
|
94 |
|
|
95 |
test.Next(_L("Compare device descriptor with value set"));
|
|
96 |
r = descriptor2.Compare(deviceDescriptor);
|
253
|
97 |
test_KErrNone(r);
|
0
|
98 |
}
|
|
99 |
|
|
100 |
// === Configuration Descriptor
|
|
101 |
|
|
102 |
test.Next(_L("GetConfigurationDescriptorSize"));
|
|
103 |
TInt configDescriptorSize = 0;
|
|
104 |
aPort->GetConfigurationDescriptorSize(configDescriptorSize);
|
|
105 |
test_Equal(KUsbDescSize_Config,static_cast<TUint>(configDescriptorSize));
|
|
106 |
|
|
107 |
test.Next(_L("GetConfigurationDescriptor"));
|
|
108 |
TBuf8<KUsbDescSize_Config> configDescriptor;
|
|
109 |
r = aPort->GetConfigurationDescriptor(configDescriptor);
|
|
110 |
test_KErrNone(r);
|
|
111 |
|
|
112 |
test.Next(_L("SetConfigurationDescriptor"));
|
|
113 |
// Change Self Power and Remote Wakeup
|
|
114 |
const TInt KUsbAttributesOffset = 7;
|
|
115 |
const TUint8 KUsbAttributeDefault = 0x80;
|
|
116 |
const TUint8 KUsbAttributeSelfPower = 0x40;
|
|
117 |
const TUint8 KUsbAttributeRemoteWakeup = 0x20;
|
253
|
118 |
configDescriptor[KUsbAttributesOffset] = KUsbAttributeDefault | (aLddPtr->iSelfPower ? KUsbAttributeSelfPower : 0)
|
0
|
119 |
| (aLddPtr->iRemoteWakeup ? KUsbAttributeRemoteWakeup : 0);
|
|
120 |
// Change the reported max power
|
|
121 |
// 100mA (= 2 * 0x32) is the highest value allowed for a bus-powered device.
|
|
122 |
const TInt KUsbMaxPowerOffset = 8;
|
|
123 |
configDescriptor[KUsbMaxPowerOffset] = aLddPtr->iMaxPower;
|
|
124 |
r = aPort->SetConfigurationDescriptor(configDescriptor);
|
|
125 |
test_KErrNone(r);
|
|
126 |
|
|
127 |
if (!gSkip)
|
|
128 |
{
|
|
129 |
test.Next(_L("GetConfigurationDescriptor()"));
|
|
130 |
TBuf8<KUsbDescSize_Config> descriptor2;
|
|
131 |
r = aPort->GetConfigurationDescriptor(descriptor2);
|
|
132 |
test_KErrNone(r);
|
|
133 |
|
|
134 |
test.Next(_L("Compare configuration desc with value set"));
|
|
135 |
r = descriptor2.Compare(configDescriptor);
|
|
136 |
test_KErrNone(r);
|
|
137 |
}
|
253
|
138 |
|
0
|
139 |
// === String Descriptors
|
|
140 |
|
|
141 |
test.Next(_L("SetStringDescriptor"));
|
|
142 |
|
|
143 |
// Set up any standard string descriptors that were defined in the xml config
|
|
144 |
if (aLddPtr->iManufacturer)
|
|
145 |
{
|
|
146 |
r = aPort->SetManufacturerStringDescriptor(* aLddPtr->iManufacturer);
|
|
147 |
test_KErrNone(r);
|
|
148 |
}
|
253
|
149 |
|
0
|
150 |
if (aLddPtr->iProduct)
|
|
151 |
{
|
|
152 |
r = aPort->SetProductStringDescriptor(* aLddPtr->iProduct);
|
|
153 |
test_KErrNone(r);
|
|
154 |
}
|
|
155 |
|
|
156 |
if (aLddPtr->iSerialNumber)
|
|
157 |
{
|
|
158 |
r = aPort->SetSerialNumberStringDescriptor(* aLddPtr->iSerialNumber);
|
|
159 |
test_KErrNone(r);
|
|
160 |
}
|
|
161 |
|
|
162 |
// Set up two arbitrary string descriptors, which can be queried
|
|
163 |
// manually from the host side for testing purposes
|
253
|
164 |
|
0
|
165 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(KString_one);
|
|
166 |
r = aPort->SetStringDescriptor(stridx1, wr_str);
|
|
167 |
test_KErrNone(r);
|
|
168 |
|
|
169 |
wr_str.FillZ(wr_str.MaxLength());
|
|
170 |
wr_str = KString_two;
|
|
171 |
r = aPort->SetStringDescriptor(stridx2, wr_str);
|
|
172 |
test_KErrNone(r);
|
|
173 |
|
|
174 |
test.End();
|
253
|
175 |
|
0
|
176 |
}
|
|
177 |
|
|
178 |
static void TestDeviceQualifierDescriptor(RDEVCLIENT* aPort)
|
|
179 |
{
|
|
180 |
test.Start(_L("Device_Qualifier Descriptor Manipulation"));
|
|
181 |
|
|
182 |
test.Next(_L("GetDeviceQualifierDescriptor()"));
|
|
183 |
TBuf8<KUsbDescSize_DeviceQualifier> descriptor;
|
|
184 |
TInt r = aPort->GetDeviceQualifierDescriptor(descriptor);
|
|
185 |
test_KErrNone(r);
|
|
186 |
|
|
187 |
test.Next(_L("SetDeviceQualifierDescriptor()"));
|
|
188 |
// Change the USB spec number to 3.00
|
|
189 |
descriptor[KDevDesc_SpecOffset] = 0x00;
|
|
190 |
descriptor[KDevDesc_SpecOffset+1] = 0x03;
|
|
191 |
// Change the device class, subclass and protocol codes
|
|
192 |
descriptor[KDevDesc_DevClassOffset] = 0xA1;
|
|
193 |
descriptor[KDevDesc_DevSubClassOffset] = 0xB2;
|
|
194 |
descriptor[KDevDesc_DevProtocolOffset] = 0xC3;
|
|
195 |
r = aPort->SetDeviceQualifierDescriptor(descriptor);
|
|
196 |
test_KErrNone(r);
|
|
197 |
|
|
198 |
test.Next(_L("GetDeviceQualifierDescriptor()"));
|
|
199 |
TBuf8<KUsbDescSize_DeviceQualifier> descriptor2;
|
|
200 |
r = aPort->GetDeviceQualifierDescriptor(descriptor2);
|
|
201 |
test_KErrNone(r);
|
|
202 |
|
|
203 |
test.Next(_L("Compare Device_Qualifier desc with value set"));
|
|
204 |
r = descriptor2.Compare(descriptor);
|
|
205 |
test_Equal(0,r);
|
|
206 |
|
|
207 |
test.End();
|
|
208 |
}
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
static void TestOtherSpeedConfigurationDescriptor(RDEVCLIENT* aPort)
|
|
213 |
{
|
|
214 |
test.Start(_L("Other_Speed_Configuration Desc Manipulation"));
|
|
215 |
|
|
216 |
test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
|
|
217 |
TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor;
|
|
218 |
TInt r = aPort->GetOtherSpeedConfigurationDescriptor(descriptor);
|
|
219 |
test_KErrNone(r);
|
|
220 |
|
|
221 |
test.Next(_L("SetOtherSpeedConfigurationDescriptor()"));
|
|
222 |
// Invert Remote-Wakup support
|
|
223 |
descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup);
|
|
224 |
// Change the reported max power to 330mA (2 * 0xA5)
|
|
225 |
descriptor[KConfDesc_MaxPowerOffset] = 0xA5;
|
|
226 |
r = aPort->SetOtherSpeedConfigurationDescriptor(descriptor);
|
|
227 |
test_KErrNone(r);
|
|
228 |
|
|
229 |
test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
|
|
230 |
TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor2;
|
|
231 |
r = aPort->GetOtherSpeedConfigurationDescriptor(descriptor2);
|
|
232 |
test_KErrNone(r);
|
|
233 |
|
|
234 |
test.Next(_L("Compare O_S_Config desc with value set"));
|
|
235 |
r = descriptor2.Compare(descriptor);
|
|
236 |
test_KErrNone(r);
|
|
237 |
|
|
238 |
test.End();
|
|
239 |
}
|
|
240 |
|
|
241 |
|
|
242 |
static void TestInterfaceDescriptor(RDEVCLIENT* aPort, TInt aNumSettings)
|
|
243 |
{
|
|
244 |
test.Start(_L("Interface Descriptor Manipulation"));
|
|
245 |
|
|
246 |
// For all settings
|
|
247 |
|
|
248 |
TInt desc_size = 0;
|
|
249 |
TInt r = 0;
|
|
250 |
TBuf8<KUsbDescSize_Interface> descriptor;
|
|
251 |
TBuf8<KUsbDescSize_Interface> descriptor2;
|
|
252 |
for (TInt i =0; i < aNumSettings; i++)
|
|
253 |
{
|
253
|
254 |
|
0
|
255 |
test.Next(_L("GetInterfaceDescriptorSize()"));
|
|
256 |
r = aPort->GetInterfaceDescriptorSize(i, desc_size);
|
|
257 |
if (r != KErrNone)
|
|
258 |
{
|
253
|
259 |
OstTraceExt2(TRACE_NORMAL, TESTINTERFACEDESCRIPTOR_TESTINTERFACEDESCRIPTOR, "Error %d in GetInterfaceDescriptorSize %d\n",r,i);
|
0
|
260 |
}
|
|
261 |
test_KErrNone(r);
|
|
262 |
test_Equal(KUsbDescSize_Interface,static_cast<TUint>(desc_size));
|
|
263 |
|
|
264 |
test.Next(_L("GetInterfaceDescriptor()"));
|
|
265 |
r = aPort->GetInterfaceDescriptor(i, descriptor);
|
|
266 |
test_KErrNone(r);
|
|
267 |
|
|
268 |
test.Next(_L("SetInterfaceDescriptor()"));
|
|
269 |
// Change the interface protocol to 0x78(+)
|
|
270 |
TUint8 prot = 0x78;
|
|
271 |
if (descriptor[KIfcDesc_ProtocolOffset] == prot)
|
|
272 |
prot++;
|
|
273 |
descriptor[KIfcDesc_ProtocolOffset] = prot;
|
|
274 |
r = aPort->SetInterfaceDescriptor(i, descriptor);
|
|
275 |
test_KErrNone(r);
|
|
276 |
|
|
277 |
test.Next(_L("GetInterfaceDescriptor()"));
|
|
278 |
r = aPort->GetInterfaceDescriptor(i, descriptor2);
|
|
279 |
test_KErrNone(r);
|
|
280 |
|
|
281 |
test.Next(_L("Compare interface descriptor with value set"));
|
|
282 |
r = descriptor2.Compare(descriptor);
|
|
283 |
test_KErrNone(r);
|
|
284 |
}
|
253
|
285 |
|
0
|
286 |
test.Next(_L("GetInterfaceDescriptor()"));
|
|
287 |
r = aPort->GetInterfaceDescriptor(aNumSettings, descriptor);
|
|
288 |
test_Equal(KErrNotFound,r);
|
|
289 |
|
|
290 |
test.Next(_L("SetInterfaceDescriptor()"));
|
|
291 |
r = aPort->SetInterfaceDescriptor(aNumSettings, descriptor);
|
|
292 |
test_Equal(KErrNotFound,r);
|
253
|
293 |
|
0
|
294 |
test.End();
|
|
295 |
}
|
|
296 |
|
|
297 |
|
|
298 |
static void TestClassSpecificDescriptors(RDEVCLIENT* aPort)
|
|
299 |
{
|
|
300 |
test.Start(_L("Class-specific Descriptor Manipulation"));
|
|
301 |
|
|
302 |
// First a class-specific Interface descriptor
|
|
303 |
|
|
304 |
test.Next(_L("SetCSInterfaceDescriptorBlock()"));
|
|
305 |
// choose arbitrary new descriptor size
|
|
306 |
const TInt KUsbDescSize_CS_Interface = KUsbDescSize_Interface + 10;
|
|
307 |
TBuf8<KUsbDescSize_CS_Interface> cs_ifc_descriptor;
|
|
308 |
cs_ifc_descriptor.FillZ(cs_ifc_descriptor.MaxLength());
|
|
309 |
cs_ifc_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Interface;
|
|
310 |
cs_ifc_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Interface;
|
|
311 |
TInt r = aPort->SetCSInterfaceDescriptorBlock(0, cs_ifc_descriptor);
|
|
312 |
test_KErrNone(r);
|
|
313 |
|
|
314 |
test.Next(_L("GetCSInterfaceDescriptorBlockSize()"));
|
|
315 |
TInt desc_size = 0;
|
|
316 |
r = aPort->GetCSInterfaceDescriptorBlockSize(0, desc_size);
|
|
317 |
test_KErrNone(r);
|
|
318 |
test_Equal(KUsbDescSize_CS_Interface,desc_size);
|
|
319 |
|
|
320 |
test.Next(_L("GetCSInterfaceDescriptorBlock()"));
|
|
321 |
TBuf8<KUsbDescSize_CS_Interface> descriptor;
|
|
322 |
r = aPort->GetCSInterfaceDescriptorBlock(0, descriptor);
|
|
323 |
test_KErrNone(r);
|
|
324 |
|
|
325 |
test.Next(_L("Compare CS ifc descriptor with value set"));
|
|
326 |
r = descriptor.Compare(cs_ifc_descriptor);
|
|
327 |
test_KErrNone(r);
|
|
328 |
|
|
329 |
// Next a class-specific Endpoint descriptor
|
|
330 |
|
|
331 |
test.Next(_L("SetCSEndpointDescriptorBlock()"));
|
|
332 |
// choose arbitrary new descriptor size
|
|
333 |
const TInt KUsbDescSize_CS_Endpoint = KUsbDescSize_Endpoint + 5;
|
|
334 |
TBuf8<KUsbDescSize_CS_Endpoint> cs_ep_descriptor;
|
|
335 |
cs_ep_descriptor.FillZ(cs_ep_descriptor.MaxLength());
|
|
336 |
cs_ep_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Endpoint;
|
|
337 |
cs_ep_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Endpoint;
|
|
338 |
r = aPort->SetCSEndpointDescriptorBlock(0, 2, cs_ep_descriptor);
|
|
339 |
test_KErrNone(r);
|
|
340 |
|
|
341 |
test.Next(_L("GetCSEndpointDescriptorBlockSize()"));
|
|
342 |
r = aPort->GetCSEndpointDescriptorBlockSize(0, 2, desc_size);
|
|
343 |
test_KErrNone(r);
|
|
344 |
test_Equal(KUsbDescSize_CS_Endpoint,desc_size);
|
|
345 |
|
|
346 |
test.Next(_L("GetCSEndpointDescriptorBlock()"));
|
|
347 |
TBuf8<KUsbDescSize_CS_Endpoint> descriptor2;
|
|
348 |
r = aPort->GetCSEndpointDescriptorBlock(0, 2, descriptor2);
|
|
349 |
test_KErrNone(r);
|
|
350 |
|
|
351 |
test.Next(_L("Compare CS ep descriptor with value set"));
|
|
352 |
r = descriptor2.Compare(cs_ep_descriptor);
|
|
353 |
test_KErrNone(r);
|
|
354 |
|
|
355 |
test.End();
|
|
356 |
}
|
|
357 |
|
|
358 |
|
|
359 |
void TestEndpointDescriptor(RDEVCLIENT* aPort,TInt aIfSetting, TInt aEpNumber,TUsbcEndpointInfo aEpInfo)
|
|
360 |
{
|
|
361 |
test.Start(_L("Endpoint Descriptor Manipulation"));
|
|
362 |
|
|
363 |
TBuf8<KUsbDescSize_AudioEndpoint> epDescriptor;
|
|
364 |
TInt desc_size;
|
|
365 |
TInt r = aPort->GetEndpointDescriptorSize(aIfSetting, aEpNumber, desc_size);
|
|
366 |
test_KErrNone(r);
|
|
367 |
test_Equal(KUsbDescSize_Endpoint + aEpInfo.iExtra,static_cast<TUint>(desc_size));
|
|
368 |
|
|
369 |
r = aPort->GetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
|
|
370 |
test_KErrNone(r);
|
|
371 |
|
|
372 |
test(((aEpInfo.iDir & KUsbEpDirIn) && (epDescriptor[KEpDesc_AddressOffset] & 0x80) ||
|
|
373 |
!(aEpInfo.iDir & KUsbEpDirIn) && !(epDescriptor[KEpDesc_AddressOffset] & 0x80)) &&
|
|
374 |
EpTypeMask2Value(aEpInfo.iType) == (TUint)(epDescriptor[KEpDesc_AttributesOffset] & 0x03) &&
|
|
375 |
aEpInfo.iInterval == epDescriptor[KEpDesc_IntervalOffset]);
|
253
|
376 |
|
0
|
377 |
// Change the endpoint poll interval
|
|
378 |
TUint8 ival = 0x66;
|
|
379 |
if (epDescriptor[KEpDesc_IntervalOffset] == ival)
|
|
380 |
ival++;
|
|
381 |
|
|
382 |
|
|
383 |
TUint8 saveAddr = 0; // save the address
|
|
384 |
if (aEpInfo.iExtra > 0)
|
|
385 |
{
|
|
386 |
saveAddr = epDescriptor[KEpDesc_SynchAddressOffset];
|
|
387 |
TUint8 addr = 0x85; // bogus address
|
|
388 |
if (epDescriptor[KEpDesc_SynchAddressOffset] == addr)
|
|
389 |
addr++;
|
|
390 |
epDescriptor[KEpDesc_SynchAddressOffset] = addr;
|
|
391 |
}
|
|
392 |
|
|
393 |
epDescriptor[KEpDesc_IntervalOffset] = ival;
|
|
394 |
r = aPort->SetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
|
|
395 |
test_KErrNone(r);
|
|
396 |
|
|
397 |
TBuf8<KUsbDescSize_AudioEndpoint> descriptor2;
|
|
398 |
r = aPort->GetEndpointDescriptor(aIfSetting, aEpNumber, descriptor2);
|
|
399 |
test_KErrNone(r);
|
|
400 |
|
|
401 |
r = descriptor2.Compare(epDescriptor);
|
|
402 |
test_KErrNone(r);
|
|
403 |
|
|
404 |
if (aEpInfo.iExtra > 0)
|
|
405 |
{
|
|
406 |
// Restore the endpoint synch address
|
|
407 |
epDescriptor[KEpDesc_SynchAddressOffset] = saveAddr;
|
|
408 |
}
|
|
409 |
|
|
410 |
// Restore the endpoint poll interval
|
|
411 |
epDescriptor[KEpDesc_IntervalOffset] = aEpInfo.iInterval;
|
|
412 |
r = aPort->SetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
|
|
413 |
test_KErrNone(r);
|
|
414 |
|
|
415 |
test.End();
|
|
416 |
}
|
|
417 |
|
|
418 |
static void TestStandardStringDescriptors(RDEVCLIENT* aPort)
|
|
419 |
{
|
|
420 |
test.Start(_L("String Descriptor Manipulation"));
|
|
421 |
|
|
422 |
//
|
|
423 |
// --- LANGID code
|
|
424 |
//
|
|
425 |
|
|
426 |
test.Next(_L("GetStringDescriptorLangId()"));
|
|
427 |
TUint16 rd_langid_orig;
|
|
428 |
TInt r = aPort->GetStringDescriptorLangId(rd_langid_orig);
|
|
429 |
test_KErrNone(r);
|
|
430 |
test.Printf(_L("Original LANGID code: 0x%04X\n"), rd_langid_orig);
|
253
|
431 |
OstTrace1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS, "Original LANGID code: 0x%04X\n", rd_langid_orig);
|
0
|
432 |
|
|
433 |
test.Next(_L("SetStringDescriptorLangId()"));
|
|
434 |
TUint16 wr_langid = 0x0809; // English (UK) Language ID
|
|
435 |
if (wr_langid == rd_langid_orig)
|
|
436 |
wr_langid = 0x0444; // Tatar Language ID
|
|
437 |
r = aPort->SetStringDescriptorLangId(wr_langid);
|
|
438 |
test_KErrNone(r);
|
|
439 |
|
|
440 |
test.Next(_L("GetStringDescriptorLangId()"));
|
|
441 |
TUint16 rd_langid;
|
|
442 |
r = aPort->GetStringDescriptorLangId(rd_langid);
|
|
443 |
test_KErrNone(r);
|
|
444 |
test.Printf(_L("New LANGID code: 0x%04X\n"), rd_langid);
|
253
|
445 |
OstTrace1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP01, "New LANGID code: 0x%04X\n", rd_langid);
|
0
|
446 |
|
|
447 |
test.Next(_L("Compare LANGID codes"));
|
|
448 |
test_Equal(wr_langid,rd_langid);
|
|
449 |
|
|
450 |
test.Next(_L("Restore original LANGID code"));
|
|
451 |
r = aPort->SetStringDescriptorLangId(rd_langid_orig);
|
|
452 |
test_KErrNone(r);
|
|
453 |
r = aPort->GetStringDescriptorLangId(rd_langid);
|
|
454 |
test_KErrNone(r);
|
|
455 |
test_Equal(rd_langid_orig,rd_langid);
|
|
456 |
|
|
457 |
//
|
|
458 |
// --- Manufacturer string
|
|
459 |
//
|
|
460 |
|
|
461 |
test.Next(_L("GetManufacturerStringDescriptor()"));
|
|
462 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str_orig;
|
|
463 |
r = aPort->GetManufacturerStringDescriptor(rd_str_orig);
|
|
464 |
test(r == KErrNone || r == KErrNotFound);
|
|
465 |
TBool restore_string;
|
|
466 |
if (r == KErrNone)
|
|
467 |
{
|
|
468 |
test.Printf(_L("Original Manufacturer string: \"%lS\"\n"), &rd_str_orig);
|
253
|
469 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP02, "Original Manufacturer string: \"%lS\"\n", rd_str_orig);
|
0
|
470 |
restore_string = ETrue;
|
|
471 |
}
|
|
472 |
else
|
|
473 |
{
|
|
474 |
test.Printf(_L("No Manufacturer string set\n"));
|
253
|
475 |
OstTrace0(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP03, "No Manufacturer string set\n");
|
0
|
476 |
restore_string = EFalse;
|
|
477 |
}
|
|
478 |
|
|
479 |
test.Next(_L("SetManufacturerStringDescriptor()"));
|
|
480 |
_LIT16(manufacturer, "Manufacturer Which Manufactures Devices");
|
|
481 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(manufacturer);
|
|
482 |
r = aPort->SetManufacturerStringDescriptor(wr_str);
|
|
483 |
test_KErrNone(r);
|
|
484 |
|
|
485 |
test.Next(_L("GetManufacturerStringDescriptor()"));
|
|
486 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
|
|
487 |
r = aPort->GetManufacturerStringDescriptor(rd_str);
|
|
488 |
test_KErrNone(r);
|
|
489 |
test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
|
253
|
490 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP04, "New Manufacturer string: \"%lS\"\n", rd_str);
|
0
|
491 |
|
|
492 |
test.Next(_L("Compare Manufacturer strings"));
|
|
493 |
r = rd_str.Compare(wr_str);
|
|
494 |
test_KErrNone(r);
|
|
495 |
|
|
496 |
test.Next(_L("SetManufacturerStringDescriptor()"));
|
|
497 |
_LIT16(manufacturer2, "Different Manufacturer Which Manufactures Different Devices");
|
|
498 |
wr_str.FillZ(wr_str.MaxLength());
|
|
499 |
wr_str = manufacturer2;
|
|
500 |
r = aPort->SetManufacturerStringDescriptor(wr_str);
|
|
501 |
test_KErrNone(r);
|
|
502 |
|
|
503 |
test.Next(_L("GetManufacturerStringDescriptor()"));
|
|
504 |
rd_str.FillZ(rd_str.MaxLength());
|
|
505 |
r = aPort->GetManufacturerStringDescriptor(rd_str);
|
|
506 |
test_KErrNone(r);
|
|
507 |
test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
|
253
|
508 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP05, "New Manufacturer string: \"%lS\"\n", rd_str);
|
0
|
509 |
|
|
510 |
test.Next(_L("Compare Manufacturer strings"));
|
|
511 |
r = rd_str.Compare(wr_str);
|
|
512 |
test_KErrNone(r);
|
|
513 |
|
|
514 |
test.Next(_L("RemoveManufacturerStringDescriptor()"));
|
|
515 |
r = aPort->RemoveManufacturerStringDescriptor();
|
|
516 |
test_KErrNone(r);
|
|
517 |
r = aPort->GetManufacturerStringDescriptor(rd_str);
|
|
518 |
test_Equal(KErrNotFound,r);
|
|
519 |
|
|
520 |
if (restore_string)
|
|
521 |
{
|
|
522 |
test.Next(_L("Restore original string"));
|
|
523 |
r = aPort->SetManufacturerStringDescriptor(rd_str_orig);
|
|
524 |
test_KErrNone(r);
|
|
525 |
r = aPort->GetManufacturerStringDescriptor(rd_str);
|
|
526 |
test_KErrNone(r);
|
|
527 |
r = rd_str.Compare(rd_str_orig);
|
|
528 |
test_KErrNone(r);
|
|
529 |
}
|
|
530 |
|
|
531 |
//
|
|
532 |
// --- Product string
|
|
533 |
//
|
|
534 |
|
|
535 |
test.Next(_L("GetProductStringDescriptor()"));
|
|
536 |
rd_str_orig.FillZ(rd_str.MaxLength());
|
|
537 |
r = aPort->GetProductStringDescriptor(rd_str_orig);
|
|
538 |
test(r == KErrNone || r == KErrNotFound);
|
|
539 |
if (r == KErrNone)
|
|
540 |
{
|
|
541 |
test.Printf(_L("Old Product string: \"%lS\"\n"), &rd_str_orig);
|
253
|
542 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP06, "Old Product string: \"%lS\"\n", rd_str_orig);
|
0
|
543 |
restore_string = ETrue;
|
|
544 |
}
|
|
545 |
else
|
|
546 |
restore_string = EFalse;
|
|
547 |
|
|
548 |
test.Next(_L("SetProductStringDescriptor()"));
|
|
549 |
_LIT16(product, "Product That Was Produced By A Manufacturer");
|
|
550 |
wr_str.FillZ(wr_str.MaxLength());
|
|
551 |
wr_str = product;
|
|
552 |
r = aPort->SetProductStringDescriptor(wr_str);
|
|
553 |
test_KErrNone(r);
|
|
554 |
|
|
555 |
test.Next(_L("GetProductStringDescriptor()"));
|
|
556 |
rd_str.FillZ(rd_str.MaxLength());
|
|
557 |
r = aPort->GetProductStringDescriptor(rd_str);
|
|
558 |
test_KErrNone(r);
|
|
559 |
test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
|
253
|
560 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP07, "New Product string: \"%lS\"\n", rd_str);
|
0
|
561 |
|
|
562 |
test.Next(_L("Compare Product strings"));
|
|
563 |
r = rd_str.Compare(wr_str);
|
|
564 |
test_KErrNone(r);
|
|
565 |
|
|
566 |
test.Next(_L("SetProductStringDescriptor()"));
|
|
567 |
_LIT16(product2, "Different Product That Was Produced By A Different Manufacturer");
|
|
568 |
wr_str.FillZ(wr_str.MaxLength());
|
|
569 |
wr_str = product2;
|
|
570 |
r = aPort->SetProductStringDescriptor(wr_str);
|
|
571 |
test_KErrNone(r);
|
|
572 |
|
|
573 |
test.Next(_L("GetProductStringDescriptor()"));
|
|
574 |
rd_str.FillZ(rd_str.MaxLength());
|
|
575 |
r = aPort->GetProductStringDescriptor(rd_str);
|
|
576 |
test_KErrNone(r);
|
|
577 |
test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
|
253
|
578 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP08, "New Product string: \"%lS\"\n", rd_str);
|
0
|
579 |
|
|
580 |
test.Next(_L("Compare Product strings"));
|
|
581 |
r = rd_str.Compare(wr_str);
|
|
582 |
test_KErrNone(r);
|
|
583 |
|
|
584 |
test.Next(_L("RemoveProductStringDescriptor()"));
|
|
585 |
r = aPort->RemoveProductStringDescriptor();
|
|
586 |
test_KErrNone(r);
|
|
587 |
r = aPort->GetProductStringDescriptor(rd_str);
|
|
588 |
test_Equal(KErrNotFound,r);
|
|
589 |
|
|
590 |
if (restore_string)
|
|
591 |
{
|
|
592 |
test.Next(_L("Restore original string"));
|
|
593 |
r = aPort->SetProductStringDescriptor(rd_str_orig);
|
|
594 |
test_KErrNone(r);
|
|
595 |
r = aPort->GetProductStringDescriptor(rd_str);
|
|
596 |
test_KErrNone(r);
|
|
597 |
r = rd_str.Compare(rd_str_orig);
|
|
598 |
test_KErrNone(r);
|
|
599 |
}
|
|
600 |
|
|
601 |
//
|
|
602 |
// --- Serial Number string
|
|
603 |
//
|
|
604 |
|
|
605 |
test.Next(_L("GetSerialNumberStringDescriptor()"));
|
|
606 |
rd_str_orig.FillZ(rd_str.MaxLength());
|
|
607 |
r = aPort->GetSerialNumberStringDescriptor(rd_str_orig);
|
|
608 |
test(r == KErrNone || r == KErrNotFound);
|
|
609 |
if (r == KErrNone)
|
|
610 |
{
|
|
611 |
test.Printf(_L("Old Serial Number: \"%lS\"\n"), &rd_str_orig);
|
253
|
612 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP09, "Old Serial Number: \"%lS\"\n", rd_str_orig);
|
0
|
613 |
restore_string = ETrue;
|
|
614 |
}
|
|
615 |
else
|
|
616 |
restore_string = EFalse;
|
|
617 |
|
|
618 |
test.Next(_L("SetSerialNumberStringDescriptor()"));
|
|
619 |
_LIT16(serial, "000666000XYZ");
|
|
620 |
wr_str.FillZ(wr_str.MaxLength());
|
|
621 |
wr_str = serial;
|
|
622 |
r = aPort->SetSerialNumberStringDescriptor(wr_str);
|
|
623 |
test_KErrNone(r);
|
|
624 |
|
|
625 |
test.Next(_L("GetSerialNumberStringDescriptor()"));
|
|
626 |
rd_str.FillZ(rd_str.MaxLength());
|
|
627 |
r = aPort->GetSerialNumberStringDescriptor(rd_str);
|
|
628 |
test_KErrNone(r);
|
|
629 |
test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
|
253
|
630 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP10, "New Serial Number: \"%lS\"\n", rd_str);
|
0
|
631 |
|
|
632 |
test.Next(_L("Compare Serial Number strings"));
|
|
633 |
r = rd_str.Compare(wr_str);
|
|
634 |
test_KErrNone(r);
|
|
635 |
|
|
636 |
test.Next(_L("SetSerialNumberStringDescriptor()"));
|
|
637 |
_LIT16(serial2, "Y11611193111711111Y");
|
|
638 |
wr_str.FillZ(wr_str.MaxLength());
|
|
639 |
wr_str = serial2;
|
|
640 |
r = aPort->SetSerialNumberStringDescriptor(wr_str);
|
|
641 |
test_KErrNone(r);
|
|
642 |
|
|
643 |
test.Next(_L("GetSerialNumberStringDescriptor()"));
|
|
644 |
rd_str.FillZ(rd_str.MaxLength());
|
|
645 |
r = aPort->GetSerialNumberStringDescriptor(rd_str);
|
|
646 |
test_KErrNone(r);
|
|
647 |
test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
|
253
|
648 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP11, "New Serial Number: \"%lS\"\n", rd_str);
|
0
|
649 |
|
|
650 |
test.Next(_L("Compare Serial Number strings"));
|
|
651 |
r = rd_str.Compare(wr_str);
|
|
652 |
test_KErrNone(r);
|
|
653 |
|
|
654 |
test.Next(_L("RemoveSerialNumberStringDescriptor()"));
|
|
655 |
r = aPort->RemoveSerialNumberStringDescriptor();
|
|
656 |
test_KErrNone(r);
|
|
657 |
r = aPort->GetSerialNumberStringDescriptor(rd_str);
|
|
658 |
test_Equal(KErrNotFound,r);
|
|
659 |
|
|
660 |
if (restore_string)
|
|
661 |
{
|
|
662 |
test.Next(_L("Restore original string"));
|
|
663 |
r = aPort->SetSerialNumberStringDescriptor(rd_str_orig);
|
|
664 |
test_KErrNone(r);
|
|
665 |
r = aPort->GetSerialNumberStringDescriptor(rd_str);
|
|
666 |
test_KErrNone(r);
|
|
667 |
r = rd_str.Compare(rd_str_orig);
|
|
668 |
test_KErrNone(r);
|
|
669 |
}
|
|
670 |
|
|
671 |
//
|
|
672 |
// --- Configuration string
|
|
673 |
//
|
|
674 |
|
|
675 |
test.Next(_L("GetConfigurationStringDescriptor()"));
|
|
676 |
rd_str_orig.FillZ(rd_str.MaxLength());
|
|
677 |
r = aPort->GetConfigurationStringDescriptor(rd_str_orig);
|
|
678 |
test(r == KErrNone || r == KErrNotFound);
|
|
679 |
if (r == KErrNone)
|
|
680 |
{
|
|
681 |
test.Printf(_L("Old Configuration string: \"%lS\"\n"), &rd_str_orig);
|
253
|
682 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP12, "Old Configuration string: \"%lS\"\n", rd_str_orig);
|
0
|
683 |
restore_string = ETrue;
|
|
684 |
}
|
|
685 |
else
|
|
686 |
restore_string = EFalse;
|
|
687 |
|
|
688 |
test.Next(_L("SetConfigurationStringDescriptor()"));
|
|
689 |
_LIT16(config, "Relatively Simple Configuration That Is Still Useful");
|
|
690 |
wr_str.FillZ(wr_str.MaxLength());
|
|
691 |
wr_str = config;
|
|
692 |
r = aPort->SetConfigurationStringDescriptor(wr_str);
|
|
693 |
test_KErrNone(r);
|
|
694 |
|
|
695 |
test.Next(_L("GetConfigurationStringDescriptor()"));
|
|
696 |
rd_str.FillZ(rd_str.MaxLength());
|
|
697 |
r = aPort->GetConfigurationStringDescriptor(rd_str);
|
|
698 |
test_KErrNone(r);
|
|
699 |
test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
|
253
|
700 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP13, "New Configuration string: \"%lS\"\n", rd_str);
|
0
|
701 |
|
|
702 |
test.Next(_L("Compare Configuration strings"));
|
|
703 |
r = rd_str.Compare(wr_str);
|
|
704 |
test_KErrNone(r);
|
|
705 |
|
|
706 |
test.Next(_L("SetConfigurationStringDescriptor()"));
|
|
707 |
_LIT16(config2, "Convenient Configuration That Can Be Very Confusing");
|
|
708 |
wr_str.FillZ(wr_str.MaxLength());
|
|
709 |
wr_str = config2;
|
|
710 |
r = aPort->SetConfigurationStringDescriptor(wr_str);
|
|
711 |
test_KErrNone(r);
|
|
712 |
|
|
713 |
test.Next(_L("GetConfigurationStringDescriptor()"));
|
|
714 |
rd_str.FillZ(rd_str.MaxLength());
|
|
715 |
r = aPort->GetConfigurationStringDescriptor(rd_str);
|
|
716 |
test_KErrNone(r);
|
|
717 |
test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
|
253
|
718 |
OstTraceExt1(TRACE_NORMAL, TESTSTANDARDSTRINGDESCRIPTORS_TESTSTANDARDSTRINGDESCRIPTORS_DUP14, "New Configuration string: \"%lS\"\n", rd_str);
|
0
|
719 |
|
|
720 |
test.Next(_L("Compare Configuration strings"));
|
|
721 |
r = rd_str.Compare(wr_str);
|
|
722 |
test_KErrNone(r);
|
|
723 |
|
|
724 |
test.Next(_L("RemoveConfigurationStringDescriptor()"));
|
|
725 |
r = aPort->RemoveConfigurationStringDescriptor();
|
|
726 |
test_KErrNone(r);
|
|
727 |
r = aPort->GetConfigurationStringDescriptor(rd_str);
|
|
728 |
test_Equal(KErrNotFound,r);
|
|
729 |
|
|
730 |
if (restore_string)
|
|
731 |
{
|
|
732 |
test.Next(_L("Restore original string"));
|
|
733 |
r = aPort->SetConfigurationStringDescriptor(rd_str_orig);
|
|
734 |
test_KErrNone(r);
|
|
735 |
r = aPort->GetConfigurationStringDescriptor(rd_str);
|
|
736 |
test_KErrNone(r);
|
|
737 |
r = rd_str.Compare(rd_str_orig);
|
|
738 |
test_KErrNone(r);
|
|
739 |
}
|
|
740 |
|
|
741 |
test.End();
|
|
742 |
}
|
|
743 |
|
|
744 |
|
|
745 |
static void TestArbitraryStringDescriptors(RDEVCLIENT* aPort,TInt aNumSettings)
|
|
746 |
{
|
|
747 |
test.Start(_L("Arbitrary String Descriptor Manipulation"));
|
|
748 |
|
|
749 |
// First test string
|
|
750 |
|
|
751 |
test.Next(_L("GetStringDescriptor() 1"));
|
|
752 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
|
|
753 |
TInt r = aPort->GetStringDescriptor(stridx1, rd_str);
|
|
754 |
test_KErrNone(r);
|
|
755 |
|
|
756 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(KString_one);
|
|
757 |
r = rd_str.Compare(wr_str);
|
|
758 |
test_KErrNone(r);
|
|
759 |
|
|
760 |
// Second test string
|
|
761 |
|
|
762 |
test.Next(_L("GetStringDescriptor() 2"));
|
|
763 |
rd_str.FillZ(rd_str.MaxLength());
|
|
764 |
r = aPort->GetStringDescriptor(stridx2, rd_str);
|
|
765 |
test_KErrNone(r);
|
|
766 |
|
|
767 |
wr_str = KString_two;
|
|
768 |
r = rd_str.Compare(wr_str);
|
|
769 |
test_KErrNone(r);
|
|
770 |
|
|
771 |
// Third test string
|
|
772 |
|
|
773 |
test.Next(_L("GetStringDescriptor() 3"));
|
|
774 |
rd_str.FillZ(rd_str.MaxLength());
|
|
775 |
r = aPort->GetStringDescriptor(stridx3, rd_str);
|
|
776 |
test_Equal(KErrNotFound,r);
|
|
777 |
|
|
778 |
test.Next(_L("SetStringDescriptor() 3"));
|
|
779 |
_LIT16(string_three, "Arbitrary String Descriptor Test String 3");
|
|
780 |
wr_str.FillZ(wr_str.MaxLength());
|
|
781 |
wr_str = string_three;
|
|
782 |
r = aPort->SetStringDescriptor(stridx3, wr_str);
|
|
783 |
test_KErrNone(r);
|
|
784 |
|
|
785 |
// In between we create another interface setting to see what happens
|
|
786 |
// to the existing string descriptor indices.
|
|
787 |
// (We don't have to test this on every platform -
|
|
788 |
// besides, those that don't support alt settings
|
|
789 |
// are by now very rare.)
|
|
790 |
if (SupportsAlternateInterfaces())
|
|
791 |
{
|
|
792 |
#ifdef USB_SC
|
|
793 |
TUsbcScInterfaceInfoBuf ifc;
|
|
794 |
#else
|
|
795 |
TUsbcInterfaceInfoBuf ifc;
|
|
796 |
#endif
|
|
797 |
_LIT16(string, "T_USB_DEVICE Bogus Test Interface (Next Setting)");
|
|
798 |
ifc().iString = const_cast<TDesC16*>(&string);
|
|
799 |
ifc().iTotalEndpointsUsed = 0;
|
|
800 |
TInt r = aPort->SetInterface(aNumSettings, ifc);
|
|
801 |
test_KErrNone(r);
|
|
802 |
}
|
|
803 |
|
|
804 |
test.Next(_L("GetStringDescriptor() 3"));
|
|
805 |
r = aPort->GetStringDescriptor(stridx3, rd_str);
|
|
806 |
test_KErrNone(r);
|
|
807 |
test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx3, &rd_str);
|
253
|
808 |
OstTraceExt2(TRACE_NORMAL, TESTARBITRARYSTRINGDESCRIPTORS_TESTARBITRARYSTRINGDESCRIPTORS, "New test string @ idx %d: \"%lS\"\n", stridx3, rd_str);
|
0
|
809 |
|
|
810 |
test.Next(_L("Compare test strings 3"));
|
|
811 |
r = rd_str.Compare(wr_str);
|
|
812 |
test_KErrNone(r);
|
|
813 |
|
|
814 |
// Remove string descriptors 3 and 4
|
|
815 |
|
|
816 |
test.Next(_L("RemoveStringDescriptor() 4"));
|
|
817 |
r = aPort->RemoveStringDescriptor(stridx4);
|
|
818 |
test_Equal(KErrNotFound,r);
|
|
819 |
|
|
820 |
test.Next(_L("RemoveStringDescriptor() 3"));
|
|
821 |
r = aPort->RemoveStringDescriptor(stridx3);
|
|
822 |
test_KErrNone(r);
|
|
823 |
|
|
824 |
r = aPort->GetStringDescriptor(stridx3, rd_str);
|
|
825 |
test_Equal(KErrNotFound,r);
|
|
826 |
|
|
827 |
if (SupportsAlternateInterfaces())
|
|
828 |
{
|
|
829 |
TInt r = aPort->ReleaseInterface(aNumSettings);
|
|
830 |
test_KErrNone(r);
|
|
831 |
}
|
|
832 |
|
|
833 |
test.End();
|
|
834 |
}
|
|
835 |
|
|
836 |
void TestInvalidSetInterface (RDEVCLIENT* aPort,TInt aNumSettings)
|
|
837 |
{
|
|
838 |
#ifdef USB_SC
|
|
839 |
TUsbcScInterfaceInfoBuf ifc;
|
|
840 |
#else
|
|
841 |
TUsbcInterfaceInfoBuf ifc;
|
|
842 |
#endif
|
|
843 |
_LIT16(string, "T_USB_DEVICE Invalid Interface");
|
|
844 |
ifc().iString = const_cast<TDesC16*>(&string);
|
|
845 |
ifc().iTotalEndpointsUsed = 0;
|
|
846 |
|
|
847 |
test.Start(_L("Test Invalid Interface Setting"));
|
|
848 |
|
|
849 |
if (SupportsAlternateInterfaces())
|
|
850 |
{
|
|
851 |
TInt r = aPort->SetInterface(aNumSettings+1, ifc);
|
253
|
852 |
test_Compare(r,!=,KErrNone);
|
0
|
853 |
}
|
253
|
854 |
|
0
|
855 |
if (aNumSettings > 1)
|
|
856 |
{
|
|
857 |
TInt r = aPort->SetInterface(aNumSettings-1, ifc);
|
253
|
858 |
test_Compare(r,!=,KErrNone);
|
0
|
859 |
}
|
|
860 |
|
|
861 |
TInt r = aPort->SetInterface(0, ifc);
|
253
|
862 |
test_Compare(r,!=,KErrNone);
|
0
|
863 |
|
|
864 |
test.End();
|
|
865 |
}
|
|
866 |
|
|
867 |
void TestInvalidReleaseInterface (RDEVCLIENT* aPort,TInt aNumSettings)
|
|
868 |
{
|
|
869 |
test.Start(_L("Test Invalid Interface Release"));
|
|
870 |
|
|
871 |
if (aNumSettings > 2)
|
|
872 |
{
|
|
873 |
TInt r = aPort->ReleaseInterface(aNumSettings-3);
|
253
|
874 |
test_Compare(r,!=,KErrNone);
|
0
|
875 |
}
|
|
876 |
|
|
877 |
if (aNumSettings > 1)
|
|
878 |
{
|
|
879 |
TInt r = aPort->ReleaseInterface(aNumSettings-2);
|
253
|
880 |
test_Compare(r,!=,KErrNone);
|
0
|
881 |
}
|
|
882 |
|
|
883 |
test.End();
|
|
884 |
}
|
|
885 |
|
|
886 |
void TestDescriptorManipulation(TBool aHighSpeed, RDEVCLIENT* aPort, TInt aNumSettings)
|
|
887 |
{
|
|
888 |
test.Start(_L("Test USB Descriptor Manipulation"));
|
|
889 |
|
|
890 |
if (aHighSpeed)
|
|
891 |
{
|
|
892 |
TestDeviceQualifierDescriptor(aPort);
|
|
893 |
|
253
|
894 |
TestOtherSpeedConfigurationDescriptor(aPort);
|
0
|
895 |
}
|
|
896 |
|
|
897 |
TestInterfaceDescriptor(aPort,aNumSettings);
|
|
898 |
|
|
899 |
TestClassSpecificDescriptors(aPort);
|
|
900 |
|
|
901 |
TestStandardStringDescriptors(aPort);
|
|
902 |
|
|
903 |
TestArbitraryStringDescriptors(aPort,aNumSettings);
|
253
|
904 |
test.Next(_L("Test USB Descriptor Manipulation1"));
|
0
|
905 |
|
|
906 |
test.End();
|
|
907 |
}
|
|
908 |
|
|
909 |
|
|
910 |
void TestOtgExtensions(RDEVCLIENT* aPort)
|
|
911 |
{
|
|
912 |
test.Start(_L("Test Some OTG API Extensions"));
|
|
913 |
|
|
914 |
// Test OTG descriptor manipulation
|
|
915 |
test.Next(_L("Get OTG Descriptor Size"));
|
|
916 |
TInt size;
|
|
917 |
aPort->GetOtgDescriptorSize(size);
|
|
918 |
test_Equal(KUsbDescSize_Otg,static_cast<TUint>(size));
|
|
919 |
|
|
920 |
test.Next(_L("Get OTG Descriptor"));
|
|
921 |
TBuf8<KUsbDescSize_Otg> otgDesc;
|
|
922 |
TInt r = aPort->GetOtgDescriptor(otgDesc);
|
|
923 |
test(r == KErrNotSupported || r == KErrNone);
|
|
924 |
|
|
925 |
test.Next(_L("Set OTG Descriptor"));
|
|
926 |
TBool supportOtg = EFalse;
|
|
927 |
if (r == KErrNotSupported)
|
|
928 |
{
|
|
929 |
r = aPort->SetOtgDescriptor(otgDesc);
|
|
930 |
test_Equal(KErrNotSupported,r);
|
|
931 |
}
|
|
932 |
else
|
|
933 |
{
|
|
934 |
supportOtg = ETrue;
|
|
935 |
otgDesc[0] = KUsbDescSize_Otg;
|
|
936 |
otgDesc[1] = KUsbDescType_Otg;
|
|
937 |
otgDesc[2] = KUsbOtgAttr_SrpSupp;
|
|
938 |
r = aPort->SetOtgDescriptor(otgDesc);
|
|
939 |
test_KErrNone(r);
|
|
940 |
TBuf8<KUsbDescSize_Otg> desc;
|
|
941 |
r = aPort->GetOtgDescriptor(desc);
|
|
942 |
test_KErrNone(r);
|
|
943 |
test_Equal(0,desc.Compare(otgDesc));
|
|
944 |
}
|
|
945 |
|
|
946 |
// Test get/set OTG feature
|
|
947 |
test.Next(_L("Get OTG Features"));
|
|
948 |
TUint8 features;
|
|
949 |
r = aPort->GetOtgFeatures(features);
|
|
950 |
if (supportOtg)
|
|
951 |
{
|
|
952 |
test_KErrNone(r);
|
|
953 |
TBool b_HnpEnable = (features & KUsbOtgAttr_B_HnpEnable) ? ETrue : EFalse;
|
|
954 |
TBool a_HnpSupport = (features & KUsbOtgAttr_A_HnpSupport) ? ETrue : EFalse;
|
|
955 |
TBool a_AltHnpSupport = (features & KUsbOtgAttr_A_AltHnpSupport) ? ETrue : EFalse;
|
|
956 |
test.Printf(_L("### OTG Features:\nB_HnpEnable(%d)\nA_HnpSupport(%d)\nA_Alt_HnpSupport(%d)\n"),
|
|
957 |
b_HnpEnable, a_HnpSupport, a_AltHnpSupport);
|
253
|
958 |
OstTraceExt3(TRACE_NORMAL, TESTOTGEXTENSIONS_TESTOTGEXTENSIONS, "### OTG Features:\nB_HnpEnable(%d)\nA_HnpSupport(%d)\nA_Alt_HnpSupport(%d)\n",
|
|
959 |
b_HnpEnable, a_HnpSupport, a_AltHnpSupport);
|
0
|
960 |
}
|
|
961 |
else
|
|
962 |
{
|
|
963 |
test_Equal(KErrNotSupported,r);
|
|
964 |
test.Printf(_L("GetOtgFeatures() not supported\n"));
|
253
|
965 |
OstTrace0(TRACE_NORMAL, TESTOTGEXTENSIONS_TESTOTGEXTENSIONS_DUP01, "GetOtgFeatures(not supported\n");
|
0
|
966 |
}
|
|
967 |
|
|
968 |
test.End();
|
|
969 |
}
|
|
970 |
|
|
971 |
|
|
972 |
void TestEndpoint0MaxPacketSizes(RDEVCLIENT* aPort)
|
|
973 |
{
|
|
974 |
test.Start(_L("Test Endpoint0 MaxPacketSizes"));
|
|
975 |
|
|
976 |
TUint32 sizes = aPort->EndpointZeroMaxPacketSizes();
|
|
977 |
TInt r = KErrNone;
|
|
978 |
TBool good;
|
|
979 |
TInt mpsize = 0;
|
|
980 |
for (TInt i = 0; i < 32; i++)
|
|
981 |
{
|
|
982 |
TUint bit = sizes & (1 << i);
|
|
983 |
if (bit != 0)
|
|
984 |
{
|
|
985 |
switch (bit)
|
|
986 |
{
|
|
987 |
case KUsbEpSizeCont:
|
|
988 |
good = EFalse;
|
|
989 |
break;
|
|
990 |
case KUsbEpSize8:
|
|
991 |
mpsize = 8;
|
|
992 |
good = ETrue;
|
|
993 |
break;
|
|
994 |
case KUsbEpSize16:
|
|
995 |
mpsize = 16;
|
|
996 |
good = ETrue;
|
|
997 |
break;
|
|
998 |
case KUsbEpSize32:
|
|
999 |
mpsize = 32;
|
|
1000 |
good = ETrue;
|
|
1001 |
break;
|
|
1002 |
case KUsbEpSize64:
|
|
1003 |
mpsize = 64;
|
|
1004 |
good = ETrue;
|
|
1005 |
break;
|
|
1006 |
case KUsbEpSize128:
|
|
1007 |
case KUsbEpSize256:
|
|
1008 |
case KUsbEpSize512:
|
|
1009 |
case KUsbEpSize1023:
|
|
1010 |
default:
|
|
1011 |
good = EFalse;
|
|
1012 |
break;
|
|
1013 |
}
|
|
1014 |
if (good)
|
|
1015 |
{
|
|
1016 |
test.Printf(_L("Ep0 supports %d bytes MaxPacketSize\n"), mpsize);
|
253
|
1017 |
OstTrace1(TRACE_NORMAL, TESTENDPOINT0MAXPACKETSIZES_TESTENDPOINT0MAXPACKETSIZES, "Ep0 supports %d bytes MaxPacketSize\n", mpsize);
|
0
|
1018 |
}
|
|
1019 |
else
|
|
1020 |
{
|
|
1021 |
test.Printf(_L("Bad Ep0 size: 0x%08x, failure will occur\n"), bit);
|
253
|
1022 |
OstTrace1(TRACE_NORMAL, TESTENDPOINT0MAXPACKETSIZES_TESTENDPOINT0MAXPACKETSIZES_DUP01, "Bad Ep0 size: 0x%08x, failure will occur\n", bit);
|
0
|
1023 |
r = KErrGeneral;
|
|
1024 |
}
|
|
1025 |
}
|
|
1026 |
}
|
|
1027 |
test_KErrNone(r);
|
|
1028 |
|
|
1029 |
test.End();
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
|