From 10bd83cc88f8a15d6d9cd8ef04cf774c2dc585ea Mon Sep 17 00:00:00 2001 From: Klaus Reimer Date: Sun, 24 Feb 2013 16:31:06 +0100 Subject: [PATCH] Add bulk IO error conditions tests --- .../usb/tck/BulkIOErrorConditionsTest.java | 130 +++ .../javax/usb/tck/IOErrorConditionsTest.java | 982 ++++++++++++++++++ 2 files changed, 1112 insertions(+) create mode 100755 src/test/java/javax/usb/tck/BulkIOErrorConditionsTest.java create mode 100755 src/test/java/javax/usb/tck/IOErrorConditionsTest.java diff --git a/src/test/java/javax/usb/tck/BulkIOErrorConditionsTest.java b/src/test/java/javax/usb/tck/BulkIOErrorConditionsTest.java new file mode 100755 index 0000000..51d9ecd --- /dev/null +++ b/src/test/java/javax/usb/tck/BulkIOErrorConditionsTest.java @@ -0,0 +1,130 @@ +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 040916 raulortz Redesign TCK to create base and optional + * tests. Separate setConfig, setInterface + * and isochronous transfers as optionals. + */ + +//import java.util.*; +import javax.usb.*; + +import org.junit.runner.RunWith; + +import de.ailis.usb4java.TCKRunner; +//import javax.usb.util.*; + +import junit.framework.TestCase; + +/** + * IO Error conditions + *

