aboutsummaryrefslogtreecommitdiff
path: root/test/org
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:24:44 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:24:44 +0200
commit4b9aa8e7c98a3420a698b1520ee63060409c7d88 (patch)
tree8598434570526fe27d832271a155e8a47f154fef /test/org
parentc1de08db7773eef6b1ed4a6e2b62f15d1df6a2a5 (diff)
downloadtraccar-server-4b9aa8e7c98a3420a698b1520ee63060409c7d88.tar.gz
traccar-server-4b9aa8e7c98a3420a698b1520ee63060409c7d88.tar.bz2
traccar-server-4b9aa8e7c98a3420a698b1520ee63060409c7d88.zip
binary encoder + test
Diffstat (limited to 'test/org')
-rw-r--r--test/org/traccar/ProtocolTest.java8
-rw-r--r--test/org/traccar/protocol/WatchProtocolEncoderTest.java14
2 files changed, 14 insertions, 8 deletions
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 1b5c0ea00..181af885d 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -52,6 +52,14 @@ public class ProtocolTest extends BaseTest {
return builder.toString();
}
+ protected ByteBuf concatenateBuffers(ByteBuf... buffers) {
+ ByteBuf result = Unpooled.buffer();
+ for (ByteBuf buf : buffers) {
+ result.writeBytes(buf);
+ }
+ return result;
+ }
+
protected ByteBuf binary(String... data) {
return Unpooled.wrappedBuffer(DataConverter.parseHex(concatenateStrings(data)));
}
diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
index 05faa1f53..e73b5bb96 100644
--- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
@@ -4,8 +4,6 @@ import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
-import java.nio.charset.StandardCharsets;
-
import static org.junit.Assert.assertEquals;
public class WatchProtocolEncoderTest extends ProtocolTest {
@@ -33,25 +31,25 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "3333");
- assertEquals("[CS*123456789012345*0005*TK,33]", encoder.encodeCommand(null, command));
+ assertEquals(buffer("[CS*123456789012345*0005*TK,33]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "2321414d520a2573");
- assertEquals("[CS*123456789012345*000b*TK,#!AMR\n%s]", encoder.encodeCommand(null, command));
+ assertEquals(buffer("[CS*123456789012345*000b*TK,#!AMR\n%s]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
- command.set(Command.KEY_DATA, "ff");
- assertEquals("[CS*123456789012345*0004*TK," + binary("ff").toString(StandardCharsets.ISO_8859_1) + ']', encoder.encodeCommand(null, command));
+ command.set(Command.KEY_DATA, "7d5b5d2c2a");
+ verifyFrame(concatenateBuffers(buffer("[CS*123456789012345*000d*TK,"), binary("7d017d027d037d047d05"), buffer("]")), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
- command.set(Command.KEY_DATA, "7d5b5d2c2a");
- assertEquals("[CS*123456789012345*000d*TK," + binary("7d017d027d037d047d05").toString(StandardCharsets.ISO_8859_1) + ']', encoder.encodeCommand(null, command));
+ command.set(Command.KEY_DATA, "ff");
+ verifyFrame(concatenateBuffers(buffer("[CS*123456789012345*0004*TK,"), binary("ff"), buffer("]")), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);