<commit_before>/*
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 * See LICENSE.md for licensing information.
 */

package de.ailis.usb4java.libusb;

import static de.ailis.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the device-scope methods of the {@link LibUsb} class which need a open
 * USB context and a device to run the tests on.
 * 
 * @author <NAME> (<EMAIL>)
 */
public class LibUSBDeviceTest
{
    /** The libusb contxet. */
    private Context context;

    /** The device to run the tests on. */
    private Device device;

    /** The device endpoint to test with. */
    private int endpoint;

    /** The value of the active configuration. */
    private int configValue;

    /** The vendor ID of the device we test. */
    private int vendorId;

    /** The manufacturer ID of the device we test. */
    private int productId;

    /**
     * Set up the test.
     */
    @Before
    public void setUp()
    {
        this.context = new Context();
        try
        {
            LibUsb.init(this.context);
            this.device = findTestDevice();
            if (this.device == null)
                throw new IllegalStateException("Need at least one USB device "
                    +
                    "with at least one endpoint to execute this test");
        }
        catch (Throwable e)
        {
            this.context = null;
            this.device = null;
        }
    }

    /**
     * Finds a test device with at least one endpoint.
     * 
     * @return The test device or null if none.
     */
    private Device findTestDevice()
    {
        DeviceList list = new DeviceList();
        if (LibUsb.getDeviceList(this.context, list) <= 0) return null;
        try
        {
            for (Device device: list)
            {
                DeviceDescriptor descriptor = new DeviceDescriptor();<commit_msg>Retain USB context when no USB device to test was found<commit_after>/*
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 * See LICENSE.md for licensing information.
 */

package de.ailis.usb4java.libusb;

import static de.ailis.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the device-scope methods of the {@link LibUsb} class which need a open
 * USB context and a device to run the tests on.
 * 
 * @author <NAME> (<EMAIL>)
 */
public class LibUSBDeviceTest
{
    /** The libusb contxet. */
    private Context context;

    /** The device to run the tests on. */
    private Device device;

    /** The device endpoint to test with. */
    private int endpoint;

    /** The value of the active configuration. */
    private int configValue;

    /** The vendor ID of the device we test. */
    private int vendorId;

    /** The manufacturer ID of the device we test. */
    private int productId;

    /**
     * Set up the test.
     */
    @Before
    public void setUp()
    {
        this.context = new Context();
        LibUsb.init(this.context);
        try
        {
            this.device = findTestDevice();
            if (this.device == null)
                throw new IllegalStateException("Need at least one USB device "
                    +
                    "with at least one endpoint to execute this test");
        }
        catch (Throwable e)
        {
            this.device = null;
        }
    }

    /**
     * Finds a test device with at least one endpoint.
     * 
     * @return The test device or null if none.
     */
    private Device findTestDevice()
    {
        DeviceList list = new DeviceList();
        if (LibUsb.getDeviceList(this.context, list) <= 0) return null;
        try
        {
            for (Device device: list)
            {
                DeviceDescriptor descriptor = new DeviceDescriptor();
{'fraction_non_alphanumeric': 0.09744517295952973, 'fraction_numerical': 0.0031652724395206874, 'mean_word_length': 2.1532430506058446, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1562739', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1211, 'n_words': 421}