From 9d548e3aab48e9f13c51c5f974b06e29db8d1d0c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 18 Dec 2016 23:33:27 +1300 Subject: Implement bit buffer utility --- test/org/traccar/helper/BitBufferTest.java | 23 ++++++++++++++++ .../traccar/protocol/AisProtocolDecoderTest.java | 31 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/org/traccar/helper/BitBufferTest.java create mode 100644 test/org/traccar/protocol/AisProtocolDecoderTest.java (limited to 'test/org/traccar') diff --git a/test/org/traccar/helper/BitBufferTest.java b/test/org/traccar/helper/BitBufferTest.java new file mode 100644 index 000000000..c2abad36d --- /dev/null +++ b/test/org/traccar/helper/BitBufferTest.java @@ -0,0 +1,23 @@ +package org.traccar.helper; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BitBufferTest { + + @Test + public void test() { + BitBuffer buffer = new BitBuffer(); + + buffer.write(0b100100); + buffer.write(0b110110); + buffer.write(0b111111); + buffer.write(0b111111); + + assertEquals(0b100, buffer.readUnsigned(3)); + assertEquals(-7, buffer.readSigned(4)); + assertEquals(0b10110, buffer.readUnsigned(5)); + } + +} diff --git a/test/org/traccar/protocol/AisProtocolDecoderTest.java b/test/org/traccar/protocol/AisProtocolDecoderTest.java new file mode 100644 index 000000000..a6c9d4c84 --- /dev/null +++ b/test/org/traccar/protocol/AisProtocolDecoderTest.java @@ -0,0 +1,31 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class AisProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + AisProtocolDecoder decoder = new AisProtocolDecoder(new AisProtocol()); + + verifyPositions(decoder, text( + "!AIVDM,2,1,8,A,53UlSb01l>Ei=H4KF218PTpv222222222222221?8h=766gB00000K6J;5KAIT03wpUkP06,0*5D\\s:MTb827ebc7686b,c:1481688230418*45\\\r\n" + + "!AIVDM,1,1,,B,B52Q8a@00Ul`9N5@ssbmCwr5oP06,0*36\r\n" + + "!AIVDM,1,1,,A,18154?v<2D=j,0*54\r\n\r\n")); + + } + +} -- cgit v1.2.3