diff options
author | smcauliffe <smcauliffe@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2006-05-15 10:27:15 +0000 |
---|---|---|
committer | smcauliffe <smcauliffe@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2006-05-15 10:27:15 +0000 |
commit | cf17451e6ac2a3f7009964f5a8f2baf4e461f0df (patch) | |
tree | caf94b5c3a5bcf04b94866d1ae0558d9eeeb0d73 | |
parent | 9363d023a0155564f4748084fe02e018374f2cc9 (diff) | |
download | reprap-backup-cf17451e6ac2a3f7009964f5a8f2baf4e461f0df.tar.gz reprap-backup-cf17451e6ac2a3f7009964f5a8f2baf4e461f0df.zip |
Added initial test for timeouts
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@318 cb376a5e-1013-0410-a455-b6b1f9ac8223
5 files changed, 82 insertions, 5 deletions
diff --git a/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java b/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java index 99195486..e25581b4 100644 --- a/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java +++ b/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java @@ -17,7 +17,6 @@ public class TestPort implements Port { private TestPortHandler handler;
private Thread handlerThread;
-
public TestPort() throws IOException {
out = new PipedOutputStream();
in = new PipedInputStream();
@@ -60,5 +59,9 @@ public class TestPort implements Port { public void addDevice(TestDevice device, SNAPAddress address) {
handler.registerDevice(address, device);
}
+
+ public void dropNextIncomingPacket() {
+ handler.dropNextIncomingPacket();
+ }
}
diff --git a/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java b/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java index a9f15b1d..71d7d46a 100644 --- a/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java +++ b/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java @@ -16,6 +16,8 @@ public class TestPortHandler { PipedInputStream in;
PipedOutputStream out;
+ boolean dropNextIncomingPacketFlag = false;
+
public TestPortHandler(PipedInputStream in, PipedOutputStream out) {
this.in = in;
this.out = out;
@@ -39,8 +41,10 @@ public class TestPortHandler { int data = in.read();
if (packet.receiveByte((byte)data)) {
// Process a packet and prepare for a new one
- processPacket(packet);
+ if (!dropNextIncomingPacketFlag)
+ processPacket(packet);
packet = new SNAPPacket();
+ dropNextIncomingPacketFlag = false;
}
} catch(Exception ex) {
System.out.println("PIC side simulator exception: " + ex);
@@ -63,4 +67,7 @@ public class TestPortHandler { device.receivePacket(out, packet);
}
+ public void dropNextIncomingPacket() {
+ dropNextIncomingPacketFlag = true;
+ }
}
diff --git a/branches/sm-unittesting/src/org/reprap/comms/port/testhandlers/TestDevice.java b/branches/sm-unittesting/src/org/reprap/comms/port/testhandlers/TestDevice.java index cd0298ec..d33730b4 100644 --- a/branches/sm-unittesting/src/org/reprap/comms/port/testhandlers/TestDevice.java +++ b/branches/sm-unittesting/src/org/reprap/comms/port/testhandlers/TestDevice.java @@ -6,12 +6,14 @@ import java.io.PipedOutputStream; import org.reprap.comms.snap.SNAPPacket;
public abstract class TestDevice {
+
+ public static final int version = 0x100;
public void receivePacket(PipedOutputStream out, SNAPPacket packet) throws Exception {
byte payload [] = packet.getPayload();
switch(payload[0]) {
case 0:
- reply(out, packet, new byte [] {0, 0, 1});
+ reply(out, packet, new byte [] {0, version & 0xff, (version & 0xff00) >> 8});
return;
}
diff --git a/branches/sm-unittesting/src/org/reprap/devices/StepperTest.java b/branches/sm-unittesting/src/org/reprap/devices/StepperTest.java new file mode 100644 index 00000000..c937923d --- /dev/null +++ b/branches/sm-unittesting/src/org/reprap/devices/StepperTest.java @@ -0,0 +1,66 @@ +package org.reprap.devices;
+
+import org.reprap.comms.Communicator;
+import org.reprap.comms.port.Port;
+import org.reprap.comms.port.TestPort;
+import org.reprap.comms.port.testhandlers.TestDevice;
+import org.reprap.comms.port.testhandlers.TestStepper;
+import org.reprap.comms.snap.SNAPAddress;
+import org.reprap.comms.snap.SNAPCommunicator;
+import org.testng.Assert;
+
+/**
+ *
+ * @testng.configuration groups = "comms,all,all-offline"
+ *
+ */
+public class StepperTest {
+
+ TestPort port;
+ GenericStepperMotor motor;
+ Communicator communicator;
+
+ /**
+ * @testng.configuration beforeSuite = "true"
+ */
+ public void setUp() throws Exception {
+ port = new TestPort();
+ port.addDevice(new TestStepper(), new SNAPAddress(2));
+
+ Communicator communicator = new SNAPCommunicator(port, new SNAPAddress(0));
+
+ motor = new GenericStepperMotor(communicator, new SNAPAddress(2), 200);
+ }
+
+ /**
+ * @testng.configuration afterSuite = "true"
+ */
+ public void tearDown() {
+ motor.dispose();
+ //communicator.dispose();
+ port.close();
+ }
+
+ /**
+ * @testng.test groups = "comms,all,all-offline"
+ * timeOut="1000"
+ */
+ public void testStepperBasic() throws Exception {
+ int version = motor.getVersion();
+ Assert.assertEquals(version, TestDevice.version);
+
+ }
+
+ /**
+ * A test that drops the first received packet to check
+ * that the request will time out and be re-sent
+ * @testng.test groups = "comms,all,all-offline"
+ * timeOut="5000"
+ */
+ public void testTimeouts() throws Exception {
+ port.dropNextIncomingPacket();
+ int version = motor.getVersion();
+ Assert.assertEquals(version, TestDevice.version);
+ }
+
+}
diff --git a/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java b/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java index 4ca00181..1686f5ce 100644 --- a/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java +++ b/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java @@ -12,7 +12,6 @@ import org.testng.Assert; /**
*
* @testng.configuration groups = "comms,all,all-offline"
- *
*/
public class ReprapTest {
private Printer printer;
@@ -49,7 +48,7 @@ public class ReprapTest { * @testng.configuration afterSuite = "true"
*/
public void tearDown() {
- printer.dispose();
+ //printer.dispose();
}
/**
|