Add first batch of unit tests from the javax.usb TCK

This commit is contained in:
Klaus Reimer 2013-02-24 02:09:14 +01:00
parent 63f9a7ada1
commit 74396d9405
15 changed files with 6230 additions and 0 deletions

View File

@ -0,0 +1,898 @@
package javax.usb.tck;
/**
* Copyright (c) 2004, International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
/*
* Change Activity: See below.
*
* FLAG REASON RELEASE DATE WHO DESCRIPTION
* ---- -------- -------- ------ ------- ------------------------------------
* 0000 nnnnnnn yymmdd Initial Development
* $P1 tck.rel1 040804 raulortz Support for UsbDisconnectedException
*/
import java.util.*;
import javax.usb.*;
import javax.usb.event.*;
import junit.framework.TestCase;
/**
* Default Control Pipe Test -- Synchronous and asynchronous IRP submissions
* <p>
* This test verifies that control transfers operations work successfully
* on the Default Control Pipe and that proper events are generated and proper
* exceptions are thrown in the operation.
*
* @author Leslie Blair
*/
@SuppressWarnings("all")
public class DefaultControlPipeTestIRP extends TestCase
{
public void setUp() throws Exception
{
usbDevice = FindProgrammableDevice.getInstance().getProgrammableDevice();
assertNotNull("Device required for test not found",usbDevice);
super.setUp();
}
public void tearDown() throws Exception
{
if ( debug )
{
/* Print out some debug info
*/
System.out.println("iterations = " + iterations);
System.out.println("numSubmits = " + numSubmits);
System.out.println("numDataEvents = " + numDataEvents);
System.out.println("numExceptionEvents = " + numExceptionEvents);
System.out.println("numDetachEvents = " + numDetachEvents);
}
super.tearDown();
}
public void testBuffersMultiplesOfMaxPacketSize_1packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 64; //used later when creating data buffer
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testBuffersMultiplesOfMaxPacketSize_2packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 128; //used later when creating data buffer
//set data in control IRP OUT and data should remain unchanged after submission
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
//IRP data when IRP is created and data is set and should be unchanged after submission
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
// IRP data when IRP is created and data is set and should be unchanged after submission
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testBuffersMultiplesOfMaxPacketSize_moreThan2Packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 192; //used later when creating data buffer
//set data in control IRP OUT and data should remain unchanged after submission
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
//IRP data when IRP is created and data is set and should be unchanged after submission
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
// IRP data when IRP is created and data is set and should be unchanged after submission
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testBuffersNotMultiplesOfMaxPacketSize_1packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 50; //used later when creating data buffer
//set data in control IRP OUT and data should remain unchanged after submission
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
//IRP data when IRP is created and data is set and should be unchanged after submission
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
// IRP data when IRP is created and data is set and should be unchanged after submission
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testBuffersNotMultiplesOfMaxPacketSize_2packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 120; //used later when creating data buffer
//set data in control IRP OUT and data should remain unchanged after submission
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
//IRP data when IRP is created and data is set and should be unchanged after submission
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
// IRP data when IRP is created and data is set and should be unchanged after submission
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testBuffersNotMultiplesOfMaxPacketSize_MoreThan2packets()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
/*******************************
/Prepare OUT IRP
*********************************/
//set Control IRP specific data
byte OUTbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte OUTbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short OUTwValue = VENDOR_REQUEST_DATA_OUT;
short OUTwIndex = 0;
short OUTwLength = 160; //used later when creating data buffer
//set data in control IRP OUT and data should remain unchanged after submission
byte bTransformType = TRANSFORM_TYPE_PASSTHROUGH;
//IRP data when IRP is created and data is set and should be unchanged after submission
boolean OUTIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean OUTverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int OUTIrpLength = OUTwLength;
int OUTIrpOffset = 0;
//Expected actual length of IRP after submission
int OUTIrpExpectedActualLength = OUTwLength;
Exception OUTexpectedException = null;
/*******************************
/Prepare IN IRP
*********************************/
//set Control IRP specific data
byte INbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_VENDOR | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte INbRequest = VENDOR_REQUEST_TRANSFER_DATA;
short INwValue = VENDOR_REQUEST_DATA_IN;
short INwIndex = OUTwIndex;
short INwLength =OUTwLength;
// IRP data when IRP is created and data is set and should be unchanged after submission
boolean INIrpAcceptShortPacket = true; //acceptShortPacket is set on an individual IRP basis; default is true
boolean INverifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int INIrpLength = OUTwLength;
int INIrpOffset = 0;
// Expected actual length of IRP after submission
int INIrpExpectedActualLength = INwLength;
Exception INexpectedException = null;
RoundTripTestIRP(transmitList[j], OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex, OUTwLength,
OUTIrpAcceptShortPacket, OUTverifyAcceptShortPacket, OUTIrpLength, OUTIrpOffset, OUTIrpExpectedActualLength,
OUTexpectedException,
INbmRequestType, INbRequest, INwValue, INwIndex, INwLength,
INIrpAcceptShortPacket, INverifyAcceptShortPacket, INIrpLength, INIrpOffset, INIrpExpectedActualLength,
INexpectedException,
bTransformType );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testRequestClearFeature()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
UsbInterface iface = usbDevice.getActiveUsbConfiguration().getUsbInterface((byte) 0);
try
{
iface.claim();
} catch ( UsbClaimException uCE )
{
fail("Interface already claimed!");
} catch ( UsbNotActiveException uNAE )
{
fail("Configuration is not active!");
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} catch ( UsbException ue ) // @P1C
{
fail("Interface was not claimed!");
}
byte SentbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_OUT | UsbConst.REQUESTTYPE_TYPE_STANDARD | UsbConst.REQUESTTYPE_RECIPIENT_ENDPOINT;
byte SentbRequest = UsbConst.REQUEST_CLEAR_FEATURE;
short SentwValue = UsbConst.FEATURE_SELECTOR_ENDPOINT_HALT;
short SentwIndex = 0x88; //first isochronous IN endpoint
short SentwLength = 0;
byte[] SentData = new byte[SentwLength];
int SentLength = SentwLength;
int SentOffset = 0;
boolean SentacceptShortPacket = true;
byte expectedbmRequestType = SentbmRequestType;
byte expectedbRequest = SentbRequest;
short expectedwValue = SentwValue;
short expectedwIndex = SentwIndex;
short expectedwLength = SentwLength;
byte[] expectedData = new byte[SentwLength];
int expectedLength = SentwLength;
int expectedOffset = 0;
boolean expectedAcceptShortPacket = SentacceptShortPacket;
boolean verifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int expectedActualLength = SentwLength; //length of "Manufacturer" in unicode
Exception expectedException = null;
OneWayTestIRP(transmitList[j], SentbmRequestType, SentbRequest, SentwValue, SentwIndex, SentwLength,
SentacceptShortPacket, SentLength, SentOffset, SentData,
expectedbmRequestType, expectedbRequest, expectedwValue, expectedwIndex, expectedwLength,
expectedAcceptShortPacket, verifyAcceptShortPacket, expectedLength, expectedOffset, expectedActualLength,
expectedException,
expectedData );
try
{
iface.release();
} catch ( UsbClaimException uCE )
{
fail("Interface was not claimed!");
} catch ( UsbNotActiveException uNAE )
{
fail("Configuration is not active!");
} catch ( UsbException ue )
{
fail("Interface was not released!");
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} // @P1A
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
public void testRequestGetDescriptor()
{
usbDevice.addUsbDeviceListener(deviceListener);
for ( int i=0; (i < iterations); i++ )
{
for ( int j=0; j<transmitList.length; j++ )
{
byte SentbmRequestType =
UsbConst.REQUESTTYPE_DIRECTION_IN | UsbConst.REQUESTTYPE_TYPE_STANDARD | UsbConst.REQUESTTYPE_RECIPIENT_DEVICE;
byte SentbRequest = UsbConst.REQUEST_GET_DESCRIPTOR;
short SentwValue = UsbConst.DESCRIPTOR_TYPE_STRING << 8;
SentwValue += 1; //string index 1
short SentwIndex = 0;
short SentwLength = 64;
byte[] SentData = new byte[SentwLength];
int SentLength = SentwLength;
int SentOffset = 0;
boolean SentacceptShortPacket = true;
byte expectedbmRequestType = SentbmRequestType;
byte expectedbRequest = SentbRequest;
short expectedwValue = SentwValue;
short expectedwIndex = SentwIndex;
short expectedwLength = SentwLength;
byte[] expectedData = manufacturerString;
int expectedLength = SentwLength;
int expectedOffset = 0;
boolean expectedAcceptShortPacket = SentacceptShortPacket;
boolean verifyAcceptShortPacket = true; //since we are setting it or allowing it to default, we know the value
int expectedActualLength = 26; //length of "Manufacturer" in unicode
Exception expectedException = null;
OneWayTestIRP(transmitList[j], SentbmRequestType, SentbRequest, SentwValue, SentwIndex, SentwLength,
SentacceptShortPacket, SentLength, SentOffset, SentData,
expectedbmRequestType, expectedbRequest, expectedwValue, expectedwIndex, expectedwLength,
expectedAcceptShortPacket, verifyAcceptShortPacket, expectedLength, expectedOffset, expectedActualLength,
expectedException,
expectedData );
}
}
usbDevice.removeUsbDeviceListener(deviceListener);
};
/**The RoundTripTest is used when an OUT IRP is sent to the default control pipe followed by an IN IRP
* retrieving the IRP from the device.
* @param OUTbmRequestType bmRequestType used for OUT IRP
* @param OUTbRequest bRequest used for OUT IRP (always 0xB0=VENDOR_REQUEST_TRANSFER_DATA)
* @param OUTwValue wValue used for OUT IRP (always 0x00=VENDOR_REQUEST_DATA_OUT for OUT IRPs)
* @param OUTwIndex wIndex for OUT IRP is start index for IRP at device end (usually zero even if offset is non-zero)
* @param OUTwLength wLength is length of OUT IRP (set by setData() or setLength() method of IRP)
* @param OUTIrpAcceptShortPacket acceptShortPacket setting for IRP (this value only used for checking default value of true.
* acceptShortPacket is NOT set in RoundTripTest)
* @param OUTverifyAcceptShortPacket Specify whether to verify acceptShortPacket
* @param OUTIrpLength Length of IRP to be read from byte[]. Set indirectly by setData(). Same as wLength for this test,
* @param OUTIrpOffset Offset in byte[] at which to start reading IRP.
* @param OUTIrpExpectedActualLength ActualLength is the length of data actually transmitted in IRP. Same as wLength for OUT.
* @param OUTexpectedException Specify any expected exception
* @param INbmRequestType bmRequestType used for IN IRP
* @param INbRequest bRequest used for IN IRP (always 0xB0=VENDOR_REQUEST_TRANSFER_DATA)
* @param INwValue wValue used for IN IRP (always 0x80=VENDOR_REQUEST_DATA_IN for IN IRPs)
* @param INwIndex wIndex for IN IRP is start index for reading IRP at device end (usually zero even if offset is non-zero)
* @param INwLength wLength is length of IN IRP to be read from device
* @param INIrpAcceptShortPacket acceptShortPacket setting for IRP (this value only used for checking default value of true.
* acceptShortPacket is NOT set in RoundTripTest)
* @param INverifyAcceptShortPacket Specify whether to verify acceptShortPacket
* @param INIrpLength Length of IN data buffer
* @param INIrpOffset Offset at which to start writing IN data buffer
* @param INIrpExpectedActualLength Actual length of data in IN buffer after submit complete.
* @param INexpectedException Specify any expected exception
* @param bTransformType TRANSFORM_TYPE_PASSTHROUGH = (byte)0x01 (only transform used in this test)
*/
private void RoundTripTestIRP(boolean SyncOrAsync, byte OUTbmRequestType, byte OUTbRequest, short OUTwValue, short OUTwIndex, short OUTwLength,
boolean OUTIrpAcceptShortPacket, boolean OUTverifyAcceptShortPacket, int OUTIrpLength, int OUTIrpOffset, int OUTIrpExpectedActualLength,
Exception OUTexpectedException,
byte INbmRequestType, byte INbRequest, short INwValue, short INwIndex, short INwLength,
boolean INIrpAcceptShortPacket, boolean INverifyAcceptShortPacket, int INIrpLength, int INIrpOffset, int INIrpExpectedActualLength,
Exception INexpectedException,
byte bTransformType )
{
if ( SyncOrAsync == SYNC_SUBMIT )
{
VerifyIrpMethods.printDebug("RoundTripTestIRP -- SYNC");
} else
{
VerifyIrpMethods.printDebug("RoundTripTestIRP -- ASYNC");
}
assertNotNull("usbDevice is null, but should not be null.", usbDevice);
//create Control IRP
UsbControlIrp usbControlIrpOUT = usbDevice.createUsbControlIrp(OUTbmRequestType, OUTbRequest, OUTwValue, OUTwIndex);
//set data in control IRP OUT and data should remain unchanged after submission
TransmitBuffer transmitBuffer = new TransmitBuffer(bTransformType, OUTwLength);
byte[] OUTbuffer = transmitBuffer.getOutBuffer();
usbControlIrpOUT.setData(OUTbuffer);
//send data
if ( !SendUsbControlIrp(SyncOrAsync, usbDevice, usbControlIrpOUT) )
{
fail("Submitting the OUT IRP failed.");
return;
} else
{
//verify OUT IRP after successful transmit--dataEventReceived
VerifyIrpMethods.verifyUsbControlIrpAfterEvent(usbControlIrpOUT,
(EventObject)LastUsbDeviceDataEvent,
transmitBuffer.getOutBuffer(),
OUTIrpExpectedActualLength,
OUTexpectedException,
OUTIrpAcceptShortPacket,
OUTverifyAcceptShortPacket,
OUTIrpOffset,
OUTIrpLength,
OUTbmRequestType,
OUTbRequest,
OUTwValue,
OUTwIndex);
//Reset device events to null after verifications are complete
LastUsbDeviceErrorEvent = null;
LastUsbDeviceDataEvent = null;
UsbControlIrp usbControlIrpIN = usbDevice.createUsbControlIrp(INbmRequestType, INbRequest, INwValue, INwIndex);
//create data buffer in control IRP IN
byte[] INBuffer = new byte[INwLength];
usbControlIrpIN.setData(INBuffer);
//send data
if ( !SendUsbControlIrp(SyncOrAsync, usbDevice, usbControlIrpIN) )
{
fail("Submitting the IN IRP failed.");
return;
} else
{
VerifyIrpMethods.verifyUsbControlIrpAfterEvent(usbControlIrpIN,
(EventObject) LastUsbDeviceDataEvent,
transmitBuffer.getInBuffer(),
INIrpExpectedActualLength,
INexpectedException,
INIrpAcceptShortPacket,
INverifyAcceptShortPacket,
INIrpOffset,
INIrpLength,
INbmRequestType,
INbRequest,
INwValue,
INwIndex);
//Reset device events to null after verifications are complete
LastUsbDeviceErrorEvent = null;
LastUsbDeviceDataEvent = null;
}
}
};
/**
* The OneWayTestIRP is a USB Standard Request that is either OUT or IN
* @param SyncOrAsync SYNC_SUBMIT or ASYNC_SUBMIT
* @param SentbmRequestType bmRequestType for IRP to be sent
* @param SentbRequest bRequest for IRP to be sent
* @param SentwValue wValue for IRP to be sent
* @param SentwIndex wIndex for IRP to be sent
* @param SentwLength wLength for IRP to be sent
* @param SentIrpAcceptShortPacket acceptShortPacket setting of IRP to be sent
* @param SentIrpLength Length of byte[] data to be sent
* @param SentIrpOffset Starting offset of byte[] data to be sent
* @param SentData byte[] to be set in IRP
* @param expectedbmRequestType expected bmRequestType
* @param expectedbRequest expected bRequest
* @param expectedwValue expected wValue
* @param expectedwIndex expected wIndex
* @param expectedwLength expected wLength
* @param expectedAcceptShortPacket expected acceptShortPacket setting
* @param verifyAcceptShortPacket Specify whether or not to verify acceptShortPacket
* @param expectedLength expected unchanged length for byte[]
* @param expectedOffset expected unchaged offset for byte[]
* @param expectedActualLength expected actual length of data sent or received
* @param expectedException expectedException
* @param expectedData expected byte[]
*/
private void OneWayTestIRP(boolean SyncOrAsync,byte SentbmRequestType, byte SentbRequest, short SentwValue, short SentwIndex, short SentwLength,
boolean SentIrpAcceptShortPacket, int SentIrpLength, int SentIrpOffset, byte []SentData,
byte expectedbmRequestType, byte expectedbRequest, short expectedwValue, short expectedwIndex, short expectedwLength,
boolean expectedAcceptShortPacket, boolean verifyAcceptShortPacket, int expectedLength, int expectedOffset, int expectedActualLength,
Exception expectedException,
byte [] expectedData )
{
if ( SyncOrAsync == SYNC_SUBMIT )
{
VerifyIrpMethods.printDebug("OneWayTestIRP -- SYNC");
} else
{
VerifyIrpMethods.printDebug("OneWayTestIRP -- ASYNC");
}
//make sure usbDevice has been set
assertNotNull("usbDevice is null, but should not be null.", usbDevice);
//create Control IRP
UsbControlIrp usbControlIrp = usbDevice.createUsbControlIrp(SentbmRequestType, SentbRequest, SentwValue, SentwIndex);
//set variable parts of Irp
usbControlIrp.setData(SentData);
usbControlIrp.setAcceptShortPacket(SentIrpAcceptShortPacket);
//send data
if ( !SendUsbControlIrp(SyncOrAsync, usbDevice, usbControlIrp) )
{
fail("Submitting the OneWayTest IRP failed.");
return;
} else
{
//verify OUT IRP after successful transmit
VerifyIrpMethods.verifyUsbControlIrpAfterEvent(usbControlIrp,
(EventObject)LastUsbDeviceDataEvent,
expectedData,
expectedActualLength,
expectedException,
expectedAcceptShortPacket,
verifyAcceptShortPacket,
expectedOffset,
expectedLength,
expectedbmRequestType,
expectedbRequest,
expectedwValue,
expectedwIndex);
//Reset device events to null after verifications are complete
LastUsbDeviceErrorEvent = null;
LastUsbDeviceDataEvent = null;
}
};
private UsbDeviceListener deviceListener = new UsbDeviceListener()
{
public void dataEventOccurred(UsbDeviceDataEvent uddE)
{
numDataEvents++;
assertNotNull(uddE);
LastUsbDeviceDataEvent = uddE;
}
public void errorEventOccurred(UsbDeviceErrorEvent udeE)
{
numExceptionEvents++;
assertNotNull(udeE);
LastUsbDeviceErrorEvent = udeE;
fail("No devices error events expected during this test. Exception is " + udeE.getUsbException().getMessage());
}
public void usbDeviceDetached(UsbDeviceEvent udE)
{
numDetachEvents++;
assertNotNull(udE);
fail("No devices should be detached during this test.");
}
};
/**
* Send the UsbControlIrp to the UsbDevice on the DCP.
* @param SyncOrAsync SYNC_SUBMIT or ASYNC_SUBMIT
* @param usbDevice
* @param usbControlIrp
* @param caughtException
* @return
*/
private boolean SendUsbControlIrp(boolean SyncOrAsync, UsbDevice usbDevice, UsbControlIrp usbControlIrp)
{
try
{
/* This will block until the submission is complete.
* Note that submissions (except interrupt and bulk in-direction)
* will not block indefinitely, they will complete or fail within
* a finite amount of time. See MouseDriver.HidMouseRunnable for more details.
*/
if ( SyncOrAsync == SYNC_SUBMIT )
{
usbDevice.syncSubmit(usbControlIrp);
} else
{
usbDevice.asyncSubmit(usbControlIrp);
usbControlIrp.waitUntilComplete(5000);
}
assertTrue("isComplete() not true for IRP after waitUntilComplete(..)", usbControlIrp.isComplete());
try
{
/*
* Wait for device event before leaving submit routine
*/
for ( int i = 0; i < 100; i++ )
{
if ( (LastUsbDeviceDataEvent != null)|
(LastUsbDeviceErrorEvent != null) )
{
//System.out.println("Data event took less than " + ((i+1) * 20 ) +" milliseconds");
break;
}
Thread.sleep( 20 ); //wait 20 ms before checkin for event
}
} catch ( InterruptedException e )
{
fail("Sleep was interrupted");
//e.printStackTrace();
}
assertNotNull("Did not receive a DeviceDataEvent after sleep.", LastUsbDeviceDataEvent);
assertNull("Unexpected DeviceErrorEvent received after submit", LastUsbDeviceErrorEvent);
numSubmits++;
return true;
} catch ( UsbException uE )
{
/* The exception sould indicate the reason for the failure.
* For this example, we'll just stop trying.
*/
fail("DCP submission failed." + uE.getMessage());
//System.out.println("DCP submission failed : " + uE.getMessage());
return false;
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
return false; // @P1A
} // @P1A
};
/**
* Constructor
*/
public DefaultControlPipeTestIRP()
{
};
protected DefaultControlPipeTestIRP(UsbDevice newUsbDevice)
{
usbDevice = newUsbDevice;
};
private static final byte VENDOR_REQUEST_TRANSFER_DATA = (byte)0xB0;
private static final short VENDOR_REQUEST_DATA_OUT = 0x00;
private static final short VENDOR_REQUEST_DATA_IN = 0x80;
private static final byte TRANSFORM_TYPE_PASSTHROUGH = (byte)0x01;
private static final byte TRANSFORM_TYPE_INVERT_BITS = (byte)0x02;
private static final byte TRANSFORM_INVERT_ALTERNATE_BITS = (byte)0x03;
private UsbDeviceDataEvent LastUsbDeviceDataEvent;
private UsbDeviceErrorEvent LastUsbDeviceErrorEvent;
private UsbDevice usbDevice;
// private boolean debug = true;
private boolean debug = false;
private int iterations = 10;
private int numSubmits = 0;
private int numDataEvents = 0;
private int numExceptionEvents = 0;
private int numDetachEvents = 0;
private static final boolean SYNC_SUBMIT = true;
private static final boolean ASYNC_SUBMIT = false;
boolean [] transmitList= {SYNC_SUBMIT, ASYNC_SUBMIT};
private static final byte[] manufacturerString = { (byte) 26, //length of descriptor
(byte) UsbConst.DESCRIPTOR_TYPE_STRING,
(byte)'M',(byte) 0x00,
(byte)'a',(byte) 0x00,
(byte)'n',(byte) 0x00,
(byte)'u',(byte) 0x00,
(byte)'f',(byte) 0x00,
(byte)'a',(byte) 0x00,
(byte)'c',(byte) 0x00,
(byte)'t',(byte) 0x00,
(byte)'u',(byte) 0x00,
(byte)'r',(byte) 0x00,
(byte)'e',(byte) 0x00,
(byte)'r',(byte) 0x00};
}

