From 79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8 Mon Sep 17 00:00:00 2001 From: Ivan Muratov Date: Mon, 17 Jul 2017 10:58:49 +0300 Subject: Rewrite the code of frame decoder. Added tests with invalid packets. --- .../traccar/protocol/Arnavi4FrameDecoderTest.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test/org') diff --git a/test/org/traccar/protocol/Arnavi4FrameDecoderTest.java b/test/org/traccar/protocol/Arnavi4FrameDecoderTest.java index 93d818f56..2203cdafc 100644 --- a/test/org/traccar/protocol/Arnavi4FrameDecoderTest.java +++ b/test/org/traccar/protocol/Arnavi4FrameDecoderTest.java @@ -9,7 +9,7 @@ import java.nio.ByteOrder; public class Arnavi4FrameDecoderTest extends ProtocolTest { @Test - public void testDecode() throws Exception { + public void testDecodeValidPackets() throws Exception { Arnavi4FrameDecoder decoder = new Arnavi4FrameDecoder(); @@ -21,7 +21,7 @@ public class Arnavi4FrameDecoderTest extends ProtocolTest { binary(ByteOrder.LITTLE_ENDIAN, "ff23f30c45f5c90f0300"), decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "ff23f30c45f5c90f0300"))); - Assert.assertEquals( // Valid PACKAGE with answer to server on file transfer. + Assert.assertEquals( // Valid PACKAGE with answer to server on file transfer null, decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "5bfd005d"))); @@ -43,4 +43,23 @@ public class Arnavi4FrameDecoderTest extends ProtocolTest { } + @Test + public void testDecodeInvalidPackets() throws Exception { + + Arnavi4FrameDecoder decoder = new Arnavi4FrameDecoder(); + + Assert.assertEquals( // Invalid PACKAGE with one DATA packet (missing last byte with end sign) + null, + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "5b01012800a3175f5903513934420447221c42055402781E0900f0c5215b4e0084005c00007c005d0000a300fa3701000029"))); + + Assert.assertEquals( // Invalid PACKAGE with two DATA packet (missing last 10 bytes) + null, + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "5b01012800a3175f5903513934420447221c42055402781E0900f0c5215b4e0084005c00007c005d0000a300fa3701000029012800a3175f5903513934420447221c42055402781E0900f0c5215b4e0084005c00007c005d00"))); + + Assert.assertEquals( // Valid PACKAGE with useless extra bytes at the end + binary(ByteOrder.LITTLE_ENDIAN, "5b01012800a3175f5903513934420447221c42055402781E0900f0c5215b4e0084005c00007c005d0000a300fa37010000295d"), + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "5b01012800a3175f5903513934420447221c42055402781E0900f0c5215b4e0084005c00007c005d0000a300fa37010000295d010203040506070809"))); + + } + } \ No newline at end of file -- cgit v1.2.3