Added:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusDecoderTest.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusDecoderTest.java?rev=1084906&view=auto
==============================================================================
---
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusDecoderTest.java
(added)
+++
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusDecoderTest.java
Thu Mar 24 11:35:26 2011
@@ -0,0 +1,381 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.modbus.transport.rtu;
+
+
+import java.util.Arrays;
+import java.util.Random;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.modbus.ModbusConstants;
+import org.apache.mina.modbus.transport.rtu.RTUModbusMessage.CRCException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RTUModbusDecoderTest extends TestCase {
+ RTUModbusDecoder decoder = new RTUModbusDecoder(false);
+ static final Logger LOG =
LoggerFactory.getLogger(RTUModbusDecoderTest.class);
+
+ ProtocolCodecSession session = new ProtocolCodecSession();
+ ProtocolDecoderOutput out = session.getDecoderOutput();
+
+ public void testDecodeOneFrame() throws Exception {
+ LOG.info("Decode one frame");
+ // write single register at address 1 and value 50, reply
+ RTUModbusMessage msg = new RTUModbusMessage(1, 6, new byte[] { (byte)
0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff); // put
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ }
+
+ public void testRejectBuggedFrame() throws Exception {
+ LOG.info("Reject bugged frame");
+ // 4 bytes frame
+ IoBuffer in = IoBuffer.allocate(10);
+ in.putChar('A'); // some crap
+ in.putChar('B');
+ in.flip();
+ // System.err.println("frame size : "+in.remaining());
+ // in.putChar('C');
+ // in.putChar('x');
+ boolean exception = false;
+ try {
+ decoder.decode(session, in, out);
+ } catch (ProtocolDecoderException e) {
+ exception = true;
+ }
+ Assert.assertTrue(exception);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+
+ // 2 bytes frame
+ in = IoBuffer.allocate(10);
+ in.put((byte) 0); //
+ in.put((byte) ModbusConstants.READ_HOLDING_REGISTERS);
+ in.flip();
+ // no exceptions
+ decoder.decode(session, in, out);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+
+ public void testRejectCorruptedFrame() throws Exception {
+ LOG.info("Reject corrupted frame");
+ // write single register at address 1 and value 50, reply
+ RTUModbusMessage msg = new RTUModbusMessage(1, 6, new byte[] { (byte)
0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff); // put
+ in.put(3, (byte) 56); // some crap
+ in.flip();
+ Exception ex = null;
+ try {
+ decoder.decode(session, in, out);
+ } catch (RTUModbusMessage.CRCException e) {
+ ex = e;
+ }
+ Assert.assertNotNull(ex);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+
+ }
+
+ public void testAcceptMultiFrame() throws Exception {
+ LOG.info("Accept multi frame");
+ // write single register at address 1 and value 50, reply
+ RTUModbusMessage msg = new RTUModbusMessage(1, 6, new byte[] { (byte)
0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+
+ in = IoBuffer.allocate(100);
+ buff.flip(); // re-put
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+ }
+
+ public void testFragmentation() throws Exception {
+ LOG.info("Fragmentation");
+
+ // write multiple register at address 1 and 10 values
+ RTUModbusMessage msgWrite10 = new RTUModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, new byte[] {
+ (byte) 0, (byte) 1, (byte) 0, (byte) 10, (byte) 20, (byte) 0,
(byte) 1, (byte) 0, (byte) 2, (byte) 0,
+ (byte) 3, (byte) 0, (byte) 4, (byte) 0, (byte) 5, (byte) 0,
(byte) 6, (byte) 0, (byte) 7, (byte) 0,
+ (byte) 8, (byte) 0, (byte) 9, (byte) 0, (byte) 10 });
+
+ // write multiple register at address 1 and 5 values
+ RTUModbusMessage msgWrite5 = new RTUModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, new byte[] {
+ (byte) 0, (byte) 1, (byte) 0, (byte) 5, (byte) 10, (byte) 0,
(byte) 1, (byte) 0, (byte) 2, (byte) 0,
+ (byte) 3, (byte) 0, (byte) 4, (byte) 0, (byte) 5 });
+
+ // write multiple register at address 1 and 5 values
+ RTUModbusMessage msgWrite4 = new RTUModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, new byte[] {
+ (byte) 0, (byte) 1, (byte) 0, (byte) 4, (byte) 8, (byte) 0,
(byte) 1, (byte) 0, (byte) 2, (byte) 0,
+ (byte) 3, (byte) 0, (byte) 4 });
+
+ IoBuffer buffPDU1 = msgWrite10.encode();
+ IoBuffer buffPDU2 = msgWrite5.encode();
+ IoBuffer buffPDU3 = msgWrite4.encode();
+ IoBuffer buffPDU123 = IoBuffer.allocate(buffPDU1.remaining() * 2 +
buffPDU2.remaining()
+ + buffPDU3.remaining());
+ buffPDU123.put(buffPDU1);
+
+ buffPDU123.put(buffPDU2);
+ buffPDU123.put(buffPDU3);
+ buffPDU1.rewind();
+ buffPDU123.put(buffPDU1);
+ buffPDU123.flip(); // PDU123 = PDU1 + PDU2 + PDU3 + PDU1
+
+ buffPDU1.flip();
+ buffPDU2.flip();
+
+ // dezcode a plain buffer
+ decoder.decode(session, buffPDU1, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ buffPDU1.rewind();
+
+ IoBuffer buff1 = IoBuffer.allocate(4);
+ while (buff1.hasRemaining()) {
+ buff1.put(buffPDU1.get());
+ }
+
+ buff1.flip();
+ // decode a part of a PDU
+ decoder.decode(session, buff1, out);
+
+ IoBuffer buff2 = IoBuffer.allocate(buffPDU1.remaining());
+ while (buffPDU1.hasRemaining()) {
+ buff2.put(buffPDU1.get());
+ }
+ buff2.flip();
+
+ // decode the second part
+ decoder.decode(session, buff2, out);
+
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+
+ // decode four concatenated big PDU
+ decoder.decode(session, buffPDU123, out);
+ Assert.assertEquals(6, session.getDecoderOutputQueue().size());
+
+ // decode a big PDU each byte per each byte
+ buffPDU1.rewind();
+ while (buffPDU1.hasRemaining()) {
+ IoBuffer bufOneByte = IoBuffer.allocate(1);
+ bufOneByte.put(buffPDU1.get());
+ bufOneByte.flip();
+ decoder.decode(session, bufOneByte, out);
+ }
+ Assert.assertEquals(7, session.getDecoderOutputQueue().size());
+
+ RTUModbusMessage msg = (RTUModbusMessage)
session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite5));
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite4));
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (RTUModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ }
+
+ public void testCorruptionOnFragmentatedFrame() throws Exception {
+ LOG.info("Fragmentation Corrupted");
+
+ // write multiple register at address 1 and 10 values
+ RTUModbusMessage msgWrite10 = new RTUModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, new byte[] {
+ (byte) 0, (byte) 1, (byte) 0, (byte) 10, (byte) 20, (byte) 0,
(byte) 1, (byte) 0, (byte) 2, (byte) 0,
+ (byte) 3, (byte) 0, (byte) 4, (byte) 0, (byte) 5, (byte) 0,
(byte) 6, (byte) 0, (byte) 7, (byte) 0,
+ (byte) 8, (byte) 0, (byte) 9, (byte) 0, (byte) 10 });
+
+ // write multiple register at address 1 and 5 values
+ RTUModbusMessage msgWrite5 = new RTUModbusMessage(1,
ModbusConstants.WRITE_FILE_RECORD, new byte[] { (byte) 0,
+ (byte) 1, (byte) 0, (byte) 5, (byte) 10, (byte) 0, (byte) 1,
(byte) 0, (byte) 2, (byte) 0, (byte) 3,
+ (byte) 0, (byte) 4, (byte) 0, (byte) 5 });
+
+ // write multiple register at address 1 and 5 values
+ RTUModbusMessage msgWrite4 = new RTUModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, new byte[] {
+ (byte) 0, (byte) 1, (byte) 0, (byte) 4, (byte) 8, (byte) 0,
(byte) 1, (byte) 0, (byte) 2, (byte) 0,
+ (byte) 3, (byte) 0, (byte) 4 });
+
+ IoBuffer buffPDU1 = msgWrite10.encode();
+ IoBuffer buffPDU2 = msgWrite5.encode();
+ IoBuffer buffPDU3 = msgWrite4.encode();
+ IoBuffer buffPDU123 = IoBuffer.allocate(buffPDU1.remaining() * 2 +
buffPDU2.remaining()
+ + buffPDU3.remaining());
+ buffPDU123.put(buffPDU1);
+
+ buffPDU123.put(buffPDU2);
+ buffPDU123.put(buffPDU3);
+ buffPDU1.rewind();
+ buffPDU123.put(buffPDU1);
+ buffPDU123.flip(); // PDU123 = PDU1 + PDU2 + PDU3 + PDU1
+
+ buffPDU1.flip();
+ buffPDU2.flip();
+
+ // dezcode a plain buffer
+ decoder.decode(session, buffPDU1, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ buffPDU1.rewind();
+
+ IoBuffer buff1 = IoBuffer.allocate(4);
+ while (buff1.hasRemaining()) {
+ buff1.put(buffPDU1.get());
+ }
+
+ buff1.flip();
+ // decode a part of a PDU
+ decoder.decode(session, buff1, out);
+
+ IoBuffer buff2 = IoBuffer.allocate(buffPDU1.remaining());
+ while (buffPDU1.hasRemaining()) {
+ buff2.put(buffPDU1.get());
+ }
+ buff2.flip();
+
+ // decode the second part
+ decoder.decode(session, buff2, out);
+
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+
+ boolean exp = false;
+ boolean expProto = false;
+ // decode four concatenated big PDU
+ while (buffPDU123.hasRemaining()) {
+ IoBuffer bufOneByte = IoBuffer.allocate(1);
+ bufOneByte.put(buffPDU123.get());
+ bufOneByte.flip();
+ try {
+ decoder.decode(session, bufOneByte, out);
+ } catch (ProtocolDecoderException e) {
+ expProto = true;
+ } catch (CRCException e) {
+ exp = true;
+ }
+ }
+ Assert.assertTrue(exp);
+ Assert.assertTrue(expProto);
+ Assert.assertEquals(3, session.getDecoderOutputQueue().size());
+
+ // decode a big PDU each byte per each byte
+ buffPDU1.rewind();
+
+ int pos = 0;
+ int where = 20;
+ exp = false;
+ while (buffPDU1.hasRemaining()) {
+ IoBuffer bufOneByte = IoBuffer.allocate(1);
+ if (where == pos) {
+ bufOneByte.put((byte) 65);
+ } else {
+ bufOneByte.put(buffPDU1.get());
+ }
+ bufOneByte.flip();
+ try {
+ decoder.decode(session, bufOneByte, out);
+ } catch (CRCException e) {
+ exp = true;
+ }
+ pos++;
+ }
+ Assert.assertTrue(exp);
+
+ }
+
+ private boolean samePDU(RTUModbusMessage msg1, RTUModbusMessage msg2) {
+ if (msg1.getDevice() != msg2.getDevice()) {
+ return false;
+ }
+ if (msg1.getFunctionCode() != msg2.getFunctionCode()) {
+ return false;
+ }
+ if (!Arrays.equals(msg1.getData(), msg2.getData())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void testRandomPDU() {
+ LOG.info("Random PDU rejection");
+ Random rng = new Random();
+ for (int i = 0; i < 50; i++) {
+
+ IoBuffer buggedBuff = IoBuffer.allocate(8 + rng.nextInt(12));
+
+ while (buggedBuff.remaining() > 0) {
+ buggedBuff.put((byte) rng.nextInt());
+ }
+ buggedBuff.flip();
+ // System.err.println("random buffer of len :
"+buggedBuff.remaining());
+ try {
+ decoder.decode(session, buggedBuff, out);
+ } catch (Exception ex) {
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+ }
+
+ public void testByteInsertion() {
+ LOG.info("Insert one byte before PDU");
+ RTUModbusMessage msg = new RTUModbusMessage(1, 6, new byte[] { (byte)
0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer pduBuff = msg.encode();
+
+ IoBuffer buff = IoBuffer.allocate(pduBuff.remaining() + 1);
+ // add a zero before the PCU
+ buff.put((byte) 0);
+ buff.put(pduBuff);
+ buff.flip();
+ boolean exception = false;
+ try {
+ decoder.decode(session, buff, out);
+ } catch (Exception ex) {
+ exception = true;
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ Assert.assertTrue(exception);
+ }
+
+}
Propchange:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusDecoderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusEncoderTest.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusEncoderTest.java?rev=1084906&view=auto
==============================================================================
---
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusEncoderTest.java
(added)
+++
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusEncoderTest.java
Thu Mar 24 11:35:26 2011
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.modbus.transport.rtu;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecSession;
+import org.apache.mina.filter.codec.ProtocolEncoderException;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.modbus.ModbusConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RTUModbusEncoderTest extends TestCase {
+
+ RTUModbusEncoder encoder = new RTUModbusEncoder();
+
+ ProtocolCodecSession session = new ProtocolCodecSession();
+ ProtocolEncoderOutput out = session.getEncoderOutput();
+
+ static final Logger LOG =
LoggerFactory.getLogger(RTUModbusEncoderTest.class);
+
+ public void testEncodeMessage() throws ProtocolEncoderException {
+ RTUModbusMessage rtu = new RTUModbusMessage(1,
ModbusConstants.READ_HOLDING_REGISTERS);
+ rtu.setData(new byte[] { (byte) 1, (byte) 10 });
+
+ encoder.encode(session, rtu, out);
+
+ IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue().poll();
+ Assert.assertEquals(buf, rtu.encode());
+
+ rtu.setFunctionCode(ModbusConstants.READ_INPUT_REGISTERS);
+
+ encoder.encode(session, rtu, out);
+
+ buf = (IoBuffer) session.getEncoderOutputQueue().poll();
+ Assert.assertEquals(buf, rtu.encode());
+ }
+
+ public void testProtocolEncoderException() throws ProtocolEncoderException
{
+
+ boolean excep = false;
+ try {
+ encoder.encode(session, new String(), out);
+ } catch (ProtocolEncoderException e) {
+ excep = true;
+ }
+
+ Assert.assertTrue(excep);
+ }
+
+}
Propchange:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/rtu/RTUModbusEncoderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderMasterTest.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderMasterTest.java?rev=1084906&view=auto
==============================================================================
---
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderMasterTest.java
(added)
+++
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderMasterTest.java
Thu Mar 24 11:35:26 2011
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.modbus.transport.tcp;
+
+
+import java.util.Arrays;
+import java.util.Random;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.modbus.ModbusConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class TCPModbusDecoderMasterTest extends TestCase {
+ TCPModbusDecoder decoder = new TCPModbusDecoder(true);
+
+ ProtocolCodecSession session = new ProtocolCodecSession();
+ ProtocolDecoderOutput out = session.getDecoderOutput();
+
+
+ static final Logger LOG =
LoggerFactory.getLogger(TCPModbusDecoderMasterTest.class);
+
+ public void testDecodeOneFrame() throws Exception {
+ LOG.info("Decode one frame");
+ // write single register at address 1 and value 50, reply
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff); // put
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ }
+
+ public void testDecodeOneModbusErrorFrame() throws Exception {
+ LOG.info("Decode one frame");
+ // write single register error, reply
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6 + 0x80, 1);
+ msg.setData(new byte[] { (byte) 1 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff); // put
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ }
+
+ public void testRejectBuggedFrame() throws Exception {
+ LOG.info("Reject bugged frame");
+ // 4 bytes frame
+ IoBuffer in = IoBuffer.allocate(10);
+ in.putChar('A'); // some crap
+ in.putChar('B');
+ in.putChar('C');
+ in.putChar('x');
+ in.putChar('D');
+ in.flip();
+ //System.err.println("frame size : "+in.remaining());
+
+ boolean exception = false;
+ try {
+ decoder.decode(session, in, out);
+ } catch (ProtocolDecoderException e) {
+ exception = true;
+ }
+ Assert.assertTrue(exception);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+
+ // 2 bytes frame
+ in = IoBuffer.allocate(10);
+ in.put((byte) 0); //
+ in.put((byte) ModbusConstants.READ_HOLDING_REGISTERS);
+ in.flip();
+ // no exceptions
+ decoder.decode(session, in, out);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+
+ public void testAcceptMultiFrame() throws Exception {
+ LOG.info("Accept multi frame");
+ // write single register at address 1 and value 50, reply
+ TCPModbusMessage msg = new TCPModbusMessage(1, 16, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+
+ in = IoBuffer.allocate(100);
+ buff.flip(); // re-put
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+ }
+
+ public void testFragmentation() throws Exception {
+ LOG.info("Fragmentation");
+
+ // Read multiple register at address 1 and 10 values
+ TCPModbusMessage msgWrite10 = new TCPModbusMessage(1,
ModbusConstants.READ_HOLDING_REGISTERS, 1);
+ msgWrite10.setData(new byte[] { (byte) 20, (byte) 0, (byte) 1, (byte)
0, (byte) 2, (byte) 0, (byte) 3,
+ (byte) 0, (byte) 4, (byte) 0, (byte) 5, (byte) 0, (byte) 6,
(byte) 0, (byte) 7, (byte) 0, (byte) 8,
+ (byte) 0, (byte) 9, (byte) 0, (byte) 10 });
+
+ // Read multiple register at address 1 and 5 values
+ TCPModbusMessage msgWrite5 = new TCPModbusMessage(1,
ModbusConstants.READ_HOLDING_REGISTERS, 1);
+ msgWrite5.setData(new byte[] { (byte) 10, (byte) 0, (byte) 1, (byte)
0, (byte) 2, (byte) 0, (byte) 3, (byte) 0,
+ (byte) 4, (byte) 0, (byte) 5 });
+
+ // Read multiple register at address 1 and 4 values
+ TCPModbusMessage msgWrite4 = new TCPModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, 1);
+ msgWrite4.setData(new byte[] { (byte) 1, (byte) 0, (byte) 2, (byte) 0
});
+
+ IoBuffer buffPDU1 = msgWrite10.encode();
+ IoBuffer buffPDU2 = msgWrite5.encode();
+ IoBuffer buffPDU3 = msgWrite4.encode();
+ IoBuffer buffPDU123 = IoBuffer.allocate(buffPDU1.remaining() * 2 +
buffPDU2.remaining()
+ + buffPDU3.remaining());
+ buffPDU123.put(buffPDU1);
+
+ buffPDU123.put(buffPDU2);
+ buffPDU123.put(buffPDU3);
+ buffPDU1.rewind();
+ buffPDU123.put(buffPDU1);
+ buffPDU123.flip(); // PDU123 = PDU1 + PDU2 + PDU3 + PDU1
+
+ buffPDU1.flip();
+ buffPDU2.flip();
+
+ // decode a plain buffer
+ decoder.decode(session, buffPDU1, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ buffPDU1.rewind();
+
+ IoBuffer buff1 = IoBuffer.allocate(4);
+ while (buff1.hasRemaining()) {
+ buff1.put(buffPDU1.get());
+ }
+
+ buff1.flip();
+ // decode a part of a PDU
+ decoder.decode(session, buff1, out);
+
+ IoBuffer buff2 = IoBuffer.allocate(buffPDU1.remaining());
+ while (buffPDU1.hasRemaining()) {
+ buff2.put(buffPDU1.get());
+ }
+ buff2.flip();
+
+ // decode the second part
+ decoder.decode(session, buff2, out);
+
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+
+ // decode four concatenated big PDU
+ decoder.decode(session, buffPDU123, out);
+ Assert.assertEquals(6, session.getDecoderOutputQueue().size());
+
+ // decode multiple PDU each byte per each byte
+ buffPDU123.rewind();
+ while (buffPDU123.hasRemaining()) {
+ IoBuffer bufOneByte = IoBuffer.allocate(1);
+ bufOneByte.put(buffPDU123.get());
+ bufOneByte.flip();
+ decoder.decode(session, bufOneByte, out);
+ }
+ Assert.assertEquals(10, session.getDecoderOutputQueue().size());
+
+ TCPModbusMessage msg = (TCPModbusMessage)
session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite5));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite4));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ }
+
+ private boolean samePDU(TCPModbusMessage msg1, TCPModbusMessage msg2) {
+ if (msg1.getDevice() != msg2.getDevice()) {
+ return false;
+ }
+ if (msg1.getFunctionCode() != msg2.getFunctionCode()) {
+ return false;
+ }
+ if (!Arrays.equals(msg1.getData(), msg2.getData())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void testRandomPDU() {
+ LOG.info("Random PDU rejection");
+
+ Random rng = new Random();
+ for (int i = 0; i < 500; i++) {
+
+ IoBuffer buggedBuff = IoBuffer.allocate(8 + rng.nextInt(12));
+
+ while (buggedBuff.remaining() > 0) {
+ buggedBuff.put((byte) rng.nextInt());
+ }
+ buggedBuff.flip();
+ //System.err.println("random buffer of len :
"+buggedBuff.remaining());
+ try {
+ decoder.decode(session, buggedBuff, out);
+ } catch (Exception ex) {
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+ }
+
+ public void testByteInsertion() {
+ LOG.info("Insert one byte before PDU");
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer pduBuff = msg.encode();
+
+ IoBuffer buff = IoBuffer.allocate(pduBuff.remaining() + 1);
+ // add a zero before the PCU
+ buff.put((byte) 0);
+ buff.put(pduBuff);
+ buff.flip();
+ boolean exception = false;
+ try {
+ decoder.decode(session, buff, out);
+ } catch (Exception ex) {
+ exception = true;
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ Assert.assertTrue(exception);
+ }
+
+}
Propchange:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderMasterTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderTest.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderTest.java?rev=1084906&view=auto
==============================================================================
---
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderTest.java
(added)
+++
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderTest.java
Thu Mar 24 11:35:26 2011
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.modbus.transport.tcp;
+
+
+import java.util.Arrays;
+import java.util.Random;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.modbus.ModbusConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPModbusDecoderTest extends TestCase {
+ TCPModbusDecoder decoder = new TCPModbusDecoder(false);
+
+ ProtocolCodecSession session = new ProtocolCodecSession();
+ ProtocolDecoderOutput out = session.getDecoderOutput();
+
+ static final Logger LOG =
LoggerFactory.getLogger(TCPModbusDecoderTest.class);
+
+ public void testDecodeOneFrame() throws Exception {
+ LOG.info("Decode one frame");
+ // write single register at address 1 and value 50, reply
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff); // put
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ }
+
+ public void testRejectBuggedFrame() throws Exception {
+ LOG.info("Reject bugged frame");
+
+ // 4 bytes frame
+ IoBuffer in = IoBuffer.allocate(10);
+ in.putChar('A'); // some crap
+ in.putChar('F');
+ in.putChar('x');
+ in.putChar('x');
+ in.putChar('F');
+ in.flip();
+ //System.err.println("frame size : "+in.remaining());
+
+ boolean exception = false;
+ try {
+ decoder.decode(session, in, out);
+ } catch (ProtocolDecoderException e) {
+ exception = true;
+ }
+ Assert.assertTrue(exception);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+
+ // 2 bytes frame
+ in = IoBuffer.allocate(10);
+ in.put((byte) 0); //
+ in.put((byte) ModbusConstants.READ_HOLDING_REGISTERS);
+ in.flip();
+ // no exceptions
+ decoder.decode(session, in, out);
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+
+ public void testAcceptMultiFrame() throws Exception {
+ LOG.info("Accept multi frame");
+ // write single register at address 1 and value 50, reply
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer buff = msg.encode();
+
+ // Test one decode and one output
+ IoBuffer in = IoBuffer.allocate(100);
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+
+ in = IoBuffer.allocate(100);
+ buff.flip(); // re-put
+ in.put(buff);
+ in.flip();
+ decoder.decode(session, in, out);
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+ }
+
+ public void testFragmentation() throws Exception {
+ LOG.info("Fragmentation");
+
+ // write multiple register at address 1 and 10 values
+ TCPModbusMessage msgWrite10 = new TCPModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, 1);
+ msgWrite10.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte)
10, (byte) 20, (byte) 0, (byte) 1,
+ (byte) 0, (byte) 2, (byte) 0, (byte) 3, (byte) 0, (byte) 4,
(byte) 0, (byte) 5, (byte) 0, (byte) 6,
+ (byte) 0, (byte) 7, (byte) 0, (byte) 8, (byte) 0, (byte) 9,
(byte) 0, (byte) 10 });
+
+ // write multiple register at address 1 and 5 values
+ TCPModbusMessage msgWrite5 = new TCPModbusMessage(1,
ModbusConstants.READ_HOLDING_REGISTERS, 1);
+ msgWrite5.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 5
});
+
+ // write multiple register at address 1 and 5 values
+ TCPModbusMessage msgWrite4 = new TCPModbusMessage(1,
ModbusConstants.WRITE_MULTIPLE_REGISTERS, 1);
+ msgWrite4.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 4,
(byte) 8, (byte) 0, (byte) 1, (byte) 0,
+ (byte) 2, (byte) 0, (byte) 3, (byte) 0, (byte) 4 });
+
+ IoBuffer buffPDU1 = msgWrite10.encode();
+ IoBuffer buffPDU2 = msgWrite5.encode();
+ IoBuffer buffPDU3 = msgWrite4.encode();
+ IoBuffer buffPDU123 = IoBuffer.allocate(buffPDU1.remaining() * 2 +
buffPDU2.remaining()
+ + buffPDU3.remaining());
+ buffPDU123.put(buffPDU1);
+
+ buffPDU123.put(buffPDU2);
+ buffPDU123.put(buffPDU3);
+ buffPDU1.rewind();
+ buffPDU123.put(buffPDU1);
+ buffPDU123.flip(); // PDU123 = PDU1 + PDU2 + PDU3 + PDU1
+
+ buffPDU1.flip();
+ buffPDU2.flip();
+
+ // dezcode a plain buffer
+ decoder.decode(session, buffPDU1, out);
+ Assert.assertEquals(1, session.getDecoderOutputQueue().size());
+ buffPDU1.rewind();
+
+ IoBuffer buff1 = IoBuffer.allocate(4);
+ while (buff1.hasRemaining()) {
+ buff1.put(buffPDU1.get());
+ }
+
+ buff1.flip();
+
+ // decode a part of a PDU
+ decoder.decode(session, buff1, out);
+
+ IoBuffer buff2 = IoBuffer.allocate(buffPDU1.remaining());
+ while (buffPDU1.hasRemaining()) {
+ buff2.put(buffPDU1.get());
+ }
+ buff2.flip();
+
+ // decode the second part
+ decoder.decode(session, buff2, out);
+
+ Assert.assertEquals(2, session.getDecoderOutputQueue().size());
+
+ // decode four concatenated big PDU
+ decoder.decode(session, buffPDU123, out);
+ Assert.assertEquals(6, session.getDecoderOutputQueue().size());
+
+ // decode a big PDU each byte per each byte
+ buffPDU123.rewind();
+ while (buffPDU123.hasRemaining()) {
+ IoBuffer bufOneByte = IoBuffer.allocate(1);
+ bufOneByte.put(buffPDU123.get());
+ bufOneByte.flip();
+ decoder.decode(session, bufOneByte, out);
+ }
+ Assert.assertEquals(10, session.getDecoderOutputQueue().size());
+
+ TCPModbusMessage msg = (TCPModbusMessage)
session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite5));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite4));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+ msg = (TCPModbusMessage) session.getDecoderOutputQueue().poll();
+ Assert.assertTrue(samePDU(msg, msgWrite10));
+
+ }
+
+ private boolean samePDU(TCPModbusMessage msg1, TCPModbusMessage msg2) {
+ if (msg1.getDevice() != msg2.getDevice()) {
+ return false;
+ }
+ if (msg1.getFunctionCode() != msg2.getFunctionCode()) {
+ return false;
+ }
+ if (!Arrays.equals(msg1.getData(), msg2.getData())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void testRandomPDU() {
+ LOG.info("Random PDU rejection");
+ System.err.println("Start Random PDU test");
+ Random rng = new Random();
+ for (int i = 0; i < 5000; i++) {
+
+ IoBuffer buggedBuff = IoBuffer.allocate(8 + rng.nextInt(12));
+
+ while (buggedBuff.remaining() > 0) {
+ buggedBuff.put((byte) rng.nextInt());
+ }
+ buggedBuff.flip();
+ //System.err.println("random buffer of len :
"+buggedBuff.remaining());
+ try {
+ decoder.decode(session, buggedBuff, out);
+ } catch (Exception ex) {
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ }
+ }
+
+ public void testByteInsertion() {
+ LOG.info("Insert one byte before PDU");
+ TCPModbusMessage msg = new TCPModbusMessage(1, 6, 1);
+ msg.setData(new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 50 });
+ IoBuffer pduBuff = msg.encode();
+
+ IoBuffer buff = IoBuffer.allocate(pduBuff.remaining() + 1);
+ // add a zero before the PCU
+ buff.put((byte) 0);
+ buff.put(pduBuff);
+ buff.flip();
+ boolean exception = false;
+ try {
+ decoder.decode(session, buff, out);
+ } catch (Exception ex) {
+ exception = true;
+ }
+ Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ Assert.assertTrue(exception);
+ }
+
+}
Propchange:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusDecoderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusEncoderTest.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusEncoderTest.java?rev=1084906&view=auto
==============================================================================
---
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusEncoderTest.java
(added)
+++
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusEncoderTest.java
Thu Mar 24 11:35:26 2011
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.modbus.transport.tcp;
+
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecSession;
+import org.apache.mina.filter.codec.ProtocolEncoderException;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.modbus.ModbusConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPModbusEncoderTest extends TestCase {
+
+ static final Logger LOG =
LoggerFactory.getLogger(TCPModbusEncoderTest.class);
+
+ TCPModbusEncoder encoder = new TCPModbusEncoder();
+ ProtocolCodecSession session = new ProtocolCodecSession();
+ ProtocolEncoderOutput out = session.getEncoderOutput();
+
+ public void testEncodeMessage() throws ProtocolEncoderException {
+
+ TCPModbusMessage tcp = new TCPModbusMessage(1,
ModbusConstants.READ_HOLDING_REGISTERS, 1);
+ tcp.setData(new byte[] { (byte) 1, (byte) 10 });
+
+
+ encoder.encode(session, tcp, out);
+
+ IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue().poll();
+ Assert.assertEquals(buf, tcp.encode());
+
+ tcp.setFunctionCode(ModbusConstants.READ_INPUT_REGISTERS);
+
+ encoder.encode(session, tcp, out);
+ buf = (IoBuffer) session.getEncoderOutputQueue().poll();
+ Assert.assertEquals(buf, tcp.encode());
+ }
+
+ public void testProtocolEncoderException() throws ProtocolEncoderException
{
+
+ boolean excep = false;
+ try {
+ encoder.encode(session, new String(), out);
+ } catch (ProtocolEncoderException e) {
+ excep = true;
+ }
+
+ Assert.assertTrue(excep);
+ }
+
+}
Propchange:
mina/sandbox/jvermillard/mina-modbus/src/test/java/org/apache/mina/modbus/transport/tcp/TCPModbusEncoderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain