Search in sources :

Example 1 with ValueBuffer

use of org.openhab.core.io.transport.modbus.ValueBuffer in project openhab-core by openhab.

the class ValueBufferTest method testPosition.

@Test
public void testPosition() {
    ValueBuffer wrap = ValueBuffer.wrap(new byte[] { 0, 0, 0, 1, 3, -1, -2 });
    assertEquals(0, wrap.position());
    wrap.position(4);
    assertEquals(4, wrap.position());
    assertEquals(3, wrap.getSInt8());
    assertEquals(5, wrap.position());
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with ValueBuffer

use of org.openhab.core.io.transport.modbus.ValueBuffer in project openhab-core by openhab.

the class ValueBufferTest method testMarkLowerThanPosition.

@Test
public void testMarkLowerThanPosition() {
    ValueBuffer wrap = ValueBuffer.wrap(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFC, 0x14, 3, -1, -2 });
    assertEquals(-1004, wrap.getSInt32());
    wrap.position(4);
    wrap.mark();
    assertEquals(4, wrap.position());
    // mark = position
    wrap.position(4);
    assertEquals(4, wrap.position());
    wrap.reset();
    assertEquals(4, wrap.position());
    // mark > position
    wrap.position(6);
    assertEquals(6, wrap.position());
    wrap.reset();
    assertEquals(4, wrap.position());
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) Test(org.junit.jupiter.api.Test)

Example 3 with ValueBuffer

use of org.openhab.core.io.transport.modbus.ValueBuffer in project openhab-core by openhab.

the class ValueBufferTest method testMarkHigherThanPosition.

@Test
public void testMarkHigherThanPosition() {
    ValueBuffer wrap = ValueBuffer.wrap(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFC, 0x14, 3, -1, -2 });
    assertEquals(-1004, wrap.getSInt32());
    wrap.position(4);
    wrap.mark();
    assertEquals(4, wrap.position());
    // mark = position
    wrap.position(4);
    assertEquals(4, wrap.position());
    wrap.reset();
    assertEquals(4, wrap.position());
    // position < mark
    // Mark is removed here
    wrap.position(3);
    assertEquals(3, wrap.position());
    boolean caughtException = false;
    try {
        wrap.reset();
    } catch (InvalidMarkException e) {
        // OK, expected
        caughtException = true;
    }
    assertTrue(caughtException);
    assertEquals(3, wrap.position());
    // Mark is removed. Reset unaccessible even with original position of 4
    wrap.position(4);
    assertEquals(4, wrap.position());
    caughtException = false;
    try {
        wrap.reset();
    } catch (InvalidMarkException e) {
        // OK, expected
        caughtException = true;
    }
    assertTrue(caughtException);
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) InvalidMarkException(java.nio.InvalidMarkException) Test(org.junit.jupiter.api.Test)

Example 4 with ValueBuffer

use of org.openhab.core.io.transport.modbus.ValueBuffer in project openhab-core by openhab.

the class ValueBufferTest method testMarkReset.

@Test
public void testMarkReset() {
    ValueBuffer wrap = ValueBuffer.wrap(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFC, 0x14, 3, -1, -2 });
    wrap.mark();
    assertEquals(-1004, wrap.getSInt32());
    wrap.reset();
    assertEquals(4294966292L, wrap.getUInt32());
    wrap.mark();
    assertEquals(3, wrap.getSInt8());
    wrap.reset();
    assertEquals(3, wrap.getSInt8());
    assertEquals(-1, wrap.getSInt8());
    assertEquals(254, wrap.getUInt8());
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) Test(org.junit.jupiter.api.Test)

Example 5 with ValueBuffer

use of org.openhab.core.io.transport.modbus.ValueBuffer in project openhab-core by openhab.

the class ValueBufferTest method testBulkGetBufferOverflow.

@Test
public void testBulkGetBufferOverflow() {
    ValueBuffer wrap = ValueBuffer.wrap(new byte[] { 0, 0 });
    byte[] threeBytes = new byte[3];
    assertThrows(BufferOverflowException.class, () -> wrap.get(threeBytes));
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 ValueBuffer (org.openhab.core.io.transport.modbus.ValueBuffer)10 InvalidMarkException (java.nio.InvalidMarkException)1