diff options
author | Ivan Muratov <binakot@gmail.com> | 2017-07-17 10:58:49 +0300 |
---|---|---|
committer | Ivan Muratov <binakot@gmail.com> | 2017-07-17 10:58:49 +0300 |
commit | 79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8 (patch) | |
tree | f6a21114ad7e97b8f2d497f684f57efad06c477b /test/org/traccar | |
parent | 43521d805b9608d107847838e4cd769d6f27ea91 (diff) | |
download | trackermap-server-79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8.tar.gz trackermap-server-79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8.tar.bz2 trackermap-server-79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8.zip |
Rewrite the code of frame decoder.
Added tests with invalid packets.
Diffstat (limited to 'test/org/traccar')
-rw-r--r-- | test/org/traccar/protocol/Arnavi4FrameDecoderTest.java | 23 |
1 files changed, 21 insertions, 2 deletions
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 |