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());
}
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());
}
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);
}
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());
}
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));
}
Aggregations