+ * This test verifies that error conditions are generated and proper + * exceptions are thrown in the operation. + * + * @author Thanh Ngo + */ + +@SuppressWarnings("all") +@RunWith(TCKRunner.class) +public class BulkIOErrorConditionsTest extends TestCase +{ + //------------------------------------------------------------------------- + // Ctor(s) + // + + + public BulkIOErrorConditionsTest() + { + thisTest = new IOErrorConditionsTest(UsbConst.ENDPOINT_TYPE_BULK); + } + + //------------------------------------------------------------------------- + // Protected overridden methods + // + + protected void setUp() throws Exception { + thisTest.setUp(); + + } + + protected void tearDown() throws Exception { + thisTest.tearDown(); + } + + + + /** + * Null Data Buffer + */ + public void testNullDataBufferInIrp() + { + thisTest.testNullDataBufferInIrp(); + } + /** + * Null Data Buffer + */ + public void testNullDataBufferAsByteArray() + { + thisTest.testNullDataBufferAsByteArray(); + } + + /** + * Action against a closed pipe + */ + public void testActionAgainstClosePipeAbortAllSubmissions() + { + thisTest.testActionAgainstClosePipeAbortAllSubmissions(); + } + /** + * Action against a closed pipe + */ + public void testActionAgainstClosePipeSubmit() + { + thisTest.testActionAgainstClosePipeSubmit(); + } + + /** + * Close a pipe with pending operation + */ + public void testClosePipePendingAction() + { + thisTest.testClosePipePendingAction(); + } + + // Moved method testOpenPipeOnInactiveAlternateSetting into the optional setInterface tests @P1D7 + + /** + * Open a pipe on an unclaimed interface + */ + public void testOpenPipeOnUnclaimedInterface() + { + thisTest.testOpenPipeOnUnclaimedInterface(); + } + + /** + * Claim an already claimed interface + */ + public void testClaimAnAlreadyClaimedInterface() + { + thisTest.testClaimAnAlreadyClaimedInterface(); + + } + + + private IOErrorConditionsTest thisTest = null; +} diff --git a/src/test/java/javax/usb/tck/IOErrorConditionsTest.java b/src/test/java/javax/usb/tck/IOErrorConditionsTest.java new file mode 100755 index 0000000..32e191d --- /dev/null +++ b/src/test/java/javax/usb/tck/IOErrorConditionsTest.java @@ -0,0 +1,982 @@ +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 040916 raulortz Redesign TCK to create base and optional + * tests. Separate setConfig, setInterface + * and isochronous transfers as optionals. + */ + +import java.util.*; +import javax.usb.*; +import javax.usb.util.*; + +import org.junit.Ignore; + +import junit.framework.TestCase; + +/** + * IO Error conditions + *

+ * This test verifies that error conditions are generated and proper + * exceptions are thrown in the operation. + * + * @author Thanh Ngo + */ + +@SuppressWarnings("all") +@Ignore("These tests are triggered by other tests and must not run directly") +public class IOErrorConditionsTest extends TestCase +{ + //------------------------------------------------------------------------- + // Ctor(s) + // + + public IOErrorConditionsTest(String name) + { + super(name); + } + public IOErrorConditionsTest(int typeOfTest) + { + testType = typeOfTest; + } + + //------------------------------------------------------------------------- + // Protected overridden methods + // + + protected void setUp() throws Exception { + printDebug("setUp"); + + + usbDevice = programmableDevice.getProgrammableDevice(); + assertTrue("Find Programmable board Failed! Got a null instance", + usbDevice != null); + + + super.setUp(); + } + + protected void tearDown() throws Exception { + printDebug("tearDown"); + try // @P1A + { // @P1A + if ( (outPipe!=null)&&(outPipe.isOpen()) ) // @P1C + { // @P1C + outPipe.abortAllSubmissions(); // @P1C + IOMethods.closePipe(outPipe); // @P1C + } // @P1C + if ( (inPipe!=null)&&(inPipe.isOpen()) ) // @P1C + { // @P1C + inPipe.abortAllSubmissions(); // @P1C + IOMethods.closePipe(inPipe); // @P1C + } // @P1C + if ( (myIface!=null)&&(myIface.isClaimed()) ) // @P1C + { // @P1C + IOMethods.releaseInterface(myIface); // @P1C + } // @P1C + } catch ( UsbDisconnectedException uDE ) // @P1A + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } // @P1A + + super.tearDown(); + } + + //------------------------------------------------------------------------- + // Public testXyz() methods + // + + /** + * Null Data Buffer + */ + public void testNullDataBufferInIrp() + { + printDebug("testNullDataBufferInIrp"); + if ( testType == bulkTest ) + { + doTestNullDataBufferInIrp(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + + doTestNullDataBufferInIrp(UsbConst.ENDPOINT_TYPE_INTERRUPT); + + } else if ( testType == isochronousTest ) + { + doTestNullDataBufferInIrp(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + } + /** + * Null Data Buffer + */ + public void testNullDataBufferAsByteArray() + { + printDebug("testNullDataBufferAsByteArray"); + if ( testType == bulkTest ) + { + doTestNullDataBufferAsByteArray(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestNullDataBufferAsByteArray(UsbConst.ENDPOINT_TYPE_INTERRUPT); + + } else if ( testType == isochronousTest ) + { + doTestNullDataBufferAsByteArray(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + } + + /** + * Action against a closed pipe + */ + public void testActionAgainstClosePipeAbortAllSubmissions() + { + printDebug("testActionAgainstClosePipeAbortAllSubmissions"); + if ( testType == bulkTest ) + { + + doTestActionAgainstClosePipeAbortAllSubmissions(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestActionAgainstClosePipeAbortAllSubmissions(UsbConst.ENDPOINT_TYPE_INTERRUPT); + } else if ( testType == isochronousTest ) + { + doTestActionAgainstClosePipeAbortAllSubmissions(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + + + } + /** + * Action against a closed pipe + */ + public void testActionAgainstClosePipeSubmit() + { + printDebug("testActionAgainstClosePipeSubmit"); + if ( testType == bulkTest ) + { + + doTestActionAgainstClosePipeSubmit(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestActionAgainstClosePipeSubmit(UsbConst.ENDPOINT_TYPE_INTERRUPT); + } else if ( testType == isochronousTest ) + { + doTestActionAgainstClosePipeSubmit(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + + + } + + /** + * Close a pipe with pending operation + */ + public void testClosePipePendingAction() + + { + printDebug("testClosePipePendingAction"); + if ( testType == bulkTest ) + { + doTestClosePipePendingAction(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestClosePipePendingAction(UsbConst.ENDPOINT_TYPE_INTERRUPT); + } else if ( testType == isochronousTest ) + { + doTestClosePipePendingAction(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + + + } + + /** + * Open a pipe on an inactive interface + */ + public void testOpenPipeOnInactiveAlternateSetting() + { + printDebug("testOpenPipeOnInactiveAlternateSetting"); + if ( testType == bulkTest ) + { + + doTestOpenPipeOnInactiveAlternateSetting(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestOpenPipeOnInactiveAlternateSetting(UsbConst.ENDPOINT_TYPE_INTERRUPT); + } else if ( testType == isochronousTest ) + { + doTestOpenPipeOnInactiveAlternateSetting(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + } + + /** + * Open a pipe on an unclaimed interface + */ + public void testOpenPipeOnUnclaimedInterface() + { + printDebug("testOpenPipeOnUnclaimedInterface"); + if ( testType == bulkTest ) + { + + doTestOpenPipeOnUnclaimedInterface(UsbConst.ENDPOINT_TYPE_BULK); + } else if ( testType == intTest ) + { + doTestOpenPipeOnUnclaimedInterface(UsbConst.ENDPOINT_TYPE_INTERRUPT); + } else if ( testType == isochronousTest ) + { + doTestOpenPipeOnUnclaimedInterface(UsbConst.ENDPOINT_TYPE_ISOCHRONOUS); + } else + { + fail("Test is defined for only bulk and isochronous endpoints."); + } + + } + + /** + * Claim an already claimed interface + */ + public void testClaimAnAlreadyClaimedInterface() + { + printDebug("testClaimAnAlreadyClaimedInterface"); + + + myIface = null; + boolean usbe = false; + + if ( usbDevice.isConfigured() ) + { + UsbConfiguration usbConfiguration = + usbDevice.getUsbConfiguration((byte) 1); + myIface = usbConfiguration.getUsbInterface((byte) 0); + + //claim the interface + IOMethods.claimInterface(myIface); + + try + { + assertTrue("in doTestClaimAnAlreadyClaimedInterface() --isClaimed() should == true): ", + myIface.isClaimed()); + myIface.claim(); + fail("should caused UsbClaimException!"); + } catch ( UsbClaimException uce ) + { + + usbe = true; + } catch ( UsbException ue ) + { + fail("UsbClaimException expected. unexpected UsbException!" + ue); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail("UsbClaimException expected. unexpected Exception" + e); + } + + if ( !usbe ) + assertTrue("Test Claim an already claimed interface did not throw UsbNotClaimedException!", false); + + } else + { + fail("device is not configured!"); + } + + + + } + +// /** +// * Claim an inactive interface +// */ +// public void testClaimAnInactiveInterface() +// { +// boolean usbe = false; +// UsbInterface inActiveInterface = getInactiveInterface(); +// if ( null == inActiveInterface ) +// { +// fail("could not locate an inactive interface to test!"); +// } +// try +// { +// inActiveInterface.claim(); +// fail("should throw Exception when claim an inactive interface!"); +// } +// catch ( UsbClaimException uce ) +// { +// } +// catch ( UsbException ue ) +// { +// } +// catch ( UsbNotActiveException unae ) +// { +// } +// } + + + /** + * private functions + */ + + /** + * Test error conditions -- Null Data Buffer + */ + private void doTestNullDataBufferAsByteArray(int endpointType) + { + outPipe = null; + UsbEndpoint outEndpoint = null; + + //UsbInterface myIface = null; + UsbIrp usbIrp = null; + boolean usbe = false; + + + if ( usbDevice.isConfigured() ) + { + + outEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_OUT); + + assertFalse("could not find output endpoint", null == outEndpoint); + + // @P2D4 + assertTrue("Interface was not claimed!", myIface.isClaimed()); + + //we have an endpoint; now try submitting a null byte array and an IRP + //with a null data + + outPipe = outEndpoint.getUsbPipe(); + assertTrue("output pipe is not active!!!", outPipe.isActive()); + IOMethods.openPipe(outPipe); + + //submit null byte array + byte [] nullBuffer = null; + try + { + outPipe.syncSubmit(nullBuffer); + fail("Expected a UsbException when submitting a null byte array."); + } catch ( IllegalArgumentException iAE ) + { + usbe = true; + } catch ( UsbException uE ) + { + fail("java.lang.IllegalArgumentException was expected. Unexpected UsbException on submitting null buffer:" + uE); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail("java.lang.IllegalArgumentException was expected. Unexpected generic exception." + e); + } + + assertTrue("java.lang.IllegalArgumentException not received when submitting a null byte []", usbe); + + + } else + { + fail ("UsbDevice is not configured!"); + } + + + } + /** + * Test error conditions -- Null Data Buffer + */ + private void doTestNullDataBufferInIrp(int endpointType) + { + + outPipe = null; + UsbEndpoint outEndpoint = null; + + //UsbInterface myIface = null; + UsbIrp usbIrp = null; + boolean usbe = false; + + + if ( usbDevice.isConfigured() ) + { + + outEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_OUT); + + assertFalse("could not find output endpoint", null == outEndpoint); + + // @P2D4 + assertTrue("Interface was not claimed!", myIface.isClaimed()); + + //we have an endpoint; now try submitting a null byte array and an IRP + //with a null data + + outPipe = outEndpoint.getUsbPipe(); + assertTrue("output pipe is not active!!!", outPipe.isActive()); + IOMethods.openPipe(outPipe); + + //submit null byte array + byte [] nullBuffer = null; + + + //submit IRP with null data + + usbIrp = outPipe.createUsbIrp(); + + try + { + usbIrp.setData(nullBuffer); + fail("Expected a UsbException when setting null data in IRP."); + outPipe.syncSubmit(usbIrp); + fail("Expected a UsbException when submitting an IRP with a null byte array in IRP."); + } catch ( IllegalArgumentException iAE ) + { + usbe = true; + } catch ( UsbException uE ) + { + fail("java.lang.IllegalArgumentException was expected. Unexpected UsbException on settin null data in IRP:" + uE); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail("java.lang.IllegalArgumentException was expected. Unexpected generic exception." + e); + } + + assertTrue("java.lang.IllegalArgumentException not received when submitting a null byte [] in IRP", usbe); + + } else + { + fail ("UsbDevice is not configured!"); + } + + } + + /** + * Test error conditions -- Action against a closed pipe + */ + private void doTestActionAgainstClosePipeAbortAllSubmissions(int endpointType) + { + + + + outPipe = null; + UsbEndpoint outEndpoint = null; + boolean usbe = false; + + + if ( usbDevice.isConfigured() ) + { + + outEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_OUT); + + assertFalse("could not find output endpoint", null == outEndpoint); + outPipe = outEndpoint.getUsbPipe(); + assertTrue("output pipe is not active!!!", outPipe.isActive()); + assertFalse("pipe should not be open.", outPipe.isOpen()); + + // @P2D4 + assertTrue("Interface was not claimed!", myIface.isClaimed()); + + + try + { + outPipe.abortAllSubmissions(); // should throw UsbNotOpenException + assertFalse("Pipe should have been closed at this part of the test.", outPipe.isOpen()); + fail("abortAllSumissions should have thrown a UsbNotOpenException when called on a closed pipe."); + } catch ( UsbNotOpenException ue ) + { + usbe = true; + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail ("UsbNotOpenException was expected. Unexpected exception: " + e); + } + + + + if ( !usbe ) + assertTrue("Test Action Agains Close Pipe abortAllSubmission() did not throw UsbNotOpenException!", false); + + } + + else + { + fail ("UsbDevice is not configured!"); + } + + } + /** + * Test error conditions -- Action against a closed pipe + */ + private void doTestActionAgainstClosePipeSubmit(int endpointType) + { + + outPipe = null; + UsbEndpoint outEndpoint = null; + boolean usbe = false; + + + if ( usbDevice.isConfigured() ) + { + + outEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_OUT); + + assertFalse("could not find output endpoint", null == outEndpoint); + outPipe = outEndpoint.getUsbPipe(); + assertTrue("output pipe is not active!!!", outPipe.isActive()); + assertFalse("pipe should not be open.", outPipe.isOpen()); + + // @P2D4 + assertTrue("Interface was not claimed!", myIface.isClaimed()); + + + try + { + byte [] data = {1,2,3,4,5}; + outPipe.syncSubmit(data); + assertFalse("Pipe should have been closed at this part of the test.", outPipe.isOpen()); + fail("Submit should have thrown a UsbNotOpenException when called on a closed pipe."); + } catch ( UsbNotOpenException ue ) + { + usbe = true; + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1A + + { + fail ("UsbNotOpenException was expected. Unexpected exception: " + e); + } + + + if ( !usbe ) + assertTrue("Test Action Agains Close Pipe Submit did not throw UsbNotOpenException!", false); + + } + + else + { + fail ("UsbDevice is not configured!"); + } + + + + + + + } + + /** + * Test error conditions -- Close a pipe with pending operation + */ + private void doTestClosePipePendingAction(int endpointType) + { + + inPipe = null; + boolean usbe = false; + UsbEndpoint inEndpoint = null; + + // get an out endpoint + if ( usbDevice.isConfigured() ) + { + + inEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_IN); + + assertFalse("could not find endpoint", null == inEndpoint); + + inPipe = inEndpoint.getUsbPipe(); + assertTrue("output pipe is not active!!!", inPipe.isActive()); + assertFalse("pipe should not be open.", inPipe.isOpen()); + + // @P2D4 + assertTrue("Interface was not claimed!", myIface.isClaimed()); + + // open the pipe + IOMethods.openPipe(inPipe); + assertTrue("pipe should be opened", inPipe.isOpen()); + + try + { + //List listOfIrps = new ArrayList(); + List inList = new ArrayList(); + UsbIrp inIrp = null; + + for ( int i = 0; i < 1000; i++ ) + { + + inIrp = inPipe.createUsbIrp(); + inIrp.setData(new byte[inPipe.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize()]); // @P2A + inList.add(inIrp); + } + inPipe.asyncSubmit(inList); + inPipe.close(); // should throw UsbException + fail ("UsbException should have been thrown when closing pipe with pending submissions."); + } catch ( UsbException ue ) + { + usbe = true; + + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail("Unexpected Exception: " + e); + } + if ( !usbe ) + assertTrue("Test Close Pipe With Pending Operations usbPipe.close() did not throw UsbException!", false); + + + } else + { + fail ("UsbDevice is not configured!"); + } + + } + + /** + * Test error conditions -- Open a pipe on an inactive interface + */ + private void doTestOpenPipeOnInactiveAlternateSetting(int endpointType) + { + + + myIface = null; + boolean usbe = false; + UsbEndpoint inEndpoint = null; + inPipe = null; + + + if ( usbDevice.isConfigured() ) + { + inEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_IN); + if ( (endpointType == UsbConst.ENDPOINT_TYPE_BULK)|| + (endpointType == UsbConst.ENDPOINT_TYPE_INTERRUPT) ) + { + + + assertFalse("could not find endpoint", null == inEndpoint); + // @P2D3 + } else + { + + + assertFalse("could not find endpoint", null == inEndpoint); + // @P2D3 + } + + inPipe = inEndpoint.getUsbPipe(); + assertFalse("Pipe should not be active!!!", + inPipe.isActive()); + + + if ( !myIface.isActive() ) + { + try + { + inPipe.open(); + fail("should caused UsbNotActiveException!"); + } catch ( UsbNotActiveException ue ) + { + usbe = true; + } catch ( UsbException ue ) + { + fail("UsbNotActiveException was expected. Unexpected UsbException: " + ue); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + fail("UsbNotActiveException was expected. Unexpected Exception: " + e); + } + } else + { + fail("Interface should have been inactive at this point."); + } + if ( !usbe ) + assertTrue("Test Open Pipe On Inactive Interface did not throw UsbNotActiveException!", false); + + } + + + else + { + fail ("UsbDevice is not configured!"); + } + + assertFalse("Leaving routine but interface was not released!", myIface.isClaimed()); + } + + + private void doTestOpenPipeOnUnclaimedInterface(int endpointType) + { + myIface = null; + boolean usbe = false; + UsbEndpoint inEndpoint = null; + inPipe = null; + + + if ( usbDevice.isConfigured() ) + { + inEndpoint = getEndpointOfType(usbDevice, endpointType, UsbConst.REQUESTTYPE_DIRECTION_IN); + + + assertFalse("could not find endpoint", null == inEndpoint); + + // @P2D4 + try + { + inEndpoint.getUsbInterface().release(); + } catch ( UsbClaimException ue ) + { + fail("The interface should have been durring getEndpointOfType method call!"); + } catch ( UsbException ue ) + { + fail("Unexpected exception: " + ue); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } // @P1A + + if ( myIface.isActive() ) + { + inPipe = inEndpoint.getUsbPipe(); + assertTrue("pipe is not active!!!", + inPipe.isActive()); + try + { + + + inPipe.open(); + fail("should caused UsbNotClaimedException!"); + + } catch ( UsbNotClaimedException ue ) + { + usbe = true; + } catch ( UsbException ue ) + { + fail("UsbNotClaimedException was expected. Unexpected UsbException: " + ue); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1A + { + fail("UsbNotClaimedException was expected. Unexpected Exception: " + e); + + } + if ( !usbe ) + assertTrue("Test Open Pipe On Unclaimed Interface did not throw UsbNotClaimedException!", false); + } + + else + { + fail("Interface should have been active."); + } + + + } + + + + } + + +// /** +// * looking for an inactive interface +// * return null if not found +// */ +// private UsbInterface getInactiveInterface() +// { +// UsbConfiguration config = null; +// UsbHub virtualRootUsbHub = getVirtualRootUsbHub(); +// List usbDevices = null; +// byte firstInterface = 0; +// // get all connected devices +// usbDevices = getAllUsbDevices(virtualRootUsbHub); +// System.out.println("Found " + usbDevices.size() + " devices total."); +// +// // find an inactive interface +// for ( int i = 0; i > usbDevices.size(); i++ ) +// { +// UsbDevice device = (UsbDevice)usbDevices.get(i); +// List configurations = device.getUsbConfigurations(); +// for ( int j = 0; i