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