Update contrib.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
20 #include "general.h" // CActiveControl, CActiveRW
22 #include "usblib.h" // Helpers
25 extern TBool gVerbose;
27 extern TBool gTempTest;
29 _LIT16(KString_one, "Arbitrary String Descriptor Test String 1");
30 _LIT16(KString_two, "Another Arbitrary String Descriptor Test String");
32 void SetupDescriptors(LDDConfigPtr aLddPtr,RDEVCLIENT* aPort, TUint16 aPid = 0)
34 // === Device Descriptor
35 test.Start(_L("Set up descriptors"));
37 test.Next(_L("GetDeviceDescriptorSize"));
38 TInt deviceDescriptorSize = 0;
39 aPort->GetDeviceDescriptorSize(deviceDescriptorSize);
40 test_Equal(KUsbDescSize_Device,static_cast<TUint>(deviceDescriptorSize));
42 test.Next(_L("GetDeviceDescriptor"));
43 TBuf8<KUsbDescSize_Device> deviceDescriptor;
44 TInt r = aPort->GetDeviceDescriptor(deviceDescriptor);
47 test.Next(_L("SetDeviceDescriptor"));
48 const TInt KUsbSpecOffset = 2;
49 const TInt KUsbDevClass = 4;
50 const TInt KUsbDevSubClass = 5;
51 const TInt KUsbDevProtocol = 6;
52 const TInt KUsbVendorIdOffset = 8;
53 const TInt KUsbProductIdOffset = 10;
54 const TInt KUsbDevReleaseOffset = 12;
55 // Change the USB spec number
56 deviceDescriptor[KUsbSpecOffset] = LoByte(aLddPtr->iSpec);
57 deviceDescriptor[KUsbSpecOffset+1] = HiByte(aLddPtr->iSpec);
58 // Change the Device Class, SubClass and Protocol to zero so that they are not device specific
59 // and diferent clases can used on different interfaces
60 deviceDescriptor[KUsbDevClass] = 0;
61 deviceDescriptor[KUsbDevSubClass] = 0;
62 deviceDescriptor[KUsbDevProtocol] = 0;
63 // Change the device vendor ID (VID)
64 deviceDescriptor[KUsbVendorIdOffset] = LoByte(aLddPtr->iVid); // little endian!
65 deviceDescriptor[KUsbVendorIdOffset+1] = HiByte(aLddPtr->iVid);
66 // Change the device product ID (PID)
69 deviceDescriptor[KUsbProductIdOffset] = LoByte(aPid); // little endian!
70 deviceDescriptor[KUsbProductIdOffset+1] = HiByte(aPid);
74 deviceDescriptor[KUsbProductIdOffset] = LoByte(aLddPtr->iPid); // little endian!
75 deviceDescriptor[KUsbProductIdOffset+1] = HiByte(aLddPtr->iPid);
77 // Change the device release number
78 deviceDescriptor[KUsbDevReleaseOffset] = LoByte(aLddPtr->iRelease); // little endian!
79 deviceDescriptor[KUsbDevReleaseOffset+1] = HiByte(aLddPtr->iRelease);
80 r = aPort->SetDeviceDescriptor(deviceDescriptor);
85 test.Next(_L("GetDeviceDescriptor()"));
86 TBuf8<KUsbDescSize_Device> descriptor2;
87 r = aPort->GetDeviceDescriptor(descriptor2);
90 test.Next(_L("Compare device descriptor with value set"));
91 r = descriptor2.Compare(deviceDescriptor);
95 // === Configuration Descriptor
97 test.Next(_L("GetConfigurationDescriptorSize"));
98 TInt configDescriptorSize = 0;
99 aPort->GetConfigurationDescriptorSize(configDescriptorSize);
100 test_Equal(KUsbDescSize_Config,static_cast<TUint>(configDescriptorSize));
102 test.Next(_L("GetConfigurationDescriptor"));
103 TBuf8<KUsbDescSize_Config> configDescriptor;
104 r = aPort->GetConfigurationDescriptor(configDescriptor);
107 test.Next(_L("SetConfigurationDescriptor"));
108 // Change Self Power and Remote Wakeup
109 const TInt KUsbAttributesOffset = 7;
110 const TUint8 KUsbAttributeDefault = 0x80;
111 const TUint8 KUsbAttributeSelfPower = 0x40;
112 const TUint8 KUsbAttributeRemoteWakeup = 0x20;
113 configDescriptor[KUsbAttributesOffset] = KUsbAttributeDefault | (aLddPtr->iSelfPower ? KUsbAttributeSelfPower : 0)
114 | (aLddPtr->iRemoteWakeup ? KUsbAttributeRemoteWakeup : 0);
115 // Change the reported max power
116 // 100mA (= 2 * 0x32) is the highest value allowed for a bus-powered device.
117 const TInt KUsbMaxPowerOffset = 8;
118 configDescriptor[KUsbMaxPowerOffset] = aLddPtr->iMaxPower;
119 r = aPort->SetConfigurationDescriptor(configDescriptor);
124 test.Next(_L("GetConfigurationDescriptor()"));
125 TBuf8<KUsbDescSize_Config> descriptor2;
126 r = aPort->GetConfigurationDescriptor(descriptor2);
129 test.Next(_L("Compare configuration desc with value set"));
130 r = descriptor2.Compare(configDescriptor);
134 // === String Descriptors
136 test.Next(_L("SetStringDescriptor"));
138 // Set up any standard string descriptors that were defined in the xml config
139 if (aLddPtr->iManufacturer)
141 r = aPort->SetManufacturerStringDescriptor(* aLddPtr->iManufacturer);
145 if (aLddPtr->iProduct)
147 r = aPort->SetProductStringDescriptor(* aLddPtr->iProduct);
151 if (aLddPtr->iSerialNumber)
153 r = aPort->SetSerialNumberStringDescriptor(* aLddPtr->iSerialNumber);
157 // Set up two arbitrary string descriptors, which can be queried
158 // manually from the host side for testing purposes
160 TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(KString_one);
161 r = aPort->SetStringDescriptor(stridx1, wr_str);
164 wr_str.FillZ(wr_str.MaxLength());
165 wr_str = KString_two;
166 r = aPort->SetStringDescriptor(stridx2, wr_str);
173 static void TestDeviceQualifierDescriptor(RDEVCLIENT* aPort)
175 test.Start(_L("Device_Qualifier Descriptor Manipulation"));
177 test.Next(_L("GetDeviceQualifierDescriptor()"));
178 TBuf8<KUsbDescSize_DeviceQualifier> descriptor;
179 TInt r = aPort->GetDeviceQualifierDescriptor(descriptor);
182 test.Next(_L("SetDeviceQualifierDescriptor()"));
183 // Change the USB spec number to 3.00
184 descriptor[KDevDesc_SpecOffset] = 0x00;
185 descriptor[KDevDesc_SpecOffset+1] = 0x03;
186 // Change the device class, subclass and protocol codes
187 descriptor[KDevDesc_DevClassOffset] = 0xA1;
188 descriptor[KDevDesc_DevSubClassOffset] = 0xB2;
189 descriptor[KDevDesc_DevProtocolOffset] = 0xC3;
190 r = aPort->SetDeviceQualifierDescriptor(descriptor);
193 test.Next(_L("GetDeviceQualifierDescriptor()"));
194 TBuf8<KUsbDescSize_DeviceQualifier> descriptor2;
195 r = aPort->GetDeviceQualifierDescriptor(descriptor2);
198 test.Next(_L("Compare Device_Qualifier desc with value set"));
199 r = descriptor2.Compare(descriptor);
207 static void TestOtherSpeedConfigurationDescriptor(RDEVCLIENT* aPort)
209 test.Start(_L("Other_Speed_Configuration Desc Manipulation"));
211 test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
212 TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor;
213 TInt r = aPort->GetOtherSpeedConfigurationDescriptor(descriptor);
216 test.Next(_L("SetOtherSpeedConfigurationDescriptor()"));
217 // Invert Remote-Wakup support
218 descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup);
219 // Change the reported max power to 330mA (2 * 0xA5)
220 descriptor[KConfDesc_MaxPowerOffset] = 0xA5;
221 r = aPort->SetOtherSpeedConfigurationDescriptor(descriptor);
224 test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
225 TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor2;
226 r = aPort->GetOtherSpeedConfigurationDescriptor(descriptor2);
229 test.Next(_L("Compare O_S_Config desc with value set"));
230 r = descriptor2.Compare(descriptor);
237 static void TestInterfaceDescriptor(RDEVCLIENT* aPort, TInt aNumSettings)
239 test.Start(_L("Interface Descriptor Manipulation"));
245 TBuf8<KUsbDescSize_Interface> descriptor;
246 TBuf8<KUsbDescSize_Interface> descriptor2;
247 for (TInt i =0; i < aNumSettings; i++)
250 test.Next(_L("GetInterfaceDescriptorSize()"));
251 r = aPort->GetInterfaceDescriptorSize(i, desc_size);
254 RDebug::Printf ("Error %d in GetInterfaceDescriptorSize %d\n",r,i);
257 test_Equal(KUsbDescSize_Interface,static_cast<TUint>(desc_size));
259 test.Next(_L("GetInterfaceDescriptor()"));
260 r = aPort->GetInterfaceDescriptor(i, descriptor);
263 test.Next(_L("SetInterfaceDescriptor()"));
264 // Change the interface protocol to 0x78(+)
266 if (descriptor[KIfcDesc_ProtocolOffset] == prot)
268 descriptor[KIfcDesc_ProtocolOffset] = prot;
269 r = aPort->SetInterfaceDescriptor(i, descriptor);
272 test.Next(_L("GetInterfaceDescriptor()"));
273 r = aPort->GetInterfaceDescriptor(i, descriptor2);
276 test.Next(_L("Compare interface descriptor with value set"));
277 r = descriptor2.Compare(descriptor);
281 test.Next(_L("GetInterfaceDescriptor()"));
282 r = aPort->GetInterfaceDescriptor(aNumSettings, descriptor);
283 test_Equal(KErrNotFound,r);
285 test.Next(_L("SetInterfaceDescriptor()"));
286 r = aPort->SetInterfaceDescriptor(aNumSettings, descriptor);
287 test_Equal(KErrNotFound,r);
293 static void TestClassSpecificDescriptors(RDEVCLIENT* aPort)
295 test.Start(_L("Class-specific Descriptor Manipulation"));
297 // First a class-specific Interface descriptor
299 test.Next(_L("SetCSInterfaceDescriptorBlock()"));
300 // choose arbitrary new descriptor size
301 const TInt KUsbDescSize_CS_Interface = KUsbDescSize_Interface + 10;
302 TBuf8<KUsbDescSize_CS_Interface> cs_ifc_descriptor;
303 cs_ifc_descriptor.FillZ(cs_ifc_descriptor.MaxLength());
304 cs_ifc_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Interface;
305 cs_ifc_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Interface;
306 TInt r = aPort->SetCSInterfaceDescriptorBlock(0, cs_ifc_descriptor);
309 test.Next(_L("GetCSInterfaceDescriptorBlockSize()"));
311 r = aPort->GetCSInterfaceDescriptorBlockSize(0, desc_size);
313 test_Equal(KUsbDescSize_CS_Interface,desc_size);
315 test.Next(_L("GetCSInterfaceDescriptorBlock()"));
316 TBuf8<KUsbDescSize_CS_Interface> descriptor;
317 r = aPort->GetCSInterfaceDescriptorBlock(0, descriptor);
320 test.Next(_L("Compare CS ifc descriptor with value set"));
321 r = descriptor.Compare(cs_ifc_descriptor);
324 // Next a class-specific Endpoint descriptor
326 test.Next(_L("SetCSEndpointDescriptorBlock()"));
327 // choose arbitrary new descriptor size
328 const TInt KUsbDescSize_CS_Endpoint = KUsbDescSize_Endpoint + 5;
329 TBuf8<KUsbDescSize_CS_Endpoint> cs_ep_descriptor;
330 cs_ep_descriptor.FillZ(cs_ep_descriptor.MaxLength());
331 cs_ep_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Endpoint;
332 cs_ep_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Endpoint;
333 r = aPort->SetCSEndpointDescriptorBlock(0, 2, cs_ep_descriptor);
336 test.Next(_L("GetCSEndpointDescriptorBlockSize()"));
337 r = aPort->GetCSEndpointDescriptorBlockSize(0, 2, desc_size);
339 test_Equal(KUsbDescSize_CS_Endpoint,desc_size);
341 test.Next(_L("GetCSEndpointDescriptorBlock()"));
342 TBuf8<KUsbDescSize_CS_Endpoint> descriptor2;
343 r = aPort->GetCSEndpointDescriptorBlock(0, 2, descriptor2);
346 test.Next(_L("Compare CS ep descriptor with value set"));
347 r = descriptor2.Compare(cs_ep_descriptor);
354 void TestEndpointDescriptor(RDEVCLIENT* aPort,TInt aIfSetting, TInt aEpNumber,TUsbcEndpointInfo aEpInfo)
356 test.Start(_L("Endpoint Descriptor Manipulation"));
358 TBuf8<KUsbDescSize_AudioEndpoint> epDescriptor;
360 TInt r = aPort->GetEndpointDescriptorSize(aIfSetting, aEpNumber, desc_size);
362 test_Equal(KUsbDescSize_Endpoint + aEpInfo.iExtra,static_cast<TUint>(desc_size));
364 r = aPort->GetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
367 test(((aEpInfo.iDir & KUsbEpDirIn) && (epDescriptor[KEpDesc_AddressOffset] & 0x80) ||
368 !(aEpInfo.iDir & KUsbEpDirIn) && !(epDescriptor[KEpDesc_AddressOffset] & 0x80)) &&
369 EpTypeMask2Value(aEpInfo.iType) == (TUint)(epDescriptor[KEpDesc_AttributesOffset] & 0x03) &&
370 aEpInfo.iInterval == epDescriptor[KEpDesc_IntervalOffset]);
372 // Change the endpoint poll interval
374 if (epDescriptor[KEpDesc_IntervalOffset] == ival)
378 TUint8 saveAddr = 0; // save the address
379 if (aEpInfo.iExtra > 0)
381 saveAddr = epDescriptor[KEpDesc_SynchAddressOffset];
382 TUint8 addr = 0x85; // bogus address
383 if (epDescriptor[KEpDesc_SynchAddressOffset] == addr)
385 epDescriptor[KEpDesc_SynchAddressOffset] = addr;
388 epDescriptor[KEpDesc_IntervalOffset] = ival;
389 r = aPort->SetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
392 TBuf8<KUsbDescSize_AudioEndpoint> descriptor2;
393 r = aPort->GetEndpointDescriptor(aIfSetting, aEpNumber, descriptor2);
396 r = descriptor2.Compare(epDescriptor);
399 if (aEpInfo.iExtra > 0)
401 // Restore the endpoint synch address
402 epDescriptor[KEpDesc_SynchAddressOffset] = saveAddr;
405 // Restore the endpoint poll interval
406 epDescriptor[KEpDesc_IntervalOffset] = aEpInfo.iInterval;
407 r = aPort->SetEndpointDescriptor(aIfSetting, aEpNumber, epDescriptor);
413 static void TestStandardStringDescriptors(RDEVCLIENT* aPort)
415 test.Start(_L("String Descriptor Manipulation"));
421 test.Next(_L("GetStringDescriptorLangId()"));
422 TUint16 rd_langid_orig;
423 TInt r = aPort->GetStringDescriptorLangId(rd_langid_orig);
425 test.Printf(_L("Original LANGID code: 0x%04X\n"), rd_langid_orig);
427 test.Next(_L("SetStringDescriptorLangId()"));
428 TUint16 wr_langid = 0x0809; // English (UK) Language ID
429 if (wr_langid == rd_langid_orig)
430 wr_langid = 0x0444; // Tatar Language ID
431 r = aPort->SetStringDescriptorLangId(wr_langid);
434 test.Next(_L("GetStringDescriptorLangId()"));
436 r = aPort->GetStringDescriptorLangId(rd_langid);
438 test.Printf(_L("New LANGID code: 0x%04X\n"), rd_langid);
440 test.Next(_L("Compare LANGID codes"));
441 test_Equal(wr_langid,rd_langid);
443 test.Next(_L("Restore original LANGID code"));
444 r = aPort->SetStringDescriptorLangId(rd_langid_orig);
446 r = aPort->GetStringDescriptorLangId(rd_langid);
448 test_Equal(rd_langid_orig,rd_langid);
451 // --- Manufacturer string
454 test.Next(_L("GetManufacturerStringDescriptor()"));
455 TBuf16<KUsbStringDescStringMaxSize / 2> rd_str_orig;
456 r = aPort->GetManufacturerStringDescriptor(rd_str_orig);
457 test(r == KErrNone || r == KErrNotFound);
458 TBool restore_string;
461 test.Printf(_L("Original Manufacturer string: \"%lS\"\n"), &rd_str_orig);
462 restore_string = ETrue;
466 test.Printf(_L("No Manufacturer string set\n"));
467 restore_string = EFalse;
470 test.Next(_L("SetManufacturerStringDescriptor()"));
471 _LIT16(manufacturer, "Manufacturer Which Manufactures Devices");
472 TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(manufacturer);
473 r = aPort->SetManufacturerStringDescriptor(wr_str);
476 test.Next(_L("GetManufacturerStringDescriptor()"));
477 TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
478 r = aPort->GetManufacturerStringDescriptor(rd_str);
480 test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
482 test.Next(_L("Compare Manufacturer strings"));
483 r = rd_str.Compare(wr_str);
486 test.Next(_L("SetManufacturerStringDescriptor()"));
487 _LIT16(manufacturer2, "Different Manufacturer Which Manufactures Different Devices");
488 wr_str.FillZ(wr_str.MaxLength());
489 wr_str = manufacturer2;
490 r = aPort->SetManufacturerStringDescriptor(wr_str);
493 test.Next(_L("GetManufacturerStringDescriptor()"));
494 rd_str.FillZ(rd_str.MaxLength());
495 r = aPort->GetManufacturerStringDescriptor(rd_str);
497 test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
499 test.Next(_L("Compare Manufacturer strings"));
500 r = rd_str.Compare(wr_str);
503 test.Next(_L("RemoveManufacturerStringDescriptor()"));
504 r = aPort->RemoveManufacturerStringDescriptor();
506 r = aPort->GetManufacturerStringDescriptor(rd_str);
507 test_Equal(KErrNotFound,r);
511 test.Next(_L("Restore original string"));
512 r = aPort->SetManufacturerStringDescriptor(rd_str_orig);
514 r = aPort->GetManufacturerStringDescriptor(rd_str);
516 r = rd_str.Compare(rd_str_orig);
521 // --- Product string
524 test.Next(_L("GetProductStringDescriptor()"));
525 rd_str_orig.FillZ(rd_str.MaxLength());
526 r = aPort->GetProductStringDescriptor(rd_str_orig);
527 test(r == KErrNone || r == KErrNotFound);
530 test.Printf(_L("Old Product string: \"%lS\"\n"), &rd_str_orig);
531 restore_string = ETrue;
534 restore_string = EFalse;
536 test.Next(_L("SetProductStringDescriptor()"));
537 _LIT16(product, "Product That Was Produced By A Manufacturer");
538 wr_str.FillZ(wr_str.MaxLength());
540 r = aPort->SetProductStringDescriptor(wr_str);
543 test.Next(_L("GetProductStringDescriptor()"));
544 rd_str.FillZ(rd_str.MaxLength());
545 r = aPort->GetProductStringDescriptor(rd_str);
547 test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
549 test.Next(_L("Compare Product strings"));
550 r = rd_str.Compare(wr_str);
553 test.Next(_L("SetProductStringDescriptor()"));
554 _LIT16(product2, "Different Product That Was Produced By A Different Manufacturer");
555 wr_str.FillZ(wr_str.MaxLength());
557 r = aPort->SetProductStringDescriptor(wr_str);
560 test.Next(_L("GetProductStringDescriptor()"));
561 rd_str.FillZ(rd_str.MaxLength());
562 r = aPort->GetProductStringDescriptor(rd_str);
564 test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
566 test.Next(_L("Compare Product strings"));
567 r = rd_str.Compare(wr_str);
570 test.Next(_L("RemoveProductStringDescriptor()"));
571 r = aPort->RemoveProductStringDescriptor();
573 r = aPort->GetProductStringDescriptor(rd_str);
574 test_Equal(KErrNotFound,r);
578 test.Next(_L("Restore original string"));
579 r = aPort->SetProductStringDescriptor(rd_str_orig);
581 r = aPort->GetProductStringDescriptor(rd_str);
583 r = rd_str.Compare(rd_str_orig);
588 // --- Serial Number string
591 test.Next(_L("GetSerialNumberStringDescriptor()"));
592 rd_str_orig.FillZ(rd_str.MaxLength());
593 r = aPort->GetSerialNumberStringDescriptor(rd_str_orig);
594 test(r == KErrNone || r == KErrNotFound);
597 test.Printf(_L("Old Serial Number: \"%lS\"\n"), &rd_str_orig);
598 restore_string = ETrue;
601 restore_string = EFalse;
603 test.Next(_L("SetSerialNumberStringDescriptor()"));
604 _LIT16(serial, "000666000XYZ");
605 wr_str.FillZ(wr_str.MaxLength());
607 r = aPort->SetSerialNumberStringDescriptor(wr_str);
610 test.Next(_L("GetSerialNumberStringDescriptor()"));
611 rd_str.FillZ(rd_str.MaxLength());
612 r = aPort->GetSerialNumberStringDescriptor(rd_str);
614 test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
616 test.Next(_L("Compare Serial Number strings"));
617 r = rd_str.Compare(wr_str);
620 test.Next(_L("SetSerialNumberStringDescriptor()"));
621 _LIT16(serial2, "Y11611193111711111Y");
622 wr_str.FillZ(wr_str.MaxLength());
624 r = aPort->SetSerialNumberStringDescriptor(wr_str);
627 test.Next(_L("GetSerialNumberStringDescriptor()"));
628 rd_str.FillZ(rd_str.MaxLength());
629 r = aPort->GetSerialNumberStringDescriptor(rd_str);
631 test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
633 test.Next(_L("Compare Serial Number strings"));
634 r = rd_str.Compare(wr_str);
637 test.Next(_L("RemoveSerialNumberStringDescriptor()"));
638 r = aPort->RemoveSerialNumberStringDescriptor();
640 r = aPort->GetSerialNumberStringDescriptor(rd_str);
641 test_Equal(KErrNotFound,r);
645 test.Next(_L("Restore original string"));
646 r = aPort->SetSerialNumberStringDescriptor(rd_str_orig);
648 r = aPort->GetSerialNumberStringDescriptor(rd_str);
650 r = rd_str.Compare(rd_str_orig);
655 // --- Configuration string
658 test.Next(_L("GetConfigurationStringDescriptor()"));
659 rd_str_orig.FillZ(rd_str.MaxLength());
660 r = aPort->GetConfigurationStringDescriptor(rd_str_orig);
661 test(r == KErrNone || r == KErrNotFound);
664 test.Printf(_L("Old Configuration string: \"%lS\"\n"), &rd_str_orig);
665 restore_string = ETrue;
668 restore_string = EFalse;
670 test.Next(_L("SetConfigurationStringDescriptor()"));
671 _LIT16(config, "Relatively Simple Configuration That Is Still Useful");
672 wr_str.FillZ(wr_str.MaxLength());
674 r = aPort->SetConfigurationStringDescriptor(wr_str);
677 test.Next(_L("GetConfigurationStringDescriptor()"));
678 rd_str.FillZ(rd_str.MaxLength());
679 r = aPort->GetConfigurationStringDescriptor(rd_str);
681 test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
683 test.Next(_L("Compare Configuration strings"));
684 r = rd_str.Compare(wr_str);
687 test.Next(_L("SetConfigurationStringDescriptor()"));
688 _LIT16(config2, "Convenient Configuration That Can Be Very Confusing");
689 wr_str.FillZ(wr_str.MaxLength());
691 r = aPort->SetConfigurationStringDescriptor(wr_str);
694 test.Next(_L("GetConfigurationStringDescriptor()"));
695 rd_str.FillZ(rd_str.MaxLength());
696 r = aPort->GetConfigurationStringDescriptor(rd_str);
698 test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
700 test.Next(_L("Compare Configuration strings"));
701 r = rd_str.Compare(wr_str);
704 test.Next(_L("RemoveConfigurationStringDescriptor()"));
705 r = aPort->RemoveConfigurationStringDescriptor();
707 r = aPort->GetConfigurationStringDescriptor(rd_str);
708 test_Equal(KErrNotFound,r);
712 test.Next(_L("Restore original string"));
713 r = aPort->SetConfigurationStringDescriptor(rd_str_orig);
715 r = aPort->GetConfigurationStringDescriptor(rd_str);
717 r = rd_str.Compare(rd_str_orig);
725 static void TestArbitraryStringDescriptors(RDEVCLIENT* aPort,TInt aNumSettings)
727 test.Start(_L("Arbitrary String Descriptor Manipulation"));
731 test.Next(_L("GetStringDescriptor() 1"));
732 TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
733 TInt r = aPort->GetStringDescriptor(stridx1, rd_str);
736 TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(KString_one);
737 r = rd_str.Compare(wr_str);
740 // Second test string
742 test.Next(_L("GetStringDescriptor() 2"));
743 rd_str.FillZ(rd_str.MaxLength());
744 r = aPort->GetStringDescriptor(stridx2, rd_str);
747 wr_str = KString_two;
748 r = rd_str.Compare(wr_str);
753 test.Next(_L("GetStringDescriptor() 3"));
754 rd_str.FillZ(rd_str.MaxLength());
755 r = aPort->GetStringDescriptor(stridx3, rd_str);
756 test_Equal(KErrNotFound,r);
758 test.Next(_L("SetStringDescriptor() 3"));
759 _LIT16(string_three, "Arbitrary String Descriptor Test String 3");
760 wr_str.FillZ(wr_str.MaxLength());
761 wr_str = string_three;
762 r = aPort->SetStringDescriptor(stridx3, wr_str);
765 // In between we create another interface setting to see what happens
766 // to the existing string descriptor indices.
767 // (We don't have to test this on every platform -
768 // besides, those that don't support alt settings
769 // are by now very rare.)
770 if (SupportsAlternateInterfaces())
773 TUsbcScInterfaceInfoBuf ifc;
775 TUsbcInterfaceInfoBuf ifc;
777 _LIT16(string, "T_USB_DEVICE Bogus Test Interface (Next Setting)");
778 ifc().iString = const_cast<TDesC16*>(&string);
779 ifc().iTotalEndpointsUsed = 0;
780 TInt r = aPort->SetInterface(aNumSettings, ifc);
784 test.Next(_L("GetStringDescriptor() 3"));
785 r = aPort->GetStringDescriptor(stridx3, rd_str);
787 test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx3, &rd_str);
789 test.Next(_L("Compare test strings 3"));
790 r = rd_str.Compare(wr_str);
793 // Remove string descriptors 3 and 4
795 test.Next(_L("RemoveStringDescriptor() 4"));
796 r = aPort->RemoveStringDescriptor(stridx4);
797 test_Equal(KErrNotFound,r);
799 test.Next(_L("RemoveStringDescriptor() 3"));
800 r = aPort->RemoveStringDescriptor(stridx3);
803 r = aPort->GetStringDescriptor(stridx3, rd_str);
804 test_Equal(KErrNotFound,r);
806 if (SupportsAlternateInterfaces())
808 TInt r = aPort->ReleaseInterface(aNumSettings);
815 void TestInvalidSetInterface (RDEVCLIENT* aPort,TInt aNumSettings)
818 TUsbcScInterfaceInfoBuf ifc;
820 TUsbcInterfaceInfoBuf ifc;
822 _LIT16(string, "T_USB_DEVICE Invalid Interface");
823 ifc().iString = const_cast<TDesC16*>(&string);
824 ifc().iTotalEndpointsUsed = 0;
826 test.Start(_L("Test Invalid Interface Setting"));
828 if (SupportsAlternateInterfaces())
830 TInt r = aPort->SetInterface(aNumSettings+1, ifc);
831 test_Compare(r,!=,KErrNone);
834 if (aNumSettings > 1)
836 TInt r = aPort->SetInterface(aNumSettings-1, ifc);
837 test_Compare(r,!=,KErrNone);
840 TInt r = aPort->SetInterface(0, ifc);
841 test_Compare(r,!=,KErrNone);
846 void TestInvalidReleaseInterface (RDEVCLIENT* aPort,TInt aNumSettings)
848 test.Start(_L("Test Invalid Interface Release"));
850 if (aNumSettings > 2)
852 TInt r = aPort->ReleaseInterface(aNumSettings-3);
853 test_Compare(r,!=,KErrNone);
856 if (aNumSettings > 1)
858 TInt r = aPort->ReleaseInterface(aNumSettings-2);
859 test_Compare(r,!=,KErrNone);
865 void TestDescriptorManipulation(TBool aHighSpeed, RDEVCLIENT* aPort, TInt aNumSettings)
867 test.Start(_L("Test USB Descriptor Manipulation"));
871 TestDeviceQualifierDescriptor(aPort);
873 TestOtherSpeedConfigurationDescriptor(aPort);
876 TestInterfaceDescriptor(aPort,aNumSettings);
878 TestClassSpecificDescriptors(aPort);
880 TestStandardStringDescriptors(aPort);
882 TestArbitraryStringDescriptors(aPort,aNumSettings);
888 void TestOtgExtensions(RDEVCLIENT* aPort)
890 test.Start(_L("Test Some OTG API Extensions"));
892 // Test OTG descriptor manipulation
893 test.Next(_L("Get OTG Descriptor Size"));
895 aPort->GetOtgDescriptorSize(size);
896 test_Equal(KUsbDescSize_Otg,static_cast<TUint>(size));
898 test.Next(_L("Get OTG Descriptor"));
899 TBuf8<KUsbDescSize_Otg> otgDesc;
900 TInt r = aPort->GetOtgDescriptor(otgDesc);
901 test(r == KErrNotSupported || r == KErrNone);
903 test.Next(_L("Set OTG Descriptor"));
904 TBool supportOtg = EFalse;
905 if (r == KErrNotSupported)
907 r = aPort->SetOtgDescriptor(otgDesc);
908 test_Equal(KErrNotSupported,r);
913 otgDesc[0] = KUsbDescSize_Otg;
914 otgDesc[1] = KUsbDescType_Otg;
915 otgDesc[2] = KUsbOtgAttr_SrpSupp;
916 r = aPort->SetOtgDescriptor(otgDesc);
918 TBuf8<KUsbDescSize_Otg> desc;
919 r = aPort->GetOtgDescriptor(desc);
921 test_Equal(0,desc.Compare(otgDesc));
924 // Test get/set OTG feature
925 test.Next(_L("Get OTG Features"));
927 r = aPort->GetOtgFeatures(features);
931 TBool b_HnpEnable = (features & KUsbOtgAttr_B_HnpEnable) ? ETrue : EFalse;
932 TBool a_HnpSupport = (features & KUsbOtgAttr_A_HnpSupport) ? ETrue : EFalse;
933 TBool a_AltHnpSupport = (features & KUsbOtgAttr_A_AltHnpSupport) ? ETrue : EFalse;
934 test.Printf(_L("### OTG Features:\nB_HnpEnable(%d)\nA_HnpSupport(%d)\nA_Alt_HnpSupport(%d)\n"),
935 b_HnpEnable, a_HnpSupport, a_AltHnpSupport);
939 test_Equal(KErrNotSupported,r);
940 test.Printf(_L("GetOtgFeatures() not supported\n"));
947 void TestEndpoint0MaxPacketSizes(RDEVCLIENT* aPort)
949 test.Start(_L("Test Endpoint0 MaxPacketSizes"));
951 TUint32 sizes = aPort->EndpointZeroMaxPacketSizes();
955 for (TInt i = 0; i < 32; i++)
957 TUint bit = sizes & (1 << i);
991 test.Printf(_L("Ep0 supports %d bytes MaxPacketSize\n"), mpsize);
995 test.Printf(_L("Bad Ep0 size: 0x%08x, failure will occur\n"), bit);