aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2022-02-04 23:55:53 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2022-02-04 23:56:14 -0800
commit0738af216e7b31926e05d3de64e14e5b7f0b214c (patch)
tree411dbb6f1241ef2051d4bd3ac3817910e2415492 /src/test/java
parent5878ea602d087da291687a0120b5a3f31f7ee861 (diff)
downloadtrackermap-server-0738af216e7b31926e05d3de64e14e5b7f0b214c.tar.gz
trackermap-server-0738af216e7b31926e05d3de64e14e5b7f0b214c.tar.bz2
trackermap-server-0738af216e7b31926e05d3de64e14e5b7f0b214c.zip
Fix buffer search
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/traccar/helper/BufferUtilTest.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/org/traccar/helper/BufferUtilTest.java b/src/test/java/org/traccar/helper/BufferUtilTest.java
new file mode 100644
index 000000000..b539b5b28
--- /dev/null
+++ b/src/test/java/org/traccar/helper/BufferUtilTest.java
@@ -0,0 +1,35 @@
+package org.traccar.helper;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.assertEquals;
+
+public class BufferUtilTest {
+
+ @Test
+ public void test1() {
+ ByteBuf buf = Unpooled.copiedBuffer("abcdef", StandardCharsets.US_ASCII);
+ assertEquals(2, BufferUtil.indexOf("cd", buf));
+ }
+
+ @Test
+ public void test2() {
+ ByteBuf buf = Unpooled.copiedBuffer("abcdef", StandardCharsets.US_ASCII);
+ buf.readerIndex(1);
+ buf.writerIndex(5);
+ assertEquals(2, BufferUtil.indexOf("cd", buf));
+ }
+
+ @Test
+ public void test3() {
+ ByteBuf buf = Unpooled.copiedBuffer("abcdefgh", StandardCharsets.US_ASCII);
+ buf.readerIndex(1);
+ buf.writerIndex(7);
+ assertEquals(3, BufferUtil.indexOf("de", buf, 2, 6));
+ }
+
+}