blob: 707e419ec9ee1a819e48477675c3f6b411fc3841 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package org.traccar.helper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class BufferUtilTest {
@Test
public void testReadSignedMagnitudeInt() {
ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex("80000001"));
assertEquals(-1, BufferUtil.readSignedMagnitudeInt(buf));
}
@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));
}
}
|