Search in sources :

Example 21 with ReverseByteArrayOutputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 22 with ReverseByteArrayOutputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 23 with ReverseByteArrayOutputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 24 with ReverseByteArrayOutputStream

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()));
}
Also used : ExplicitlyTaggedSeqOf(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSeqOf) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 25 with ReverseByteArrayOutputStream

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()));
}
Also used : SeqOfExplicitlyTaggedType(org.openmuc.jasn1.compiler.tagging_test.SeqOfExplicitlyTaggedType) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)44 Test (org.junit.Test)38 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerOctetString (org.openmuc.jasn1.ber.types.BerOctetString)4 BerUTF8String (org.openmuc.jasn1.ber.types.string.BerUTF8String)4 ProfileElement (org.openmuc.jasn1.compiler.pedefinitions.ProfileElement)4 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 BerNull (org.openmuc.jasn1.ber.types.BerNull)3 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 PEHeader (org.openmuc.jasn1.compiler.pedefinitions.PEHeader)2 UInt15 (org.openmuc.jasn1.compiler.pedefinitions.UInt15)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 ChildInformation (org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation)2 Date (org.openmuc.jasn1.compiler.x690_ber_example.Date)2 EmployeeNumber (org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber)2