aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-18 13:18:28 -0800
committerGitHub <noreply@github.com>2019-02-18 13:18:28 -0800
commit0e209e80f03e72095e5b449679925066b01403d2 (patch)
tree881ab37ce5867fd8358d4bdf0195824c47e26be2 /test
parent774d560ecb5f8da9e64059a4d25622c4fba55bf2 (diff)
parentc82be0541481955a0832948574244f31757f7067 (diff)
downloadtrackermap-server-0e209e80f03e72095e5b449679925066b01403d2.tar.gz
trackermap-server-0e209e80f03e72095e5b449679925066b01403d2.tar.bz2
trackermap-server-0e209e80f03e72095e5b449679925066b01403d2.zip
Merge pull request #4221 from flocsy/8bit-voice-message
Fixed 8bit voice message
Diffstat (limited to 'test')
-rw-r--r--test/org/traccar/BaseTest.java29
-rw-r--r--test/org/traccar/ProtocolTest.java12
-rw-r--r--test/org/traccar/protocol/WatchFrameDecoderTest.java4
-rw-r--r--test/org/traccar/protocol/WatchProtocolDecoderTest.java24
-rw-r--r--test/org/traccar/protocol/WatchProtocolEncoderTest.java31
5 files changed, 85 insertions, 15 deletions
diff --git a/test/org/traccar/BaseTest.java b/test/org/traccar/BaseTest.java
index fb1b5de8f..0b2c616ce 100644
--- a/test/org/traccar/BaseTest.java
+++ b/test/org/traccar/BaseTest.java
@@ -1,9 +1,34 @@
package org.traccar;
+import io.netty.buffer.ByteBuf;
+import org.traccar.database.MediaManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
public class BaseTest {
-
+
+ public static class MockMediaManager extends MediaManager {
+ Map<String, ByteBuf> files = new HashMap<>();
+
+ MockMediaManager() {
+ super("");
+ }
+
+ @Override
+ public String writeFile(String uniqueId, ByteBuf buf, String extension) {
+ String fileName = uniqueId + "/mock." + extension;
+ files.put(fileName, buf);
+ return fileName;
+ }
+
+ public ByteBuf readFile(String fileName) {
+ return files.get(fileName);
+ }
+ }
+
static {
- Context.init(new TestIdentityManager());
+ Context.init(new TestIdentityManager(), new MockMediaManager());
}
}
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 1b5c0ea00..377474556 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)));
}
@@ -60,6 +68,10 @@ public class ProtocolTest extends BaseTest {
return concatenateStrings(data);
}
+ protected String text(ByteBuf data) {
+ return data.toString(StandardCharsets.ISO_8859_1);
+ }
+
protected ByteBuf buffer(String... data) {
return Unpooled.copiedBuffer(concatenateStrings(data), StandardCharsets.ISO_8859_1);
}
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("]"))));
+
}
}
diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
index b7c8d83f9..51846f51a 100644
--- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -1,7 +1,17 @@
package org.traccar.protocol;
+import io.netty.buffer.ByteBuf;
import org.junit.Test;
+import org.traccar.Context;
import org.traccar.ProtocolTest;
+import org.traccar.database.MediaManager;
+import org.traccar.model.Position;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class WatchProtocolDecoderTest extends ProtocolTest {
@@ -101,7 +111,19 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, buffer(
"[ZJ*014111001350304*0038*008a*UD,070318,021027,V,00.000000,N,000.000000,E,0,0,0,0,100,18,1000,50,00000000,4,255,460,0,9346,5223,42,9346,5214,20,9784,4083,11,9346,5221,5]"));
-
}
+ @Test
+ public void testDecodeVoiceMessage() throws Exception {
+ WatchProtocolDecoder decoder = new WatchProtocolDecoder(null);
+
+ verifyNull(decoder.decode(null, null, buffer("[CS*1234567890*0004*TK,1]")));
+
+ String hex = "7d5b5d2c2aff";
+ Object decodedObject = decoder.decode(null, null, concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), binary(hex), buffer("]")));
+ assertTrue("not a position", decodedObject instanceof Position);
+ Position position = (Position) decodedObject;
+ assertEquals("1234567890/mock.amr", position.getAttributes().get("audio"));
+ verifyFrame(concatenateBuffers(buffer("#!AMR"), binary(hex)), ((MockMediaManager) Context.getMediaManager()).readFile("1234567890/mock.amr"));
+ }
}
diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
index f55086082..649f5a10d 100644
--- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
@@ -1,5 +1,6 @@
package org.traccar.protocol;
+import io.netty.buffer.ByteBuf;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
@@ -18,53 +19,59 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- assertEquals("[CS*123456789012345*0005*RESET]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0005*RESET]", text((ByteBuf)encoder.encodeCommand(null, command)));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SOS_NUMBER);
command.set(Command.KEY_INDEX, 1);
command.set(Command.KEY_PHONE, "123456789");
- assertEquals("[CS*123456789012345*000e*SOS1,123456789]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*000e*SOS1,123456789]", text((ByteBuf)encoder.encodeCommand(null, command)));
command = new Command();
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));
+ command.set(Command.KEY_DATA, "2321414d520a2573");
+ 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, "2321414d520a2573");
- assertEquals("[CS*123456789012345*000b*TK,#!AMR\n%s]", 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, "ff");
+ verifyFrame(concatenateBuffers(buffer("[CS*123456789012345*0004*TK,"), binary("ff"), buffer("]")), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_MESSAGE);
command.set(Command.KEY_MESSAGE, "text");
- assertEquals("[CS*123456789012345*0018*MESSAGE,0074006500780074]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0018*MESSAGE,0074006500780074]", text((ByteBuf)encoder.encodeCommand(null, command)));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "WORK,6-9,11-13,13-15,17-19");
- assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", text((ByteBuf)encoder.encodeCommand(null, command)));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SET_TIMEZONE);
command.set(Command.KEY_TIMEZONE, "Europe/Amsterdam");
- assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0006*LZ,,+1]", text((ByteBuf)encoder.encodeCommand(null, command)));
command.set(Command.KEY_TIMEZONE, "GMT+01:30");
- assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", text((ByteBuf)encoder.encodeCommand(null, command)));
command.set(Command.KEY_TIMEZONE, "Atlantic/Azores");
- assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0006*LZ,,-1]", text((ByteBuf)encoder.encodeCommand(null, command)));
command.set(Command.KEY_TIMEZONE, "GMT-11:30");
- assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(null, command));
+ assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", text((ByteBuf)encoder.encodeCommand(null, command)));
}