Add unit test for EndpointDescriptor and catch uninitialized usage of it
This commit is contained in:
parent
0d2a6d3d49
commit
b0ea43c88b
@ -39,7 +39,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bLength)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bLength;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +53,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bDescriptorType)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bDescriptorType;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bDescriptorType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +67,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bEndpointAddress)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bEndpointAddress;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bEndpointAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +81,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bmAttributes)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bmAttributes;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bmAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +95,10 @@ JNIEXPORT jshort JNICALL METHOD_NAME(EndpointDescriptor, wMaxPacketSize)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->wMaxPacketSize;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->wMaxPacketSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +109,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bInterval)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bInterval;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,7 +123,10 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bRefresh)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bRefresh;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bRefresh;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,7 +137,10 @@ JNIEXPORT jint JNICALL METHOD_NAME(EndpointDescriptor, bSynchAddress)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->bSynchAddress;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->bSynchAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,6 +153,7 @@ JNIEXPORT jobject JNICALL METHOD_NAME(EndpointDescriptor, extra)
|
||||
{
|
||||
struct libusb_endpoint_descriptor *descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return NULL;
|
||||
return (*env)->NewDirectByteBuffer(env, (void *) descriptor->extra,
|
||||
descriptor->extra_length);
|
||||
}
|
||||
@ -141,5 +166,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(EndpointDescriptor, extraLength)
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrapEndpointDescriptor(env, this)->extra_length;
|
||||
struct libusb_endpoint_descriptor* descriptor =
|
||||
unwrapEndpointDescriptor(env, this);
|
||||
if (!descriptor) return 0;
|
||||
return descriptor->extra_length;
|
||||
}
|
||||
|
||||
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Klaus Reimer <k@ailis.de>
|
||||
* See LICENSE.md for licensing information.
|
||||
*/
|
||||
|
||||
package de.ailis.usb4java.libusb;
|
||||
|
||||
import static de.ailis.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the {@link EndpointDescriptor} class.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
public class EndpointDescriptorTest
|
||||
{
|
||||
/** The test subject. */
|
||||
private EndpointDescriptor descriptor;
|
||||
|
||||
/**
|
||||
* Setup test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new EndpointDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down test.
|
||||
*/
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bLength()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedLength()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bDescriptorType()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedDescriptorType()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bDescriptorType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bEndpointAddress()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedEndpointAddress()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bEndpointAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bmAttributes()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedAttributes()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bmAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#wMaxPacketSize()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedMaxPacketSize()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.wMaxPacketSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bInterval()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedInterval()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bInterval();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bRefresh()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedRefresh()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#bSynchAddress()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedSynchAddress()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.bSynchAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#extra()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedExtra()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.extra();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninitialized access to
|
||||
* {@link EndpointDescriptor#extraLength()}
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUninitializedExtraLength()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
this.descriptor.extraLength();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user