use of org.codice.ddf.libs.klv.data.numerical.KlvLong in project ddf by codice.
the class KlvDecoderTest method testLongValue.
@Test
public void testLongValue() throws KlvDecodingException {
final byte[] klvBytes = { -8, 8, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x50, (byte) 0x96, (byte) 0xE1, (byte) 0xF1 };
final KlvLong klvLong = new KlvLong(new byte[] { -8 }, "test");
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvLong, klvBytes);
final long value = ((KlvLong) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(-2942901775L));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvLong in project ddf by codice.
the class KlvDecoderTest method testUnsignedIntValue.
@Test
public void testUnsignedIntValue() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, (byte) 0xAF, 0x69, 0x1E, 0x0F };
final KlvLong klvUnsignedInt = new KlvLong(new byte[] { -8 }, "test");
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvUnsignedInt, klvBytes);
final long value = ((KlvLong) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(2942901775L));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvLong in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsUnsignedInt.
@Test
public // 160.719211474396, which is wrong.
void testFloatingPointEncodedAsUnsignedInt() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, 0x72, 0x4A, 0x0A, 0x20 };
final KlvLong klvUnsignedInt = new KlvLong(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint sensorRelativeAzimuth = new KlvIntegerEncodedFloatingPoint(klvUnsignedInt, 0, (1L << 32) - 1, 0, 360);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, sensorRelativeAzimuth, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(160.719211436975, 1e-12)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvLong in project alliance by codice.
the class ListOfDatesHandlerTest method testAcceptingData.
@Test
public void testAcceptingData() {
Date testDate = new Date();
KlvLong klvLong = mock(KlvLong.class);
when(klvLong.getValue()).thenReturn(TimeUnit.MILLISECONDS.toMicros(testDate.getTime()));
klvHandler.accept(klvLong);
assertThat(klvHandler.asAttribute().isPresent(), is(true));
assertThat(klvHandler.asAttribute().get().getValue(), is(testDate));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvLong in project ddf by codice.
the class KlvDecoderTest method isErrorIndicatedLong.
private boolean isErrorIndicatedLong(long value, Optional<Long> errorValue) throws KlvDecodingException {
KlvLong klvLong = new KlvLong(new byte[] { 0 }, "test", errorValue);
byte[] dataBytes = new byte[10];
dataBytes[0] = 0;
dataBytes[1] = 8;
arraycopy(longToBytes(value), 0, dataBytes, 2, 8);
return isErrorIndicatedDecode(klvLong, dataBytes);
}
Aggregations