aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/helper/ChannelBufferToolsTest.java
blob: d34dfe9f7365642dda65dd13008cf1606c7e3c1b (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
package org.traccar.helper;

import org.jboss.netty.buffer.ChannelBuffers;

import static org.junit.Assert.*;
import org.junit.Test;

public class ChannelBufferToolsTest {
    
    @Test
    public void testReadHexInteger() {
        byte[] buf = {0x01, (byte) 0x90, 0x34};
        int result = ChannelBufferTools.readHexInteger(
                ChannelBuffers.wrappedBuffer(buf), 5);
        assertEquals(1903, result);
    }
    
    @Test
    public void testReadHexString() {
        byte[] buf = {0x01, (byte) 0x90, 0x34};
        String result = ChannelBufferTools.readHexString(
                ChannelBuffers.wrappedBuffer(buf), 5);
        assertEquals("01903", result);
        
        result = String.valueOf(Long.parseLong(result));
        assertEquals("1903", result);
    }

    @Test
    public void convertHexStringTest() {
        assertArrayEquals(new byte[] {0x12, 0x34}, ChannelBufferTools.hexToBytes("1234"));
    }

    @Test
    public void convertHexByteArray() {
        assertEquals("1234", ChannelBufferTools.bytesToHex(new byte[]{0x12, 0x34}));
    }

}