use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerRealTest method coding1dot5.
@Test
public void coding1dot5() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
BerReal berReal = new BerReal(1.5);
berReal.encode(berStream, true);
// System.out.println(DatatypeConverter.printHexBinary(berStream.getArray()));
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090380FF03"), berStream.getArray());
ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
BerReal berRealDecoded = new BerReal();
berRealDecoded.decode(berInputStream, true);
Assert.assertEquals(1.5, berRealDecoded.value, 0.01);
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerRealTest method coding0dot2.
@Test
public void coding0dot2() throws IOException {
final BerReal orig = new BerReal(0.2);
final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true);
orig.encode(baos, true);
final BerReal decoded = new BerReal();
decoded.decode(new ByteArrayInputStream(baos.getArray()), true);
Assert.assertEquals(orig.value, decoded.value, 0.001);
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerRealTest method codingZero.
@Test
public void codingZero() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
BerReal berReal = new BerReal(0);
berReal.encode(berStream, true);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("0900"), berStream.getArray());
ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
BerReal berRealDecoded = new BerReal();
berRealDecoded.decode(berInputStream, true);
Assert.assertEquals(0, berRealDecoded.value, 0.01);
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class TaggingTest method explicitlyTaggedSeqOfTest.
@Test
public void explicitlyTaggedSeqOfTest() throws Exception {
ExplicitlyTaggedSeqOf seqOf = new ExplicitlyTaggedSeqOf();
List<BerInteger> integerList = seqOf.getBerInteger();
integerList.add(new BerInteger(3));
integerList.add(new BerInteger(4));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
seqOf.encode(os);
System.out.println("seqOf : " + DatatypeConverter.printHexBinary(os.getArray()));
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF21083006020103020104"), os.getArray());
seqOf = new ExplicitlyTaggedSeqOf();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class TaggingTest method seqOfExplicitlyTaggedTypeTest.
@Test
public void seqOfExplicitlyTaggedTypeTest() throws Exception {
SeqOfExplicitlyTaggedType seqOf = new SeqOfExplicitlyTaggedType();
List<BerInteger> integerList = seqOf.getBerInteger();
integerList.add(new BerInteger(3));
integerList.add(new BerInteger(4));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
seqOf.encode(os);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("300AA303020103A303020104"), os.getArray());
seqOf = new SeqOfExplicitlyTaggedType();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
Aggregations