View File

@ -0,0 +1,434 @@
package javax.usb.tck;
/*
* Copyright (c) IBM Corporation, 2004
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License.
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*
*/
/*
* Change Activity: See below.
*
* FLAG REASON RELEASE DATE WHO DESCRIPTION
* ---- -------- -------- ------ ------- ------------------------------------
* 0000 nnnnnnn yymmdd Initial Development
* $P1 tck.rel1 040804 raulortz Support for UsbDisconnectedException
*/
import java.io.*;
import java.util.*;
import javax.usb.*;
import javax.usb.util.*;
/**
* This is the Singleton class to find the Programmable Development board
* usage: (FindProgrammableDevice.getInstance()).getProgrammableDevice()
* @author Thanh Ngo
*/
@SuppressWarnings("all")
public class FindProgrammableDevice extends Object
{
//-------------------------------------------------------------------------
// Ctor(s)
//
/** Ctor is protected because we are a Singleton */
protected FindProgrammableDevice()
{
}
//-------------------------------------------------------------------------
// Public methods
//
/** @return the sole instance of this class (lazily) */
public static FindProgrammableDevice getInstance()
{
if ( instance == null )
{
instance = new FindProgrammableDevice();
instance.init();
}
return instance;
}
//-------------------------------------------------------------------------
// Protected methods
//
/** Initializing the FindProgrammableDevice instance */
protected void init()
{
// empty
}
//-------------------------------------------------------------------------
// Public methods
//
/**
* find the first Programmable board with default vendorID = 0x0547 and
* default productID = 0x1002
* return null if not found
*/
public UsbDevice getProgrammableDevice()
{
programmableVendorId = (short)0x0547;
programmableProductId = (short)0x1002;
return getProgrammableDevice(programmableVendorId, programmableProductId);
}
/**
* find the first Programmable board with default vendorID = 0x0547 and
* default productID = 0xFF01
* This device is used for topology test.
* return null if not found
*/
public UsbDevice getTopologyTestDevice()
{
programmableVendorId = (short)0x0547;
programmableProductId = (short)0xFF01;
return getProgrammableDevice(programmableVendorId, programmableProductId);
}
/**
* find the first Programmable board with vendor ID and product ID
* return null if not found
*/
public UsbDevice getProgrammableDevice(short vendorId, short productId)
{
return getUsbDevice(vendorId, productId);
}
/**
* find the Programmable boards
* return List of Programmable boards, null if not found
*/
public List getProgrammableDevicesList()
{
short vendorId = getProgrammableVendorId();
short productId = getProgrammableProductId();
return getUsbDevicesList(vendorId, productId);
}
/**
* find the usb boards with its manufacture string
* return List of device if found
* return null if not found.
*/
public List getUsbDeviceWithProductString(String manufactureString)
{
return getUsbDevicesWithManufacturerString(getVirtualRootUsbHub(), manufactureString);
}
/**
* find the first usb board with its vendorID and productID
* return null if not found
*/
public UsbDevice getUsbDevice(short vendorId, short productId)
{
virtualRootUsbHub = getVirtualRootUsbHub();
usbDevices = null;
// get all connected devices
if ( debug )
{
usbDevices = getAllUsbDevices(virtualRootUsbHub);
System.out.println("Found " + usbDevices.size() + " devices total.");
}
usbDevices = getUsbDevicesWithId(virtualRootUsbHub, vendorId, productId);
if ( debug )
{
System.out.print("Found " + usbDevices.size() + " devices with");
System.out.print(" vendor ID 0x" + UsbUtil.toHexString(vendorId));
System.out.print(" product ID 0x" + UsbUtil.toHexString(productId));
System.out.println("");
}
if ( usbDevices.isEmpty() )
{
if ( debug )
{
System.out.println("List Empty");
}
return null;
}
else
{
// return the first item
return(UsbDevice)usbDevices.get(0);
}
}
/**
* find the usb board with its vendorID and productID
* return List of device if found
* return null if not found.
*/
public List getUsbDevicesList(short vendorId, short productId)
{
virtualRootUsbHub = getVirtualRootUsbHub();
usbDevices = null;
// get all connected devices
if ( debug )
{
usbDevices = getAllUsbDevices(virtualRootUsbHub);
System.out.println("Found " + usbDevices.size() + " devices total.");
}
usbDevices = getUsbDevicesWithId(virtualRootUsbHub, vendorId, productId);
if ( debug )
{
System.out.print("Found " + usbDevices.size() + " devices with");
System.out.print(" vendor ID 0x" + UsbUtil.toHexString(vendorId));
System.out.print(" product ID 0x" + UsbUtil.toHexString(productId));
System.out.println("");
}
if ( usbDevices.isEmpty() )
{
if ( debug )
{
System.out.println("List Empty");
}
return null;
}
// return the list
return usbDevices;
}
//-------------------------------------------------------------------------
// Private methods
//
/**
* Get the virtual root UsbHub.
* @return virtual root UsbHub.
*/
private static UsbHub getVirtualRootUsbHub()
{
UsbServices services = null;
UsbHub virtualRootUsbHub = null;
/* First we need to get the UsbServices.
* This might throw either an UsbException or SecurityException.
* A SecurityException means we're not allowed to access the USB bus,
* while a UsbException indicates there is a problem either in
* the javax.usb implementation or the OS USB support.
*/
try
{
services = UsbHostManager.getUsbServices();
}
catch ( UsbException uE )
{
throw new RuntimeException("Error : " + uE.getMessage());
}
catch ( SecurityException sE )
{
throw new RuntimeException("Error : " + sE.getMessage());
}
/* Now we need to get the virtual root UsbHub,
* everything is connected to it. The Virtual Root UsbHub
* doesn't actually correspond to any physical device, it's
* strictly virtual. Each of the devices connected to one of its
* ports corresponds to a physical host controller located in
* the system. Those host controllers are (usually) located inside
* the computer, e.g. as a PCI board, or a chip on the mainboard,
* or a PCMCIA card. The virtual root UsbHub aggregates all these
* host controllers.
*
* This also may throw an UsbException or SecurityException.
*/
try
{
virtualRootUsbHub = services.getRootUsbHub();
}
catch ( UsbException uE )
{
throw new RuntimeException("Error : " + uE.getMessage());
}
catch ( SecurityException sE )
{
throw new RuntimeException("Error : " + sE.getMessage());
}
return virtualRootUsbHub;
}
/**
* This forms an inclusive list of all UsbDevices connected to this UsbDevice.
* <p>
* The list includes the provided device. If the device is also a hub,
* the list will include all devices connected to it, recursively.
* @param usbDevice The UsbDevice to use.
* @return An inclusive List of all connected UsbDevices.
*/
private static List getAllUsbDevices(UsbDevice usbDevice)
{
List list = new ArrayList();
list.add(usbDevice);
/* this is just normal recursion. Nothing special. */
if ( usbDevice.isUsbHub() )
{
List devices = ((UsbHub)usbDevice).getAttachedUsbDevices();
for ( int i=0; i<devices.size(); i++ )
list.addAll(getAllUsbDevices((UsbDevice)devices.get(i)));
}
return list;
}
/**
* Get a List of all devices that match the specified vendor and product id.
* @param usbDevice The UsbDevice to check.
* @param vendorId The vendor id to match.
* @param productId The product id to match.
* @param A List of any matching UsbDevice(s).
*/
private static List getUsbDevicesWithId(UsbDevice usbDevice, short vendorId, short productId)
{
List list = new ArrayList();
/* A device's descriptor is always available. All descriptor
* field names and types match exactly what is in the USB specification.
* Note that Java does not have unsigned numbers, so if you are
* comparing 'magic' numbers to the fields, you need to handle it correctly.
* For example if you were checking for Intel (vendor id 0x8086) devices,
* if (0x8086 == descriptor.idVendor())
* will NOT work. The 'magic' number 0x8086 is a positive integer, while
* the _short_ vendor id 0x8086 is a negative number! So you need to do either
* if ((short)0x8086 == descriptor.idVendor())
* or
* if (0x8086 == UsbUtil.unsignedInt(descriptor.idVendor()))
* or
* short intelVendorId = (short)0x8086;
* if (intelVendorId == descriptor.idVendor())
* Note the last one, if you don't cast 0x8086 into a short,
* the compiler will fail because there is a loss of precision;
* you can't represent positive 0x8086 as a short; the max value
* of a signed short is 0x7fff (see Short.MAX_VALUE).
*
* See javax.usb.util.UsbUtil.unsignedInt() for some more information.
*/
if ( vendorId == usbDevice.getUsbDeviceDescriptor().idVendor() &&
productId == usbDevice.getUsbDeviceDescriptor().idProduct() )
list.add(usbDevice);
/* this is just normal recursion. Nothing special. */
if ( usbDevice.isUsbHub() )
{
List devices = ((UsbHub)usbDevice).getAttachedUsbDevices();
for ( int i=0; i<devices.size(); i++ )
list.addAll(getUsbDevicesWithId((UsbDevice)devices.get(i), vendorId, productId));
}
return list;
}
/**
* Get a List of all devices that match the specified manufacturer string.
* @param usbDevice The UsbDevice to check.
* @param manufacturerString The manufacturer string to match.
* @return A List of any matching UsbDevice(s).
*/
public static List getUsbDevicesWithManufacturerString(UsbDevice usbDevice, String manufacturerString)
{
List list = new ArrayList();
/* Getting the product string may generate an UsbException,
* as it may be necessary to actually communicate with the device
* which could fail.
*/
try
{
if ( manufacturerString.equals(usbDevice.getManufacturerString()) )
list.add(usbDevice);
}
catch ( UsbException uE )
{
/* If there is an UsbException, we couldn't communicate
* with the device for some reason. The exact reason should be
* indicated by the UsbException (we won't try to determine it here).
* We could try to get the string again (possibly after trying to
* figure out and/or fix the cause of the UsbException),
* or we could ignore this device, or we could throw the UsbException,
* or some other Exception, on up. Since this is an example we'll
* throw a RuntimeException on up (if we threw the UsbException,
* we would have to declare that in this method definition).
* This isn't a good thing to do in normal code.
*/
throw new RuntimeException("Couldn't get manufacturer string : " + uE.toString());
}
catch ( UnsupportedEncodingException usE )
{
/* If there is an UnsupportedEncodingException, the
* available Java libraries did not have an encoding that
* could convert the 16-bit UNICODE byte[] to a String.
* This is uncommon, and probably means that the string
* is not in english _and_ the Java libraries are significantly
* reduced, possibly for an embedded Java (J2ME?) implementation.
* For this case, we'll ignore the device - the provided string
* most likely does not match whatever the device's string is.
* But, who knows, it might...remember this is just an example!
*/
}
catch ( UsbDisconnectedException uDE ) // @P1A
{ // @P1A
System.out.println ("A connected device should't throw the UsbDisconnectedException!");// @P1A
} // @P1A
/* this is just normal recursion. Nothing special. */
if ( usbDevice.isUsbHub() )
{
List devices = ((UsbHub)usbDevice).getAttachedUsbDevices();
for ( int i=0; i<devices.size(); i++ )
list.addAll(getUsbDevicesWithManufacturerString((UsbDevice)devices.get(i), manufacturerString));
}
return list;
}
/**
* Get a Programmable vendor ID.
* @return A vendor ID.
*/
public short getProgrammableVendorId()
{
return programmableVendorId;
}
/**
* Get a Programmable product ID.
* @return A product ID.
*/
public short getProgrammableProductId()
{
return programmableProductId;
}
//-------------------------------------------------------------------------
// Instance variables
//
private static final boolean debug = false; // true = debug
protected static FindProgrammableDevice instance = null;
private UsbHub virtualRootUsbHub = getVirtualRootUsbHub();
private List usbDevices = null;
// Programmable Development Kit
private short programmableVendorId;
private short programmableProductId;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
package javax.usb.tck;
/**
* Copyright (c) 2004, International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
import javax.usb.tck.sigtest.*;
import java.io.*;
import junit.framework.*;
/**
* This is the API signature test for the entire javax.usb.* package.
* This test verifies the existence of all expected public classes and
* interfaces. In those public classes and interfaces it verifies the
* existence, correct modifiers, arguments, and throws clauses of
* public constructors and methods. It also verifies the existence and
* correct modifiers of public fields.
*
* @author Bob Rossi
*/
@SuppressWarnings("all")
public class SignatureTest extends TestCase
{
/**
* Test the signatures of all the classes and methods for compliance
* with the Javax.usb specification.
*/
public void testSignatures() throws IOException
{
String javaxusbtck_home =
System.getProperty("javaxusbtck_home", System.getProperty("user.dir"));
File dir = new File(javaxusbtck_home, "src/test/resources");
File file = new File(dir, "javax.usb-1.0.sig");
String result = ProjectDesc.compareProjectFile(file);
Assert.assertNull(result, result);
}
}

View File

@ -0,0 +1,240 @@
package javax.usb.tck;
/*
* Copyright (c) IBM Corporation, 2004
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License.
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*
*/
/**
* This is the TransmitBuffer class to create a OUT transmitt buffer based on
* parameters supply to the constructor.
* It will create an expected buffer to be received on an IN buffer also
* based on the parameters supplied to the constructor.
* @author Thanh Ngo
*/
@SuppressWarnings("all")
public class TransmitBuffer extends Object
{
/**
* Constructor.
* @param ucTransformType The Data manipilation:
* 1 - Pass through
* 2 - Invert every bit starting with the second bit
* 3 - Invert every other bit (invert odd bits assuming bit numbering begins at 0)
* 4 - Drop every third byte (ex. OUT - b1, b2, b3, b4, b5, b6 IN - b1, b2, b4, b5)
*
* @param uilRPLength The length of the data byte in
* @exception IllegalArgumentException If the offset, length or data is invalid.
*/
protected TransmitBuffer(byte ucTransformType, int uilRPLength)
{
//System.out.println("type: " + ucTransformType + " length: " + uilRPLength);
if ( 0 > ucTransformType )
throw new IllegalArgumentException("Type cannot be negative");
if ( 0 == ucTransformType )
throw new IllegalArgumentException("Type cannot be 0");
if ( 5 < ucTransformType )
throw new IllegalArgumentException("Valid value are 1 to 4");
if ( 0 > uilRPLength )
throw new IllegalArgumentException("Length cannot be negative");
transformType = ucTransformType;
rpLength = uilRPLength;
outBuffer = new byte[rpLength];
byte fill = 0;
for ( int i = 0; i < rpLength; i++ )
outBuffer[i] = fill++;
outBuffer[0] = (byte)transformType;
outBuffer[1] = (byte)(rpLength / 256);
outBuffer[2] = (byte)(rpLength % 256);
outBuffer[3] = sequenceNumber;
int pos = 7;
while ( pos < rpLength )
{
outBuffer[pos] = sequenceNumber;
pos += 8;
}
outBuffer[rpLength-1] = sequenceNumber;
if ( transformType_passthru == ucTransformType )
{
inBuffer = new byte[rpLength];
System.arraycopy(outBuffer, 0, inBuffer,0, inBuffer.length);
}
else if ( transformType_invert_every_bit == ucTransformType )
{
inBuffer = new byte[rpLength];
for ( int i = 0; i < inBuffer.length; i++ )
inBuffer[i] = (byte)(outBuffer[i] ^ 0xff);
}
else if ( transformType_invert_every_other_bit == ucTransformType )
{
inBuffer = new byte[rpLength];
for ( int i = 0; i < inBuffer.length; i++ )
inBuffer[i] = (byte)(outBuffer[i] ^ 0x55);
}
else if ( transformType_drop_every_third_byte == ucTransformType )
{
int size = rpLength / 3;
size = rpLength - size;
inBuffer = new byte[size];
int outIndex = 0;
int inIndex = 0;
while ( outIndex < rpLength )
{
inBuffer[inIndex++] = outBuffer[outIndex++]; // 1st byte
if ( outIndex < rpLength )
inBuffer[inIndex++] = outBuffer[outIndex++]; // 2nd byte
if ( outIndex < rpLength )
outIndex++; // 3rd byte , skip
}
}
else
{
throw new IllegalArgumentException("Length exceed limit");
}
mySequenceNumber = sequenceNumber;
sequenceNumber++; // next Transmitt buffer sequence
}
//-------------------------------------------------------------------------
// Public methods
//
/** compare the IN buffer expected to an IN buffer actually received
* @param in The Buffer to be compared with IN buffer
* @return true if the two buffers are the same, false otherwise.
*/
boolean compareBuffers(byte[] inData)
{
if ( inBuffer.length != inData.length )
{
//System.out.println("-->length!!!");
return false;
}
for ( int i = 0; i < inData.length; i++ )
{
if ( inBuffer[i] != inData[i] )
{
//System.out.println("-->False!!! i= " + i + " in: " + inBuffer[i] + " out: " + inData[i]);
return false;
}
}
return true;
}
/** compare the OUT buffer to a buffer supplied as a parameter
* @param outData The buffer to compare with the OUT buffer
* @return true if the two buffers are the same, false otherwise
*/
protected boolean compareToOUTBuffer(byte[] outData)
{
if ( outBuffer.length != outData.length )
return false;
for ( int i = 0; i < outData.length; i++ )
{
if ( outBuffer[i] != outData[i] )
{
return false;
}
}
return true;
}
/** compare two byte arrays supplied as a parameter. Length of byte arrays is expected to be equal.
* @param buffer1 First byte array.
* @param buffer2 Second byte array.
* @return true if the two byte arrays are the same, false otherwise
*/
protected static boolean compareTwoByteArrays(byte[] buffer1, byte[] buffer2)
{
if ( buffer1.length != buffer2.length )
return false;
for ( int i = 0; i < buffer1.length; i++ )
{
if ( buffer1[i] != buffer2[i] )
{
return false;
}
}
return true;
}
/** Compares first "length" number of bytes of two arrays.
* The caller must ensure that the length does not exceed the
* length of either buffer1 or buffer2.
* @param buffer1 First byte array.
* @param buffer2 Second byte array.
* @param length Number of bytes to compare
* @return true if the two byte arrays are the same over the range specified, false otherwise
*/
protected static boolean compareTwoByteArraysForSpecifiedLength(byte[] buffer1, int offset1, byte[] buffer2, int offset2,int length)
{
for ( int i = 0; i < length; i++ )
{
if ( buffer1[i + offset1] != buffer2[i + offset2] )
{
return false;
}
}
return true;
}
/**
* Get the IN buffer.
* @return The IN data buffer.
*/
protected byte[] getInBuffer()
{
return inBuffer;
}
/**
* Get the OUT buffer.
* @return The OUT data buffer.
*/
protected byte[] getOutBuffer()
{
return outBuffer;
}
/**
* Get the sequenceNumber.
* @return The sequenceNumber variable.
*/
protected int getsequenceNumber()
{
return mySequenceNumber;
}
//-------------------------------------------------------------------------
// Instance variables
//
private byte transformType;
private int rpLength;
private byte[] inBuffer = new byte[0];
private byte[] outBuffer = new byte[0];
private static byte sequenceNumber = 0;
private byte mySequenceNumber;
private static final byte transformType_passthru = 1;
private static final byte transformType_invert_every_bit = 2;
private static final byte transformType_invert_every_other_bit = 3;
private static final byte transformType_drop_every_third_byte = 4;
}

View File

@ -0,0 +1,335 @@
package javax.usb.tck;
/**
* Copyright (c) 2004, International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
/*
* Change Activity: See below.
*
* FLAG REASON RELEASE DATE WHO DESCRIPTION
* ---- -------- -------- ------ -------- ------------------------------------
* 0000 nnnnnnn yymmdd Initial Development
* $P1 tck.rel1 040804 raulortz Support for UsbDisconnectedException
* $P2 tck.rel1 041222 raulortz Redesign TCK to create base and optional
* tests. Separate setConfig, setInterface
* and isochronous transfers as optionals.
*/
import junit.framework.TestCase;
import java.util.*;
import javax.usb.*;
/**
* Usb Interface Policy Test
* <p>
* Goal: This test will use a new implementation of the UsbInterfacePolicy
* Interface to test the that the UsbInterfacePolicy is being used correctly.
*
* @author Dale Heeks
*/
@SuppressWarnings("all")
public class UsbInterfacePolicyTest extends TestCase
{
public UsbInterfacePolicyTest(String name)
{
super(name);
}
protected void setUp() throws Exception {
usbDevice = programmableDevice.getProgrammableDevice();
assertTrue( "Find Programmable board Failed! Got a null instance", usbDevice != null );
assertTrue("The usbDevice is not confuigured", usbDevice.isConfigured());
usbConfiguration = usbDevice.getUsbConfiguration((byte)1);
policy1 = new InterfacePolicyImp();
}
protected void tearDown() throws Exception {
}
/*ForceClaim policy test cases */
/**
* Test forceClaim policy with a false return
* <p>
* This test case will set the ForceClaim policy
* to false and then call claim to ensure that the
* ForceClaim policy method is invoked inside
* the UsbInterfacePolicyImp class
*<p>
* <strong>NOTE:</strong> This will not check if the claim isn't forced
* because some implemetations
* will not be able to do a force claim and some will,
*
*/
public void testIfaceForceClaimFalse()
{
policy1.setForceClaimPolicy(false);
assertFalse("Force Claim tag isn't reset, this is probably a TCK defect",
policy1.getForceClaimTag() );
assertTrue("Can't claim Interface, this is probably a defect with your implementation",
claimIface(usbConfiguration.getUsbInterface((byte)0), policy1));
// @P2D4
//reset the claim tag
policy1.setForceClaimTag(false);
releaseIface(usbConfiguration.getUsbInterface((byte)0), null);
}
/**
* Test forceClaim policy with a true return
* <p>
* This test case will set the ForceClaim policy
* to true and then call claim to ensure that the
* ForceClaim policy method is invoked inside
* the UsbInterfacePolicyImp class
*<p>
* <strong>NOTE:</strong> This will not check if the claim is forced
* because some implemetations
* will not be able to do a force claim and some will.
*
*/
public void testIfaceForceClaimTrue()
{
policy1.setForceClaimPolicy(true);
assertFalse("Force Claim tag isn't reset, this is probably a TCK defect",
policy1.getForceClaimTag() );
assertTrue("Can't claim Interface, this is probably a defect with your implementation",
claimIface(usbConfiguration.getUsbInterface((byte)0), policy1));
// @P2D4
//Reset the force claim tag
policy1.setForceClaimTag(false);
releaseIface(usbConfiguration.getUsbInterface((byte)0), null);
}
//This method will take an interface and policy and call the appropriate
//claim method, this method should only be used within this test
private boolean claimIface(UsbInterface iface,
UsbInterfacePolicy ifacePolicy)
{
try
{
if ( ifacePolicy == null )
iface.claim();
else
iface.claim(ifacePolicy);
} catch ( UsbClaimException uce )
{
return false;
} catch ( UsbNotActiveException unae )
{
fail("UsbNotActiveException: " + unae);
} catch ( UsbException ue )
{
fail("UsbException: " + ue);
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} // @P1A
return true;
}
//This method takes a interface and key and make the appropriate
//interface method call
private int releaseIface(UsbInterface iface,
Object key)
{
try
{
iface.release();
} catch ( UsbClaimException uce )
{
return notClaimed;
} catch ( UsbNotActiveException unae )
{
fail("UsbNotActiveException: " + unae);
} catch ( UsbException ue )
{
fail("UsbException: " + ue);
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} // @P1A
return released;
}
//Method that takes an interface and returns it's first pipe
private UsbPipe getUsbPipe(UsbInterface iface)
{
List endpoints = iface.getUsbEndpoints();
UsbEndpoint e1 = (UsbEndpoint)endpoints.get(0);
return e1.getUsbPipe();
}
//Method that will call the appropriate open method given
//a pipe and a key
private int openPipe(UsbPipe pipe, Object key)
{
try
{
pipe.open();
} catch ( UsbNotActiveException unae )
{
fail("UsbNotActiveException: " + unae);
} catch ( UsbNotClaimedException unae )
{
fail("UsbNotActiveException: " + unae);
} catch ( UsbException ue )
{
fail("UsbException: " + ue);
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} // @P1A
return opened;
}
//method to close a pipe, this is for test case clean up
private boolean closePipe(UsbPipe pipe)
{
try
{
pipe.close();
} catch ( UsbException ue )
{
fail("UsbException: " + ue);
} catch ( UsbNotActiveException unae )
{
fail("UsbNotOpenedException: " + unae);
} catch ( UsbDisconnectedException uDE ) // @P1C
{ // @P1A
fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A
} // @P1A
return true;
}
private FindProgrammableDevice programmableDevice = FindProgrammableDevice.getInstance();
private InterfacePolicyImp policy1 = null;
private UsbConfiguration usbConfiguration = null;
private UsbDevice usbDevice = null;
private UsbInterface iface = null;
private UsbEndpoint Endpoint;
private static final boolean debug = true;
private static final int released = 1111;
private static final int opened = 2222;
private static final int notClaimed = 4444;
/*
*************************************************************************
********************Test Interface Policy Implemetation class************
*************************************************************************/
/**
* Copyright (c) 2004, International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
/**
* Name of class -- Usb Interface Policy test implementation
* <p>
* This class is an implementation of the UsbInterfacePolicy, this
* should only be used for the Javax.usb tck.
*
* @author Dale Heeks
*/
private class InterfacePolicyImp implements UsbInterfacePolicy
{
/**Constuctor
*
* <p>
* Default constructor, sets everything in this policy to true,
* which is also the same as the default policy
*
*
*/
public InterfacePolicyImp ()
{
forceClaimPolicy = true;
forceClaimTag = false;
}
/**Method that should be called from a claim using
* the non default interface policy
*
*@param arg0 The current UsbInterface that is being claimed
*
*@return boolean Whether to allow an interface to attempt
*a force claim
*/
public boolean forceClaim(UsbInterface arg0)
{
forceClaimTag = true;
return forceClaimPolicy;
}
/**Allows a user to dynamically set the force claim policy
*
* @param forceClaimIn The new force claim policy
*/
public void setForceClaimPolicy(boolean forceClaimIn)
{
forceClaimPolicy = forceClaimIn;
}
/**Allows a user to dynamically set the force claim tag
*
* <p>
* The force claim tag checks to see if the force claim policy has been called
*
* @param forceClaimTagIn The new force claim tag
*/
public void setForceClaimTag(boolean forceClaimTagIn)
{
forceClaimTag = forceClaimTagIn;
}
/**Allows a user to check the force claim tag
*
* <p>
* The force claim tag checks to see if the force claim policy has been called
*
* @return boolean The force claim tag
*/
public boolean getForceClaimTag()
{
return forceClaimTag;
}
private boolean forceClaimPolicy;
private boolean forceClaimTag;
}
/*************************************************************************/
}

View File

@ -0,0 +1,413 @@
/**
* Copyright (c) 2004, International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
package javax.usb.tck;
import junit.framework.Assert;
import java.util.*;
import javax.usb.*;
import javax.usb.event.*;
/**
* VerifyIrpMethods
* <p>
* Helper functions to verify IRPs and Events
*
* @author Leslie Blair
*/
@SuppressWarnings("all")
public class VerifyIrpMethods
{
private static void verifyDataEventValuesAndUsbIrpValuesWithExpectedValues(UsbIrp usbIrpSubmitted,
EventObject usbEvent,
byte[] expectedData)
{
printDebug("Entering verifyDataEventValuesAndUsbIrpValuesWithExpectedValues");
UsbIrp usbEventIrp = null;
byte[] usbEventData = null;
//Verify usbDataEvent is not null
Assert.assertNotNull("Event must not be null.", usbEvent);
//Get the IRP from the Data event
if ( UsbDeviceDataEvent.class == usbEvent.getClass() )
{
usbEventIrp = (((UsbDeviceDataEvent) usbEvent).getUsbControlIrp());
usbEventData = (((UsbDeviceDataEvent) usbEvent).getData());
Assert.assertNotNull("UsbDevice from Device event is unexpectedly null.",((UsbDeviceEvent)usbEvent).getUsbDevice());
}
else if ( UsbPipeDataEvent.class == usbEvent.getClass() )
{
usbEventIrp = (((UsbPipeDataEvent) usbEvent).getUsbIrp());
usbEventData = (((UsbPipeDataEvent) usbEvent).getData());
}
if ( usbIrpSubmitted != null )
{
/*
* Verify submitted IRP
*/
Assert.assertTrue("isComplete() not true.",usbIrpSubmitted.isComplete());
//Verify ActualLength as expected
Assert.assertEquals("ActualLength not expected value.",
expectedData.length, usbIrpSubmitted.getActualLength());
//Verify data in IRP
Assert.assertTrue("IRP data not as expected", TransmitBuffer.compareTwoByteArraysForSpecifiedLength(
usbIrpSubmitted.getData(),usbIrpSubmitted.getOffset(),
expectedData, 0, expectedData.length));
//Verify no exception
Assert.assertFalse("isUsbException() not false.", usbIrpSubmitted.isUsbException());
Assert.assertNull("getUsbException() not null.", usbIrpSubmitted.getUsbException());
/*
* Verify data event IRP and data
*/
//Verify the IRP returned in data event is the same as IRP submitted
Assert.assertSame("The submitted Irp and the usbIrp returned " +
"in event are not the same object",
usbIrpSubmitted, usbEventIrp);
}
else
{
printDebug("No IRP submitted for verification. Test must by sync byte [].");
}
//Verify data in the IRP from data event (This is really covered in assert that submitted IRP and event IRP are the same.)
Assert.assertTrue("Data from device data event IRP not expected data.",
TransmitBuffer.compareTwoByteArraysForSpecifiedLength(usbEventIrp.getData(),
usbEventIrp.getOffset(),
expectedData, 0,
expectedData.length));
//Note that the getData() from the DeviceDataEvent returns only the actual data transferred as opposed to the
//getData() for the DeviceDataEvent IRP which contains the entire byte[] originally set in the IRP.
//Therefore, the usbDeviceDataEvent.getData() should be an exact match for the expectedData.
Assert.assertTrue("Data from UsbDeviceDataEvent not expected data.",
TransmitBuffer.compareTwoByteArraysForSpecifiedLength(usbEventData, 0,
expectedData, 0, expectedData.length));
printDebug("Leaving verifyDataEventValuesAndUsbIrpValuesWithExpectedValues");
};
private static void verifyErrorEventValuesAndUsbIrpValuesWithExpectedValues(UsbIrp usbIrpSubmitted,
EventObject usbEvent,
Exception expectedException)
{
printDebug("Entering verifyErrorEventValuesAndUsbIrpValuesWithExpectedValues");
//Verify usbEvent is not null
Assert.assertNotNull("Event must not be null.", usbEvent);
// Verify submitted IRP
Assert.assertTrue("isComplete() not true.",usbIrpSubmitted.isComplete());
//Verify exception
Assert.assertTrue("isUsbException() not true.", usbIrpSubmitted.isUsbException());
Assert.assertNotNull("getUsbException() is null.", usbIrpSubmitted.getUsbException());
//Verify expected exception
if ( UsbDeviceErrorEvent.class == usbEvent.getClass() )
{
if ( (((UsbDeviceErrorEvent)usbEvent).getUsbException()).getClass() != expectedException.getClass() )
{
Assert.fail("\nExpected exception class is " + expectedException.getClass().toString() +
"\nReceived exception class is " + ((UsbDeviceErrorEvent)usbEvent).getUsbException().getClass().toString() );
}
Assert.assertNotNull("UsbDevice from Device event is unexpectedly null.",((UsbDeviceEvent)usbEvent).getUsbDevice());
}
else if ( UsbPipeErrorEvent.class == usbEvent.getClass() )
{
if ( (((UsbPipeErrorEvent)usbEvent).getUsbException()).getClass() != expectedException.getClass() )
{
Assert.fail("\nExpected exception class is " + expectedException.getClass().toString() +
"\nReceived exception class is " + ((UsbPipeErrorEvent)usbEvent).getUsbException().getClass().toString() );
}
}
/*Possible TODO -- if getUsb(Control)Irp method is added to DeviceErrorEvent and PipeErrorEvent classes
* then the following code needs to be added to this method. At that point you may consider combining this method with the
* "verifyDataEventValuesAndUsbIrpValuesWithExpectedValues" method because there will be more common code.
*
UsbIrp usbEventIrp = null;
byte[] usbEventData = null;
//Get the IRP from the event
if ( UsbDeviceErrorEvent.class == usbEvent.getClass())
{
usbEventIrp = (((UsbDeviceErrorEvent) usbEvent).getUsbControlIrp());
usbEventData = (((UsbDeviceErrorEvent) usbEvent).getData());
}
else if (UsbPipeErrorEvent.class == usbEvent.getClass())
{
usbEventIrp = (((UsbPipeErrorEvent) usbEvent).getUsbIrp());
usbEventData = (((UsbPipeErrorEvent) usbEvent).getData());
}
//Verify the IRP returned in event is the same as IRP submitted
Assert.assertSame("The submitted usbControlIrp and the usbControlIrp returned " +
"in event are not the same object",
usbIrpSubmitted, usbEventIrp);
//Assert.assertTrue("The submitted usbControlIrp and the usbControlIrp returned " +
// "in UsbDeviceDataEvent are not equal",
// usbIrpSubmitted.equals(usbEventIrp));
*/
printDebug("Leaving verifyErrorEventValuesAndUsbIrpValuesWithExpectedValues");
};
private static void validateExpectations(byte [] expectedData, Exception expectedException) throws IllegalArgumentException
{
printDebug("Entering validateExpectations");
/*
* The verification to be performed is based on which value, expectedData or expectedException, is set.
* One, and only one, of these values must be set.
*/
if ( (expectedData != null) && (expectedException != null) )
{
throw new IllegalArgumentException("Both expectedData and expectedException are non-null. If a data event " +
"is expected, expectedData should be set. If an error event is expected, expectedError should be set. " +
"Both values should not be set");
}
else if ( (expectedData == null) && (expectedException == null) )
{
throw new IllegalArgumentException("Both expectedData and expectedException are null. If a data event " +
"is expected, expectedData should be set. If an error event is expected, expectedError should be set. " +
"One of the values must be set.");
}
printDebug("Leaving validateExpectations");
}
/**
* verifyUsbIrpAfterEvent(..) verifies a UsbIrp against expected values
* @param usbIrpSubmitted IRP to verify
* @param usbEvent UsbDevice(or Pipe) Data or Error Event
* @param expectedData expected byte[] in IRP (must be null if expected exception not null)
* @param expectedActualLength actual length of data transmitted
* @param expectedException expected exception (must be null if expected data is not null)
* @param expectedAcceptShortPacket expected value of acceptShortPacket
* @param verifyAcceptShortPacket Specifies whether to verify acceptShortPacket
* @param expectedOffset expected offset for byte [] in IRP
* @param expectedLength expected length for byte [] in IRP
* @param expectedbmRequestType expected bmRequestType in control IRP
* @param expectedbRequest expected bRequest in control IRP
* @param expectedwValue expected wValue in control IRP
* @param expectedwIndex expected wIndex in control IRP
*/
protected static void verifyUsbControlIrpAfterEvent(UsbControlIrp usbControlIrpSubmitted,
EventObject usbEvent,
byte[] expectedData,
int expectedActualLength,
Exception expectedException,
boolean expectedAcceptShortPacket,
boolean verifyAcceptShortPacket,
int expectedOffset,
int expectedLength,
byte expectedbmRequestType,
byte expectedbRequest,
short expectedwValue,
short expectedwIndex)
{
printDebug("Entering verifyUsbControlIrpAfterEvent");
//Verify UsbControlIrp values
Assert.assertEquals("bmRequestType not expected value.",
expectedbmRequestType, usbControlIrpSubmitted.bmRequestType());
Assert.assertEquals("bRequest not expected value.",
expectedbRequest, usbControlIrpSubmitted.bRequest());
Assert.assertEquals("wValue not expected value.",
expectedwValue, usbControlIrpSubmitted.wValue());
Assert.assertEquals("wIndex not expected value.",
expectedwIndex, usbControlIrpSubmitted.wIndex());
//verify UsbIrp values
VerifyIrpMethods.verifyUsbIrpAfterEvent(usbControlIrpSubmitted,
usbEvent,
expectedData,
expectedActualLength,
expectedException,
expectedAcceptShortPacket,
verifyAcceptShortPacket,
expectedOffset,
expectedLength);
printDebug("Leaving verifyUsbControlIrpAfterEvent");
};
/**
* verifyUsbIrpAfterEvent(..) verifies a UsbIrp against expected values
* @param usbIrpSubmitted IRP to verify
* @param usbEvent UsbDevice(or Pipe) Data or Error Event
* @param expectedData expected byte[] in IRP (must be null if expected exception not null)
* @param expectedActualLength actual length of data transmitted
* @param expectedException expected exception (must be null if expected data is not null)
* @param expectedAcceptShortPacket expected value of acceptShortPacket
* @param verifyAcceptShortPacket Specifies whether to verify acceptShortPacket
* @param expectedOffset expected offset for byte [] in IRP
* @param expectedLength expected length for byte [] in IRP
*/
protected static void verifyUsbIrpAfterEvent(UsbIrp usbIrpSubmitted,
EventObject usbEvent,
byte[] expectedData,
int expectedActualLength,
Exception expectedException,
boolean expectedAcceptShortPacket,
boolean verifyAcceptShortPacket,
int expectedOffset,
int expectedLength)
{
printDebug("Entering verifyUsbIrpAfterEvent");
try
{
validateExpectations(expectedData, expectedException);
}
catch ( IllegalArgumentException iaE )
{
Assert.fail("Illegal Arguments supplied to verifyUsbIrpAfterEvent(...) method");
}
/*
* Verify values in UsbIrp that should be unchanged after submission.
* This verification is valid for a data event or error event
*
* Verify AcceptShortPacket, Offset, and Length not changed
*/
if ( usbIrpSubmitted != null )
{
Assert.assertEquals("Offset changed after IRP submitted.", expectedOffset, usbIrpSubmitted.getOffset());
Assert.assertEquals("Length changed after IRP submitted.", expectedLength, usbIrpSubmitted.getLength());
if ( verifyAcceptShortPacket )
{
Assert.assertEquals("AcceptShortPacket changed after IRP submitted.",
expectedAcceptShortPacket, usbIrpSubmitted.getAcceptShortPacket());
}
}
else
{
printDebug("No IRP submitted for verification. Test must by sync byte [].");
}
/*
* Data event verification
*/
if ( expectedData != null )
{
//Verify expected values in UsbIrp after data event
VerifyIrpMethods.verifyDataEventValuesAndUsbIrpValuesWithExpectedValues(usbIrpSubmitted,
usbEvent,
expectedData);
}
/*
* Error event verification
*/
else
{
//Verify expected values in UsbIrp after error event
VerifyIrpMethods.verifyErrorEventValuesAndUsbIrpValuesWithExpectedValues(usbIrpSubmitted,
usbEvent,
expectedException);
}
printDebug("Leaving verifyUsbIrpAfterEvent");
};
/**
* verifyRequestTest(..) verifies a UsbIrp against expected values
* @param usbIrpSubmitted IRP to verify
* @param expectedbmRequestType expected bmRequestType in control IRP
* @param expectedbRequest expected bRequest in control IRP
* @param expectedwValue expected wValue in control IRP
* @param expectedwIndex expected wIndex in control IRP
*/
protected static void verifyRequestTest(UsbControlIrp usbControlIrpSubmitted,
byte expectedbmRequestType,
byte expectedbRequest,
short expectedwValue,
short expectedwIndex)
{
printDebug("Entering verifyRequestTest");
//Verify UsbControlIrp values
Assert.assertEquals("bmRequestType not expected value.",
expectedbmRequestType, usbControlIrpSubmitted.bmRequestType());
Assert.assertEquals("bRequest not expected value.",
expectedbRequest, usbControlIrpSubmitted.bRequest());
Assert.assertEquals("wValue not expected value.",
expectedwValue, usbControlIrpSubmitted.wValue());
Assert.assertEquals("wIndex not expected value.",
expectedwIndex, usbControlIrpSubmitted.wIndex());
}
/**
* verifyRequestTestData(..) verifies a UsbIrp against expected values
* @param usbIrpSubmitted IRP to verify
* @param expectedbmRequestType expected bmRequestType in control IRP
* @param expectedbRequest expected bRequest in control IRP
* @param expectedwValue expected wValue in control IRP
* @param expectedwIndex expected wIndex in control IRP
* @param expectedLength expected length for byte [] in IRP
* @param expectedData expected byte[] in IRP (must be null if expected exception not null)
*/
protected static void verifyRequestTestData(UsbControlIrp usbControlIrpSubmitted,
byte expectedbmRequestType,
byte expectedbRequest,
short expectedwValue,
short expectedwIndex,
int expectedLength)
{
byte[] buffer;
printDebug("Entering verifyRequestTestData");
//Verify UsbControlIrp values
Assert.assertEquals("bmRequestType not expected value.",
expectedbmRequestType, usbControlIrpSubmitted.bmRequestType());
Assert.assertEquals("bRequest not expected value.",
expectedbRequest, usbControlIrpSubmitted.bRequest());
Assert.assertEquals("wValue not expected value.",
expectedwValue, usbControlIrpSubmitted.wValue());
Assert.assertEquals("wIndex not expected value.",
expectedwIndex, usbControlIrpSubmitted.wIndex());
Assert.assertEquals("Length changed after IRP submitted.",
expectedLength, usbControlIrpSubmitted.getLength());
}
/**
* printDebug method will print the specified string if "debug" is true.
* Useful function for debugging
* @param infoString
*/
protected static void printDebug(String infoString)
{
if ( debug )
{
System.out.println(infoString);
}
}
private static boolean debug = false;
//private static boolean debug = true;
}

View File

@ -0,0 +1,319 @@
package javax.usb.tck.sigtest;
/**
* Copyright (c) 2003,2004 International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
/**
* This class stores all the information needed to compare the signature
* of one class to another.
*
* @author Matthew J. Duftler
*/
@SuppressWarnings("all")
public class ClassDesc extends MemberDesc
{
private String superClassName = null;
private List interfaceNames = new Vector();
private List constructorDescs = new Vector();
private List methodDescs = new Vector();
public ClassDesc(String name, int modifiers)
{
super(name, modifiers);
}
public void setSuperClassName(String superClassName)
{
this.superClassName = superClassName;
}
public String getSuperClassName()
{
return superClassName;
}
public void setInterfaceNames(List interfaceNames)
{
this.interfaceNames = interfaceNames;
}
public List getInterfaceNames()
{
return interfaceNames;
}
public void addConstructorDesc(MethodDesc constructorDesc)
{
constructorDescs.add(constructorDesc);
}
public void setConstructorDescs(List constructorDescs)
{
this.constructorDescs = constructorDescs;
}
public List getConstructorDescs()
{
return constructorDescs;
}
public void addMethodDesc(MethodDesc methodDesc)
{
methodDescs.add(methodDesc);
}
public void setMethodDescs(List methodDescs)
{
this.methodDescs = methodDescs;
}
public List getMethodDescs()
{
return methodDescs;
}
public static ClassDesc parseClassDesc(BufferedReader classDescReader)
throws IOException
{
String classDescStr = classDescReader.readLine();
List tokens = SigTestUtils.stringToList(classDescStr, " ");
int size = tokens.size();
int i = 0;
int modifiers = Integer.parseInt((String)tokens.get(i++));
String className = (String)tokens.get(i++);
String superClassName = null;
String interfaceNamesListStr = null;
List interfaceNames = null;
while (size > i)
{
String tempToken = (String)tokens.get(i++);
if (tempToken.equals("extends"))
{
superClassName = (String)tokens.get(i++);
}
else if (tempToken.equals("implements"))
{
interfaceNamesListStr = (String)tokens.get(i++);
}
}
if (interfaceNamesListStr != null)
{
interfaceNames = SigTestUtils.stringToList(interfaceNamesListStr, ",");
}
ClassDesc classDesc = new ClassDesc(className, modifiers);
classDesc.setSuperClassName(superClassName);
if (interfaceNames != null)
{
classDesc.setInterfaceNames(interfaceNames);
}
classDescReader.readLine();
String tempLine = null;
while (!(tempLine = classDescReader.readLine()).equals("}"))
{
MethodDesc methodDesc = MethodDesc.parseMethodDesc(tempLine);
if (methodDesc.getReturnTypeName() == null)
{
classDesc.addConstructorDesc(methodDesc);
}
else
{
classDesc.addMethodDesc(methodDesc);
}
}
return classDesc;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
else if (obj == this)
{
return true;
}
else
{
ClassDesc that = (ClassDesc)obj;
if (!SigTestUtils.objectsEqual(name, that.name))
{
return false;
}
else if (modifiers != that.modifiers)
{
return false;
}
else if (!SigTestUtils.objectsEqual(superClassName, that.superClassName))
{
return false;
}
else if (!SigTestUtils.collectionsMatch(interfaceNames,
that.interfaceNames))
{
return false;
}
else if (!SigTestUtils.collectionsMatch(constructorDescs,
that.constructorDescs))
{
return false;
}
else if (!SigTestUtils.collectionsMatch(methodDescs, that.methodDescs))
{
return false;
}
else
{
return true;
}
}
}
public String compare(ClassDesc that)
{
StringBuffer strBuf = new StringBuffer();
if (modifiers != that.modifiers)
{
strBuf.append("On class '" + name + "', the modifiers are '" +
Modifier.toString(that.modifiers) +
"', when they should be '" +
Modifier.toString(modifiers) + "'.");
}
if (!SigTestUtils.objectsEqual(superClassName, that.superClassName))
{
strBuf.append("\nClass '" + name + "' " +
(that.superClassName != null
? "extends '" + that.superClassName + "'"
: "does not extend any class") +
", when it should" +
(superClassName != null
? " extend '" + superClassName + "'."
: "n't extend any class."));
}
if (!SigTestUtils.collectionsMatch(interfaceNames, that.interfaceNames))
{
strBuf.append("\nClass '" + name + "' " +
(that.interfaceNames.size() > 0
? "implements '" + that.interfaceNames + "'"
: "does not implement any interfaces") +
", when it should" +
(interfaceNames.size() > 0
? " implement '" + interfaceNames + "'."
: "n't implement any interfaces."));
}
List referenceExtras = new Vector();
List candidateExtras = new Vector();
SigTestUtils.findExtras(constructorDescs,
that.constructorDescs,
referenceExtras,
candidateExtras);
if (referenceExtras.size() > 0 || candidateExtras.size() > 0)
{
strBuf.append("\nClass '" + name + "'" +
(candidateExtras.size() > 0
? " has extraneous constructor" +
(candidateExtras.size() > 1 ? "s" : "") + " " +
SigTestUtils.getExpandedMethodList(candidateExtras)
: "") +
(referenceExtras.size() > 0
? (candidateExtras.size() > 0 ? " and" : "") +
" is missing constructor" +
(referenceExtras.size() > 1 ? "s" : "") + " " +
SigTestUtils.getExpandedMethodList(referenceExtras)
: "") + ".");
}
referenceExtras = new Vector();
candidateExtras = new Vector();
SigTestUtils.findExtras(methodDescs,
that.methodDescs,
referenceExtras,
candidateExtras);
if (referenceExtras.size() > 0 || candidateExtras.size() > 0)
{
strBuf.append("\nClass '" + name + "'" +
(candidateExtras.size() > 0
? " has extraneous method" +
(candidateExtras.size() > 1 ? "s" : "") + " " +
SigTestUtils.getExpandedMethodList(candidateExtras)
: "") +
(referenceExtras.size() > 0
? (candidateExtras.size() > 0 ? " and" : "") +
" is missing method" +
(referenceExtras.size() > 1 ? "s" : "") + " " +
SigTestUtils.getExpandedMethodList(referenceExtras)
: "") + ".");
}
return (strBuf.length() > 0)
? strBuf.toString()
: null;
}
public String toString()
{
StringBuffer strBuf = new StringBuffer();
strBuf.append(modifiers + " " + name +
(superClassName != null
? " extends " + superClassName
: "") +
(interfaceNames.size() > 0
? " implements " + SigTestUtils.listToString(interfaceNames)
: "") +
"\n{\n");
Iterator constrIterator = constructorDescs.iterator();
while (constrIterator.hasNext())
{
strBuf.append(" " + constrIterator.next() + "\n");
}
Iterator methodIterator = methodDescs.iterator();
while (methodIterator.hasNext())
{
strBuf.append(" " + methodIterator.next() + "\n");
}
strBuf.append("}");
return strBuf.toString();
}
public int hashCode()
{
return toString().hashCode();
}
}

View File

@ -0,0 +1,49 @@
package javax.usb.tck.sigtest;
/**
* Copyright (c) 2003,2004 International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
/**
* This class stores the name and modifiers for a given member (class or
* method).
*
* @author Matthew J. Duftler
*/
@SuppressWarnings("all")
public class MemberDesc
{
protected String name = null;
protected int modifiers = 0;
public MemberDesc(String name, int modifiers)
{
this.name = name;
this.modifiers = modifiers;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setModifiers(int modifiers)
{
this.modifiers = modifiers;
}
public int getModifiers()
{
return modifiers;
}
}

View File

@ -0,0 +1,180 @@
package javax.usb.tck.sigtest;
/**
* Copyright (c) 2003,2004 International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
import java.lang.reflect.*;
import java.util.*;
/**
* This class stores all the information needed to identify a method
* signature.
*
* @author Matthew J. Duftler
*/
@SuppressWarnings("all")
public class MethodDesc extends MemberDesc
{
private String returnTypeName = null;
private List paramTypeNames = new Vector();
private List exceptionTypeNames = new Vector();
public MethodDesc(String name,
int modifiers,
String returnTypeName,
List paramTypeNames,
List exceptionTypeNames)
{
super(name, modifiers);
this.returnTypeName = returnTypeName;
this.paramTypeNames = paramTypeNames;
this.exceptionTypeNames = exceptionTypeNames;
}
public void setReturnTypeName(String returnTypeName)
{
this.returnTypeName = returnTypeName;
}
public String getReturnTypeName()
{
return returnTypeName;
}
public void setParameterTypeNames(List paramTypeNames)
{
this.paramTypeNames = paramTypeNames;
}
public List getParameterTypeNames()
{
return paramTypeNames;
}
public void setExceptionTypeNames(List exceptionTypeNames)
{
this.exceptionTypeNames = exceptionTypeNames;
}
public List getExceptionTypeNames()
{
return exceptionTypeNames;
}
public static MethodDesc parseMethodDesc(String methodDescStr)
{
String[] tokens = SigTestUtils.tokenize(methodDescStr, " ");
int modifiers = Integer.parseInt(tokens[0]);
String returnTypeName = null;
int offset = 0;
if (!tokens[2].startsWith("("))
{
returnTypeName = tokens[1];
offset = 1;
}
String methodName = tokens[1 + offset];
String parameterTypeNamesStr = tokens[2 + offset];
parameterTypeNamesStr =
parameterTypeNamesStr.substring(1, parameterTypeNamesStr.length() - 1);
List parameterTypeNames =
SigTestUtils.stringToList(parameterTypeNamesStr, ",");
List exceptionTypeNames;
if (tokens.length > (3 + offset))
{
String exceptionTypeNamesStr = tokens[4 + offset];
exceptionTypeNames =
SigTestUtils.stringToList(exceptionTypeNamesStr, ",");
}
else
{
exceptionTypeNames = new Vector();
}
MethodDesc methodDesc =
new MethodDesc(methodName,
modifiers,
returnTypeName,
parameterTypeNames,
exceptionTypeNames);
return methodDesc;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
else if (obj == this)
{
return true;
}
else
{
MethodDesc that = (MethodDesc)obj;
if (!SigTestUtils.objectsEqual(name, that.name))
{
return false;
}
else if (modifiers != that.modifiers)
{
return false;
}
else if (!SigTestUtils.objectsEqual(returnTypeName, that.returnTypeName))
{
return false;
}
else if (!SigTestUtils.objectsEqual(paramTypeNames, that.paramTypeNames))
{
return false;
}
else if (!SigTestUtils.collectionsMatch(exceptionTypeNames,
that.exceptionTypeNames))
{
return false;
}
else
{
return true;
}
}
}
public int hashCode()
{
return toString().hashCode();
}
public String toString(boolean expandModifiers)
{
return (expandModifiers
? Modifier.toString(modifiers)
: modifiers + "") + " " +
(returnTypeName != null ? returnTypeName + " " : "") +
name + " (" + SigTestUtils.listToString(paramTypeNames) + ")" +
(exceptionTypeNames.size() > 0
? " throws " + SigTestUtils.listToString(exceptionTypeNames)
: "");
}
public String toString()
{
return toString(false);
}
}

View File

@ -0,0 +1,179 @@
package javax.usb.tck.sigtest;
/**
* Copyright (c) 2003,2004 International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
import java.io.*;
import java.util.*;
/**
* This class stores a name and a collection of class descriptions,
* to form a project.
*
* @author Matthew J. Duftler
*/
@SuppressWarnings("all")
public class ProjectDesc
{
private String name;
private List classDescs = new Vector();
public ProjectDesc(String name)
{
this.name = name;
}
public void addClassDesc(ClassDesc classDesc)
{
classDescs.add(classDesc);
}
public ClassDesc getClassDesc(String className)
{
Iterator iterator = classDescs.iterator();
while (iterator.hasNext())
{
ClassDesc classDesc = (ClassDesc)iterator.next();
if (SigTestUtils.objectsEqual(classDesc.getName(), className))
{
return classDesc;
}
}
return null;
}
public void setClassDescs(List classDescs)
{
this.classDescs = classDescs;
}
public List getClassDescs()
{
return classDescs;
}
/**
* This method compares this project description to the specified one.
*
* @param that the project description to compare this one to
*
* @return a description of the differences, or null if they match perfectly
*/
public String compare(ProjectDesc that)
{
StringBuffer strBuf = new StringBuffer();
Iterator iterator = classDescs.iterator();
while (iterator.hasNext())
{
ClassDesc thisCD = (ClassDesc)iterator.next();
ClassDesc thatCD = that.getClassDesc(thisCD.getName());
if (thatCD != null)
{
String result = thisCD.compare(thatCD);
if (result != null)
{
strBuf.append("\n" + result);
}
}
}
List referenceExtras = new Vector();
List candidateExtras = new Vector();
SigTestUtils.findExtraClasses(this,
that,
referenceExtras,
candidateExtras);
if (referenceExtras.size() > 0 || candidateExtras.size() > 0)
{
strBuf.append("\nProject '" + that.name + "'" +
(candidateExtras.size() > 0
? " has extraneous class" +
(candidateExtras.size() > 1 ? "es" : "") + " " +
SigTestUtils.getCondensedClassList(candidateExtras)
: "") +
(referenceExtras.size() > 0
? (candidateExtras.size() > 0 ? " and" : "") +
" is missing class" +
(referenceExtras.size() > 1 ? "es" : "") + " " +
SigTestUtils.getCondensedClassList(referenceExtras)
: "") + ".");
}
return (strBuf.length() > 0)
? strBuf.toString()
: null;
}
/**
* This method compares the specified project file to the classes
* currently available on the classpath.
*
* @param file the project file to read from
*
* @return a description of the differences, or null if they match perfectly
*/
public static String compareProjectFile(File projectFile)
throws IOException
{
ProjectDesc riPD = readProjectFile("ReferenceImpl", projectFile);
ProjectDesc cdPD = SigTestUtils.getProjectDesc(riPD);
return riPD.compare(cdPD);
}
public String toString()
{
StringBuffer strBuf = new StringBuffer("Project '" + name + "': ");
int size = classDescs.size();
for (int i = 0; i < size; i++)
{
strBuf.append((i > 0 ? ", " : "") +
((ClassDesc)classDescs.get(i)).getName());
}
return strBuf.toString();
}
/**
* This method reads the specified project file into memory.
*
* @param projectName the name to be used when referring to the project in
* error messages
* @param file the project file to read from
*
* @return a model of the project
*/
public static ProjectDesc readProjectFile(String projectName,
File file)
throws IOException
{
ProjectDesc pd = new ProjectDesc(projectName);
FileReader fileReader = new FileReader(file);
BufferedReader buf = new BufferedReader(fileReader);
while (buf.ready())
{
pd.addClassDesc(ClassDesc.parseClassDesc(buf));
}
buf.close();
fileReader.close();
return pd;
}
}

View File

@ -0,0 +1,441 @@
package javax.usb.tck.sigtest;
/**
* Copyright (c) 2003,2004 International Business Machines Corporation.
* All Rights Reserved.
*
* This software is provided and licensed under the terms and conditions
* of the Common Public License:
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*/
import java.lang.reflect.*;
import java.io.*;
import java.util.*;
/**
* This class implements static utility methods for use by the signature
* test tool.
*
* @author Matthew J. Duftler
*/
@SuppressWarnings("all")
public class SigTestUtils
{
/**
* This method builds a new project description by using an existing one
* as a reference. The new project description is built by resolving each
* class specified in the reference description, and adding their signatures
* to the newly built project.
*
* @param referencePD the reference project description
*
* @return the new project description
*/
public static ProjectDesc getProjectDesc(ProjectDesc referencePD)
{
ProjectDesc candidatePD = new ProjectDesc("CandidateImpl");
Iterator iterator = referencePD.getClassDescs().iterator();
while (iterator.hasNext())
{
ClassDesc referenceCD = (ClassDesc)iterator.next();
String className = referenceCD.getName();
ClassDesc candidateCD = null;
try
{
Class candidateClass = Class.forName(className);
candidateCD = getClassDesc(candidateClass);
}
catch (ClassNotFoundException e)
{
}
if (candidateCD != null)
{
candidatePD.addClassDesc(candidateCD);
}
}
return candidatePD;
}
public static ClassDesc getClassDesc(Class theClass)
{
String className = getClassName(theClass);
ClassDesc classDesc = new ClassDesc(className,
theClass.getModifiers());
Class superClass = theClass.getSuperclass();
if (superClass != null)
{
classDesc.setSuperClassName(getClassName(superClass));
}
List interfaceNames = getTypeNames(theClass.getInterfaces());
classDesc.setInterfaceNames(interfaceNames);
List constructorDescs =
getConstructorDescs(className, theClass.getDeclaredConstructors());
classDesc.setConstructorDescs(constructorDescs);
List methodDescs =
getMethodDescs(theClass.getDeclaredMethods());
classDesc.setMethodDescs(methodDescs);
return classDesc;
}
public static List getConstructorDescs(String className,
Constructor[] constructors)
{
List constructorDescs = new Vector();
for (int i = 0; i < constructors.length; i++)
{
MethodDesc constructorDesc =
new MethodDesc(className,
constructors[i].getModifiers(),
null,
getTypeNames(constructors[i].getParameterTypes()),
getTypeNames(constructors[i].getExceptionTypes()));
constructorDescs.add(constructorDesc);
}
return constructorDescs;
}
public static List getMethodDescs(Method[] methods)
{
List methodDescs = new Vector();
for (int i = 0; i < methods.length; i++)
{
MethodDesc methodDesc =
new MethodDesc(methods[i].getName(),
methods[i].getModifiers(),
getClassName(methods[i].getReturnType()),
getTypeNames(methods[i].getParameterTypes()),
getTypeNames(methods[i].getExceptionTypes()));
methodDescs.add(methodDesc);
}
return methodDescs;
}
public static List getTypeNames(Class[] types)
{
List typeNames = new Vector();
for (int i = 0; i < types.length; i++)
{
typeNames.add(getClassName(types[i]));
}
return typeNames;
}
public static String listToString(List list)
{
StringBuffer strBuf = new StringBuffer();
int size = list.size();
for (int i = 0; i < size; i++)
{
strBuf.append((i > 0 ? "," : "") +
list.get(i));
}
return strBuf.toString();
}
public static List stringToList(String str, String delim)
{
return Arrays.asList(tokenize(str, delim));
}
public static String[] tokenize(String tokenStr, String delim)
{
StringTokenizer strTok = new StringTokenizer(tokenStr, delim);
String[] tokens = new String[strTok.countTokens()];
for (int i = 0; i < tokens.length; i++)
{
tokens[i] = strTok.nextToken();
}
return tokens;
}
public static boolean objectsEqual(Object obj1, Object obj2)
{
if (obj1 == null)
{
return (obj2 == null);
}
else
{
return obj1.equals(obj2);
}
}
public static boolean collectionsMatch(Collection c1, Collection c2)
{
if (c1 == null)
{
return (c2 == null);
}
else
{
return c1.containsAll(c2) && c2.containsAll(c1);
}
}
public static String getExpandedMethodList(List list)
{
StringBuffer strBuf = new StringBuffer("[");
int size = list.size();
for (int i = 0; i < size; i++)
{
strBuf.append((i > 0 ? ", " : "") +
((MethodDesc)list.get(i)).toString(true));
}
strBuf.append("]");
return strBuf.toString();
}
public static String getCondensedClassList(List list)
{
StringBuffer strBuf = new StringBuffer("[");
int size = list.size();
for (int i = 0; i < size; i++)
{
strBuf.append((i > 0 ? ", " : "") +
((ClassDesc)list.get(i)).getName());
}
strBuf.append("]");
return strBuf.toString();
}
public static void findExtras(Collection reference,
Collection candidate,
List referenceExtras,
List candidateExtras)
{
referenceExtras.addAll(reference);
referenceExtras.removeAll(candidate);
candidateExtras.addAll(candidate);
candidateExtras.removeAll(reference);
if (candidateExtras.size() > 0)
{
Iterator memberDescs = candidateExtras.iterator();
while (memberDescs.hasNext())
{
MemberDesc memberDesc = (MemberDesc)memberDescs.next();
int modifiers = memberDesc.getModifiers();
if (Modifier.isPrivate(modifiers)
|| !(Modifier.isProtected(modifiers)
|| Modifier.isPublic(modifiers)))
{
memberDescs.remove();
}
}
}
}
public static void findExtraClasses(ProjectDesc referencePD,
ProjectDesc candidatePD,
List referenceExtras,
List candidateExtras)
{
referenceExtras.addAll(referencePD.getClassDescs());
candidateExtras.addAll(candidatePD.getClassDescs());
Iterator iterator = referenceExtras.iterator();
while (iterator.hasNext())
{
ClassDesc referenceCD = (ClassDesc)iterator.next();
ClassDesc candidateCD =
candidatePD.getClassDesc(referenceCD.getName());
if (candidateCD != null)
{
iterator.remove();
}
}
iterator = candidateExtras.iterator();
while (iterator.hasNext())
{
ClassDesc candidateCD = (ClassDesc)iterator.next();
ClassDesc referenceCD =
referencePD.getClassDesc(candidateCD.getName());
if (referenceCD != null)
{
iterator.remove();
}
}
}
/*
This method will return the correct name for a class object representing
a primitive, a single instance of a class, as well as n-dimensional arrays
of primitives or instances. This logic is needed to handle the string returned
from Class.getName(). If the class object represents a single instance (or
a primitive), Class.getName() returns the fully-qualified name of the class
and no further work is needed. However, if the class object represents an
array (of n dimensions), Class.getName() returns a Descriptor (the Descriptor
grammar is defined in section 4.3 of the Java VM Spec). This method will
parse the Descriptor if necessary.
*/
public static String getClassName(Class targetClass)
{
String className = targetClass.getName();
return targetClass.isArray() ? parseDescriptor(className) : className;
}
/*
See the comment above for getClassName(targetClass)...
*/
private static String parseDescriptor(String className)
{
char[] classNameChars = className.toCharArray();
int arrayDim = 0;
int i = 0;
while (classNameChars[i] == '[')
{
arrayDim++;
i++;
}
StringBuffer classNameBuf = new StringBuffer();
switch (classNameChars[i++])
{
case 'B' : classNameBuf.append("byte");
break;
case 'C' : classNameBuf.append("char");
break;
case 'D' : classNameBuf.append("double");
break;
case 'F' : classNameBuf.append("float");
break;
case 'I' : classNameBuf.append("int");
break;
case 'J' : classNameBuf.append("long");
break;
case 'S' : classNameBuf.append("short");
break;
case 'Z' : classNameBuf.append("boolean");
break;
case 'L' : classNameBuf.append(classNameChars,
i, classNameChars.length - i - 1);
break;
}
for (i = 0; i < arrayDim; i++)
classNameBuf.append("[]");
return classNameBuf.toString();
}
private static OutputStream getOutputStream(String root,
String name,
boolean overwrite,
boolean verbose)
throws IOException
{
if (root != null)
{
File directory = new File(root);
if (!directory.exists())
{
if (!directory.mkdirs())
{
throw new IOException("Failed to create directory '" + root + "'.");
}
else if (verbose)
{
System.out.println("Created directory '" +
directory.getAbsolutePath() + "'.");
}
}
}
File file = new File(root, name);
String absolutePath = file.getAbsolutePath();
if (file.exists())
{
if (!overwrite)
{
throw new IOException("File '" + absolutePath + "' already exists. " +
"Please remove it or enable the " +
"overwrite option.");
}
else
{
file.delete();
if (verbose)
{
System.out.println("Deleted file '" + absolutePath + "'.");
}
}
}
FileOutputStream fos = new FileOutputStream(absolutePath);
if (verbose)
{
System.out.println("Created file '" + absolutePath + "'.");
}
return fos;
}
public static void generateProjectFile(String classListFile,
String projectFile,
boolean overwrite)
throws IOException,
ClassNotFoundException
{
FileReader in = new FileReader(classListFile);
BufferedReader buf = new BufferedReader(in);
OutputStream out = getOutputStream(null, projectFile, overwrite, true);
PrintWriter pw = new PrintWriter(out);
String tempLine;
while ((tempLine = buf.readLine()) != null)
{
pw.println(getClassDesc(Class.forName(tempLine)));
}
pw.flush();
pw.close();
buf.close();
in.close();
}
}

View File

@ -0,0 +1,497 @@
1 javax.usb.UsbAbortException extends javax.usb.UsbException
{
1 javax.usb.UsbAbortException (java.lang.String)
1 javax.usb.UsbAbortException ()
}
1 javax.usb.UsbBabbleException extends javax.usb.UsbException
{
1 javax.usb.UsbBabbleException (java.lang.String)
1 javax.usb.UsbBabbleException ()
}
1 javax.usb.UsbBitStuffException extends javax.usb.UsbException
{
1 javax.usb.UsbBitStuffException (java.lang.String)
1 javax.usb.UsbBitStuffException ()
}
1 javax.usb.UsbClaimException extends javax.usb.UsbException
{
1 javax.usb.UsbClaimException (java.lang.String)
1 javax.usb.UsbClaimException ()
}
1537 javax.usb.UsbConfiguration
{
1025 boolean isActive ()
1025 java.util.List getUsbInterfaces ()
1025 javax.usb.UsbInterface getUsbInterface (byte)
1025 boolean containsUsbInterface (byte)
1025 javax.usb.UsbDevice getUsbDevice ()
1025 javax.usb.UsbConfigurationDescriptor getUsbConfigurationDescriptor ()
1025 java.lang.String getConfigurationString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
}
1537 javax.usb.UsbConfigurationDescriptor implements javax.usb.UsbDescriptor
{
1025 short wTotalLength ()
1025 byte bNumInterfaces ()
1025 byte bConfigurationValue ()
1025 byte iConfiguration ()
1025 byte bmAttributes ()
1025 byte bMaxPower ()
}
1537 javax.usb.UsbConst
{
}
1537 javax.usb.UsbControlIrp implements javax.usb.UsbIrp
{
1025 byte bmRequestType ()
1025 byte bRequest ()
1025 short wValue ()
1025 short wIndex ()
}
1 javax.usb.UsbCRCException extends javax.usb.UsbException
{
1 javax.usb.UsbCRCException (java.lang.String)
1 javax.usb.UsbCRCException ()
}
1537 javax.usb.UsbDescriptor
{
1025 byte bLength ()
1025 byte bDescriptorType ()
}
1537 javax.usb.UsbDevice
{
1025 javax.usb.UsbPort getParentUsbPort () throws javax.usb.UsbDisconnectedException
1025 boolean isUsbHub ()
1025 java.lang.String getManufacturerString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
1025 java.lang.String getSerialNumberString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
1025 java.lang.String getProductString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
1025 java.lang.Object getSpeed ()
1025 java.util.List getUsbConfigurations ()
1025 javax.usb.UsbConfiguration getUsbConfiguration (byte)
1025 boolean containsUsbConfiguration (byte)
1025 byte getActiveUsbConfigurationNumber ()
1025 javax.usb.UsbConfiguration getActiveUsbConfiguration ()
1025 boolean isConfigured ()
1025 javax.usb.UsbDeviceDescriptor getUsbDeviceDescriptor ()
1025 javax.usb.UsbStringDescriptor getUsbStringDescriptor (byte) throws javax.usb.UsbException,javax.usb.UsbDisconnectedException
1025 java.lang.String getString (byte) throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
1025 void syncSubmit (javax.usb.UsbControlIrp) throws javax.usb.UsbException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void asyncSubmit (javax.usb.UsbControlIrp) throws javax.usb.UsbException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void syncSubmit (java.util.List) throws javax.usb.UsbException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void asyncSubmit (java.util.List) throws javax.usb.UsbException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 javax.usb.UsbControlIrp createUsbControlIrp (byte,byte,short,short)
1025 void addUsbDeviceListener (javax.usb.event.UsbDeviceListener)
1025 void removeUsbDeviceListener (javax.usb.event.UsbDeviceListener)
}
1537 javax.usb.UsbDeviceDescriptor implements javax.usb.UsbDescriptor
{
1025 short bcdUSB ()
1025 byte bDeviceClass ()
1025 byte bDeviceSubClass ()
1025 byte bDeviceProtocol ()
1025 byte bMaxPacketSize0 ()
1025 short idVendor ()
1025 short idProduct ()
1025 short bcdDevice ()
1025 byte iManufacturer ()
1025 byte iProduct ()
1025 byte iSerialNumber ()
1025 byte bNumConfigurations ()
}
1 javax.usb.UsbDisconnectedException extends java.lang.RuntimeException
{
1 javax.usb.UsbDisconnectedException (java.lang.String)
1 javax.usb.UsbDisconnectedException ()
}
1537 javax.usb.UsbEndpoint
{
1025 javax.usb.UsbInterface getUsbInterface ()
1025 javax.usb.UsbEndpointDescriptor getUsbEndpointDescriptor ()
1025 byte getDirection ()
1025 byte getType ()
1025 javax.usb.UsbPipe getUsbPipe ()
}
1537 javax.usb.UsbEndpointDescriptor implements javax.usb.UsbDescriptor
{
1025 byte bEndpointAddress ()
1025 byte bmAttributes ()
1025 short wMaxPacketSize ()
1025 byte bInterval ()
}
1 javax.usb.UsbException extends java.lang.Exception
{
1 javax.usb.UsbException (java.lang.String)
1 javax.usb.UsbException ()
}
17 javax.usb.UsbHostManager extends java.lang.Object
{
2 javax.usb.UsbHostManager ()
9 javax.usb.UsbServices getUsbServices () throws javax.usb.UsbException,java.lang.SecurityException
9 java.util.Properties getProperties () throws javax.usb.UsbException,java.lang.SecurityException
10 javax.usb.UsbServices createUsbServices () throws javax.usb.UsbException,java.lang.SecurityException
10 void setupProperties () throws javax.usb.UsbException,java.lang.SecurityException
26 java.lang.String USBSERVICES_PROPERTY_NOT_DEFINED ()
26 java.lang.String USBSERVICES_CLASSNOTFOUNDEXCEPTION (java.lang.String)
26 java.lang.String USBSERVICES_EXCEPTIONININITIALIZERERROR (java.lang.String)
26 java.lang.String USBSERVICES_INSTANTIATIONEXCEPTION (java.lang.String)
26 java.lang.String USBSERVICES_ILLEGALACCESSEXCEPTION (java.lang.String)
26 java.lang.String USBSERVICES_CLASSCASTEXCEPTION (java.lang.String)
}
1537 javax.usb.UsbHub implements javax.usb.UsbDevice
{
1025 byte getNumberOfPorts ()
1025 java.util.List getUsbPorts ()
1025 javax.usb.UsbPort getUsbPort (byte)
1025 java.util.List getAttachedUsbDevices ()
1025 boolean isRootUsbHub ()
}
1537 javax.usb.UsbInterface
{
1025 void claim () throws javax.usb.UsbClaimException,javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbDisconnectedException
1025 void claim (javax.usb.UsbInterfacePolicy) throws javax.usb.UsbClaimException,javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbDisconnectedException
1025 void release () throws javax.usb.UsbClaimException,javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbDisconnectedException
1025 boolean isClaimed ()
1025 boolean isActive ()
1025 int getNumSettings ()
1025 byte getActiveSettingNumber () throws javax.usb.UsbNotActiveException
1025 javax.usb.UsbInterface getActiveSetting () throws javax.usb.UsbNotActiveException
1025 javax.usb.UsbInterface getSetting (byte)
1025 boolean containsSetting (byte)
1025 java.util.List getSettings ()
1025 java.util.List getUsbEndpoints ()
1025 javax.usb.UsbEndpoint getUsbEndpoint (byte)
1025 boolean containsUsbEndpoint (byte)
1025 javax.usb.UsbConfiguration getUsbConfiguration ()
1025 javax.usb.UsbInterfaceDescriptor getUsbInterfaceDescriptor ()
1025 java.lang.String getInterfaceString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException,javax.usb.UsbDisconnectedException
}
1537 javax.usb.UsbInterfaceDescriptor implements javax.usb.UsbDescriptor
{
1025 byte bInterfaceNumber ()
1025 byte bAlternateSetting ()
1025 byte bNumEndpoints ()
1025 byte bInterfaceClass ()
1025 byte bInterfaceSubClass ()
1025 byte bInterfaceProtocol ()
1025 byte iInterface ()
}
1537 javax.usb.UsbInterfacePolicy
{
1025 boolean forceClaim (javax.usb.UsbInterface)
}
1537 javax.usb.UsbIrp
{
1025 byte[] getData ()
1025 int getOffset ()
1025 int getLength ()
1025 int getActualLength ()
1025 void setData (byte[])
1025 void setData (byte[],int,int)
1025 void setOffset (int)
1025 void setLength (int)
1025 void setActualLength (int)
1025 boolean isUsbException ()
1025 javax.usb.UsbException getUsbException ()
1025 void setUsbException (javax.usb.UsbException)
1025 boolean getAcceptShortPacket ()
1025 void setAcceptShortPacket (boolean)
1025 boolean isComplete ()
1025 void setComplete (boolean)
1025 void complete ()
1025 void waitUntilComplete ()
1025 void waitUntilComplete (long)
}
1 javax.usb.UsbNativeClaimException extends javax.usb.UsbClaimException
{
1 javax.usb.UsbNativeClaimException (java.lang.String)
1 javax.usb.UsbNativeClaimException ()
}
1 javax.usb.UsbNotActiveException extends java.lang.RuntimeException
{
1 javax.usb.UsbNotActiveException (java.lang.String)
1 javax.usb.UsbNotActiveException ()
}
1 javax.usb.UsbNotClaimedException extends java.lang.RuntimeException
{
1 javax.usb.UsbNotClaimedException (java.lang.String)
1 javax.usb.UsbNotClaimedException ()
}
1 javax.usb.UsbNotOpenException extends java.lang.RuntimeException
{
1 javax.usb.UsbNotOpenException (java.lang.String)
1 javax.usb.UsbNotOpenException ()
}
1 javax.usb.UsbPIDException extends javax.usb.UsbException
{
1 javax.usb.UsbPIDException (java.lang.String)
1 javax.usb.UsbPIDException ()
}
1537 javax.usb.UsbPipe
{
1025 void open () throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotClaimedException,javax.usb.UsbDisconnectedException
1025 void close () throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,javax.usb.UsbDisconnectedException
1025 boolean isActive ()
1025 boolean isOpen ()
1025 javax.usb.UsbEndpoint getUsbEndpoint ()
1025 int syncSubmit (byte[]) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 javax.usb.UsbIrp asyncSubmit (byte[]) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void syncSubmit (javax.usb.UsbIrp) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void asyncSubmit (javax.usb.UsbIrp) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void syncSubmit (java.util.List) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void asyncSubmit (java.util.List) throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,java.lang.IllegalArgumentException,javax.usb.UsbDisconnectedException
1025 void abortAllSubmissions () throws javax.usb.UsbNotActiveException,javax.usb.UsbNotOpenException,javax.usb.UsbDisconnectedException
1025 javax.usb.UsbIrp createUsbIrp ()
1025 javax.usb.UsbControlIrp createUsbControlIrp (byte,byte,short,short)
1025 void addUsbPipeListener (javax.usb.event.UsbPipeListener)
1025 void removeUsbPipeListener (javax.usb.event.UsbPipeListener)
}
1 javax.usb.UsbPlatformException extends javax.usb.UsbException
{
1 javax.usb.UsbPlatformException (java.lang.String,int,java.lang.Exception)
1 javax.usb.UsbPlatformException (int,java.lang.Exception)
1 javax.usb.UsbPlatformException (java.lang.String,java.lang.Exception)
1 javax.usb.UsbPlatformException (java.lang.String,int)
1 javax.usb.UsbPlatformException (java.lang.Exception)
1 javax.usb.UsbPlatformException (int)
1 javax.usb.UsbPlatformException (java.lang.String)
1 javax.usb.UsbPlatformException ()
1 java.lang.Exception getPlatformException ()
1 int getErrorCode ()
}
1537 javax.usb.UsbPort
{
1025 byte getPortNumber ()
1025 javax.usb.UsbHub getUsbHub ()
1025 javax.usb.UsbDevice getUsbDevice ()
1025 boolean isUsbDeviceAttached ()
}
1537 javax.usb.UsbServices
{
1025 javax.usb.UsbHub getRootUsbHub () throws javax.usb.UsbException,java.lang.SecurityException
1025 void addUsbServicesListener (javax.usb.event.UsbServicesListener)
1025 void removeUsbServicesListener (javax.usb.event.UsbServicesListener)
1025 java.lang.String getApiVersion ()
1025 java.lang.String getImpVersion ()
1025 java.lang.String getImpDescription ()
}
1 javax.usb.UsbShortPacketException extends javax.usb.UsbException
{
1 javax.usb.UsbShortPacketException (java.lang.String)
1 javax.usb.UsbShortPacketException ()
}
1 javax.usb.UsbStallException extends javax.usb.UsbException
{
1 javax.usb.UsbStallException (java.lang.String)
1 javax.usb.UsbStallException ()
}
1537 javax.usb.UsbStringDescriptor implements javax.usb.UsbDescriptor
{
1025 byte[] bString ()
1025 java.lang.String getString () throws java.io.UnsupportedEncodingException
}
1 javax.usb.Version extends java.lang.Object
{
1 javax.usb.Version ()
9 void main (java.lang.String[])
9 java.lang.String getApiVersion ()
9 java.lang.String getUsbVersion ()
}
1 javax.usb.event.UsbDeviceDataEvent extends javax.usb.event.UsbDeviceEvent
{
1 javax.usb.event.UsbDeviceDataEvent (javax.usb.UsbDevice,javax.usb.UsbControlIrp)
1 byte[] getData ()
1 javax.usb.UsbControlIrp getUsbControlIrp ()
}
1 javax.usb.event.UsbDeviceErrorEvent extends javax.usb.event.UsbDeviceEvent
{
1 javax.usb.event.UsbDeviceErrorEvent (javax.usb.UsbDevice,javax.usb.UsbControlIrp)
1 javax.usb.UsbException getUsbException ()
1 javax.usb.UsbControlIrp getUsbControlIrp ()
}
1 javax.usb.event.UsbDeviceEvent extends java.util.EventObject
{
1 javax.usb.event.UsbDeviceEvent (javax.usb.UsbDevice)
1 javax.usb.UsbDevice getUsbDevice ()
}
1537 javax.usb.event.UsbDeviceListener implements java.util.EventListener
{
1025 void usbDeviceDetached (javax.usb.event.UsbDeviceEvent)
1025 void errorEventOccurred (javax.usb.event.UsbDeviceErrorEvent)
1025 void dataEventOccurred (javax.usb.event.UsbDeviceDataEvent)
}
1 javax.usb.event.UsbPipeDataEvent extends javax.usb.event.UsbPipeEvent
{
1 javax.usb.event.UsbPipeDataEvent (javax.usb.UsbPipe,javax.usb.UsbIrp)
1 javax.usb.event.UsbPipeDataEvent (javax.usb.UsbPipe,byte[],int)
1 byte[] getData ()
1 int getActualLength ()
}
1 javax.usb.event.UsbPipeErrorEvent extends javax.usb.event.UsbPipeEvent
{
1 javax.usb.event.UsbPipeErrorEvent (javax.usb.UsbPipe,javax.usb.UsbIrp)
1 javax.usb.event.UsbPipeErrorEvent (javax.usb.UsbPipe,javax.usb.UsbException)
1 javax.usb.UsbException getUsbException ()
}
1 javax.usb.event.UsbPipeEvent extends java.util.EventObject
{
1 javax.usb.event.UsbPipeEvent (javax.usb.UsbPipe,javax.usb.UsbIrp)
1 javax.usb.event.UsbPipeEvent (javax.usb.UsbPipe)
1 javax.usb.UsbPipe getUsbPipe ()
1 boolean hasUsbIrp ()
1 javax.usb.UsbIrp getUsbIrp ()
}
1537 javax.usb.event.UsbPipeListener implements java.util.EventListener
{
1025 void errorEventOccurred (javax.usb.event.UsbPipeErrorEvent)
1025 void dataEventOccurred (javax.usb.event.UsbPipeDataEvent)
}
1 javax.usb.event.UsbServicesEvent extends java.util.EventObject
{
1 javax.usb.event.UsbServicesEvent (javax.usb.UsbServices,javax.usb.UsbDevice)
1 javax.usb.UsbServices getUsbServices ()
1 javax.usb.UsbDevice getUsbDevice ()
}
1537 javax.usb.event.UsbServicesListener implements java.util.EventListener
{
1025 void usbDeviceAttached (javax.usb.event.UsbServicesEvent)
1025 void usbDeviceDetached (javax.usb.event.UsbServicesEvent)
}
1 javax.usb.util.DefaultUsbControlIrp extends javax.usb.util.DefaultUsbIrp implements javax.usb.UsbControlIrp
{
1 javax.usb.util.DefaultUsbControlIrp (byte[],int,int,boolean,byte,byte,short,short)
1 javax.usb.util.DefaultUsbControlIrp (byte,byte,short,short)
1 byte bmRequestType ()
1 byte bRequest ()
1 short wValue ()
1 short wIndex ()
1 short wLength ()
}
1 javax.usb.util.DefaultUsbIrp extends java.lang.Object implements javax.usb.UsbIrp
{
1 javax.usb.util.DefaultUsbIrp (byte[],int,int,boolean)
1 javax.usb.util.DefaultUsbIrp (byte[])
1 javax.usb.util.DefaultUsbIrp ()
1 byte[] getData ()
1 int getOffset ()
1 int getLength ()
1 int getActualLength ()
1 void setData (byte[],int,int) throws java.lang.IllegalArgumentException
1 void setData (byte[]) throws java.lang.IllegalArgumentException
1 void setOffset (int) throws java.lang.IllegalArgumentException
1 void setLength (int) throws java.lang.IllegalArgumentException
1 void setActualLength (int) throws java.lang.IllegalArgumentException
1 boolean isUsbException ()
1 javax.usb.UsbException getUsbException ()
1 void setUsbException (javax.usb.UsbException)
1 boolean getAcceptShortPacket ()
1 void setAcceptShortPacket (boolean)
1 boolean isComplete ()
1 void setComplete (boolean)
1 void complete ()
1 void waitUntilComplete ()
1 void waitUntilComplete (long)
}
1 javax.usb.util.StandardRequest extends java.lang.Object
{
1 javax.usb.util.StandardRequest (javax.usb.UsbDevice)
1 void clearFeature (byte,short,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
1 byte getConfiguration () throws javax.usb.UsbException
1 int getDescriptor (byte,byte,short,byte[]) throws javax.usb.UsbException
1 byte getInterface (short) throws javax.usb.UsbException
1 short getStatus (byte,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
1 void setAddress (short) throws javax.usb.UsbException
1 void setConfiguration (short) throws javax.usb.UsbException
1 int setDescriptor (byte,byte,short,byte[]) throws javax.usb.UsbException
1 void setFeature (byte,short,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
1 void setInterface (short,short) throws javax.usb.UsbException
1 short synchFrame (short) throws javax.usb.UsbException
9 void clearFeature (javax.usb.UsbDevice,byte,short,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
9 byte getConfiguration (javax.usb.UsbDevice) throws javax.usb.UsbException
9 int getDescriptor (javax.usb.UsbDevice,byte,byte,short,byte[]) throws javax.usb.UsbException
9 byte getInterface (javax.usb.UsbDevice,short) throws javax.usb.UsbException
9 short getStatus (javax.usb.UsbDevice,byte,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
9 void setAddress (javax.usb.UsbDevice,short) throws javax.usb.UsbException
9 void setConfiguration (javax.usb.UsbDevice,short) throws javax.usb.UsbException
9 int setDescriptor (javax.usb.UsbDevice,byte,byte,short,byte[]) throws javax.usb.UsbException
9 void setFeature (javax.usb.UsbDevice,byte,short,short) throws javax.usb.UsbException,java.lang.IllegalArgumentException
9 void setInterface (javax.usb.UsbDevice,short,short) throws javax.usb.UsbException
9 short synchFrame (javax.usb.UsbDevice,short) throws javax.usb.UsbException
12 void checkRecipient (byte) throws java.lang.IllegalArgumentException
}
1 javax.usb.util.UsbUtil extends java.lang.Object
{
1 javax.usb.util.UsbUtil ()
9 short unsignedShort (byte)
9 int unsignedInt (byte)
9 int unsignedInt (short)
9 long unsignedLong (byte)
9 long unsignedLong (short)
9 long unsignedLong (int)
9 short toShort (byte,byte)
9 int toInt (byte,byte,byte,byte)
9 long toLong (byte,byte,byte,byte,byte,byte,byte,byte)
9 int toInt (short,short)
9 long toLong (short,short,short,short)
9 long toLong (int,int)
9 java.lang.String toHexString (byte)
9 java.lang.String toHexString (short)
9 java.lang.String toHexString (int)
9 java.lang.String toHexString (long)
9 java.lang.String toHexString (long,char,int,int)
9 java.lang.String toHexString (java.lang.String,byte[],int)
9 java.lang.String toHexString (java.lang.String,short[],int)
9 java.lang.String toHexString (java.lang.String,int[],int)
9 java.lang.String toHexString (java.lang.String,long[],int)
9 java.lang.String toHexString (java.lang.String,byte[])
9 java.lang.String toHexString (java.lang.String,short[])
9 java.lang.String toHexString (java.lang.String,int[])
9 java.lang.String toHexString (java.lang.String,long[])
9 java.lang.String getSpeedString (java.lang.Object)
9 javax.usb.UsbDevice synchronizedUsbDevice (javax.usb.UsbDevice)
9 javax.usb.UsbPipe synchronizedUsbPipe (javax.usb.UsbPipe)
}
9 javax.usb.util.UsbUtil$SynchronizedUsbDevice extends java.lang.Object implements javax.usb.UsbDevice
{
1 javax.usb.util.UsbUtil$SynchronizedUsbDevice (javax.usb.UsbDevice)
1 javax.usb.UsbPort getParentUsbPort ()
1 boolean isUsbHub ()
1 java.lang.String getManufacturerString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException
1 java.lang.String getSerialNumberString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException
1 java.lang.String getProductString () throws javax.usb.UsbException,java.io.UnsupportedEncodingException
1 java.lang.Object getSpeed ()
1 java.util.List getUsbConfigurations ()
1 javax.usb.UsbConfiguration getUsbConfiguration (byte)
1 boolean containsUsbConfiguration (byte)
1 byte getActiveUsbConfigurationNumber ()
1 javax.usb.UsbConfiguration getActiveUsbConfiguration ()
1 boolean isConfigured ()
1 javax.usb.UsbDeviceDescriptor getUsbDeviceDescriptor ()
1 javax.usb.UsbStringDescriptor getUsbStringDescriptor (byte) throws javax.usb.UsbException
1 java.lang.String getString (byte) throws javax.usb.UsbException,java.io.UnsupportedEncodingException
1 void syncSubmit (javax.usb.UsbControlIrp) throws javax.usb.UsbException
1 void asyncSubmit (javax.usb.UsbControlIrp) throws javax.usb.UsbException
1 void syncSubmit (java.util.List) throws javax.usb.UsbException
1 void asyncSubmit (java.util.List) throws javax.usb.UsbException
1 javax.usb.UsbControlIrp createUsbControlIrp (byte,byte,short,short)
1 void addUsbDeviceListener (javax.usb.event.UsbDeviceListener)
1 void removeUsbDeviceListener (javax.usb.event.UsbDeviceListener)
}
9 javax.usb.util.UsbUtil$SynchronizedUsbPipe extends java.lang.Object implements javax.usb.UsbPipe
{
1 javax.usb.util.UsbUtil$SynchronizedUsbPipe (javax.usb.UsbPipe)
1 void open () throws javax.usb.UsbException,javax.usb.UsbNotActiveException,javax.usb.UsbNotClaimedException
1 void close () throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 boolean isActive ()
1 boolean isOpen ()
1 javax.usb.UsbEndpoint getUsbEndpoint ()
1 int syncSubmit (byte[]) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 javax.usb.UsbIrp asyncSubmit (byte[]) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 void syncSubmit (javax.usb.UsbIrp) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 void asyncSubmit (javax.usb.UsbIrp) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 void syncSubmit (java.util.List) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 void asyncSubmit (java.util.List) throws javax.usb.UsbException,javax.usb.UsbNotOpenException
1 void abortAllSubmissions () throws javax.usb.UsbNotOpenException
1 javax.usb.UsbIrp createUsbIrp ()
1 javax.usb.UsbControlIrp createUsbControlIrp (byte,byte,short,short)
1 void addUsbPipeListener (javax.usb.event.UsbPipeListener)
1 void removeUsbPipeListener (javax.usb.event.UsbPipeListener)
}

View File

@ -0,0 +1 @@
javax.usb.services = de.ailis.usb4java.Services