aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:28:00 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:28:00 +0200
commit1e0e3a43894466246d6042ec71b9c01f63c58b13 (patch)
treebb45a9986590e1d4565f27d72e741387da00bafd
parent4b9aa8e7c98a3420a698b1520ee63060409c7d88 (diff)
downloadtrackermap-server-1e0e3a43894466246d6042ec71b9c01f63c58b13.tar.gz
trackermap-server-1e0e3a43894466246d6042ec71b9c01f63c58b13.tar.bz2
trackermap-server-1e0e3a43894466246d6042ec71b9c01f63c58b13.zip
binary decoder test
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java6
-rw-r--r--test/org/traccar/protocol/WatchFrameDecoderTest.java4
2 files changed, 8 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java
index b2ac5b4f7..b4a82c0be 100644
--- a/src/org/traccar/protocol/WatchFrameDecoder.java
+++ b/src/org/traccar/protocol/WatchFrameDecoder.java
@@ -33,7 +33,8 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
while (buf.readerIndex() < endIndex) {
byte b = buf.readByte();
if (b == '}') {
- switch (buf.readByte()) {
+ byte c = buf.readByte();
+ switch (c) {
case 0x01:
frame.writeByte('}');
break;
@@ -50,7 +51,8 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
frame.writeByte('*');
break;
default:
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(String.format(
+ "unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, c));
}
} else {
frame.writeByte(b);
diff --git a/test/org/traccar/protocol/WatchFrameDecoderTest.java b/test/org/traccar/protocol/WatchFrameDecoderTest.java
index 741807de2..4e40eea86 100644
--- a/test/org/traccar/protocol/WatchFrameDecoderTest.java
+++ b/test/org/traccar/protocol/WatchFrameDecoderTest.java
@@ -26,6 +26,10 @@ public class WatchFrameDecoderTest extends ProtocolTest {
binary("5b5a4a2a3031343131313030313335303330342a303033342a303030392a4c4b2c302c302c31395d"),
decoder.decode(null, null, binary("5b5a4a2a3031343131313030313335303330342a303033342a303030392a4c4b2c302c302c31395d")));
+ verifyFrame(
+ concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), binary("7d5b5d2c2aff"), buffer("]")),
+ decoder.decode(null, null, concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), binary("7d017d027d037d047d05ff"), buffer("]"))));
+
}
}