All Downloads are FREE. Search and download functionalities are using the official Maven repository.

purejavacomm.testsuite.TestFreeFormPortIdentifiers Maven / Gradle / Ivy

Go to download

FiloFirmata is a client library for the Firmata protocol used with hardware project boards.

There is a newer version: 0.1.11
Show newest version
package purejavacomm.testsuite;

import java.io.File;

import purejavacomm.CommPortIdentifier;
import purejavacomm.NoSuchPortException;

/**
 * This test case tests how CommPortIdentifier handles free form port names.
 * Serial ports are notorious for not being able to enumerate reliably, so an
 * application that allows a user to select a serial port will always have to
 * provide a free-form entry to provide the serial device name.
 * 
 * The API that takes this device name and returns an identifier is
 * {@link CommPortIdentifier#getPortIdentifier(String)}.
 */
public class TestFreeFormPortIdentifiers extends TestBase {

	public static void testMissingPortInCommPortIdentifier() throws Exception {
		begin("TestMissingPort"); //  - getPortIdentifier on missing port

		// Must throw NoSuchPortException

		try {
			CommPortIdentifier.getPortIdentifier("blablub");

			fail("Got an identifier for non-exisiting path");
		} catch (NoSuchPortException nspe) {
			// All good
		}

		finishedOK();
	}
	
	public static void testDevicePathInCommPortIdentifier() throws Exception {
		begin("TestDevicePath "); // - getPortIdentifier on device path");

		// Must return an identifier

		try {
			CommPortIdentifier.getPortIdentifier(getPortName());
		} catch (NoSuchPortException nspe) {
			fail("Couldn't obtain identifier for device path");
		}

		finishedOK();
	}
	
	public static void testDevicePathToInvalidTTYInCommPortIdentifier() throws Exception {
		begin("TestDevicePathToInvalidTTY");// - getPortIdentifier on invalid device");

		// Must throw NoSuchPortException

		File tempFile = File.createTempFile("pjc", null);
		tempFile.deleteOnExit();
		
		try {
			CommPortIdentifier.getPortIdentifier(tempFile.getAbsolutePath());

			fail("Got an identifier for an invalid device");
		} catch (NoSuchPortException nspe) {
			// All good
		}

		finishedOK();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy