Search in sources :

Example 1 with KlvLong

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));
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong) Test(org.junit.Test)

Example 2 with KlvLong

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));
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong) Test(org.junit.Test)

Example 3 with KlvLong

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)));
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong) KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) Test(org.junit.Test)

Example 4 with KlvLong

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));
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong) Date(java.util.Date) Test(org.junit.Test)

Example 5 with KlvLong

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);
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong)

Aggregations

KlvLong (org.codice.ddf.libs.klv.data.numerical.KlvLong)6 Test (org.junit.Test)4 Date (java.util.Date)1 KlvByte (org.codice.ddf.libs.klv.data.numerical.KlvByte)1 KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)1 KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)1 KlvShort (org.codice.ddf.libs.klv.data.numerical.KlvShort)1 KlvUnsignedByte (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1 KlvString (org.codice.ddf.libs.klv.data.text.KlvString)1 BeforeClass (org.junit.BeforeClass)1