Search in sources :

Example 11 with BerInteger

use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.

the class TaggingTest method explicitlyTaggedSetTest.

@Test
public void explicitlyTaggedSetTest() throws Exception {
    ExplicitlyTaggedSet set = new ExplicitlyTaggedSet();
    set.setMyInteger(new BerInteger(1));
    set.setMyBoolean(new BerBoolean(true));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    set.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210831060201010101FF"), os.getArray());
    set = new ExplicitlyTaggedSet();
    set.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(set.getMyInteger());
    Assert.assertNotNull(set.getMyBoolean());
}
Also used : ExplicitlyTaggedSet(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSet) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 12 with BerInteger

use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.

the class TaggingTest method implicitlyRetaggedTaggedChoiceTest.

@Test
public void implicitlyRetaggedTaggedChoiceTest() throws Exception {
    ImplicitlyRetaggedTaggedChoice choice = new ImplicitlyRetaggedTaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("A303020101"), os.getArray());
}
Also used : ImplicitlyRetaggedTaggedChoice(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 13 with BerInteger

use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.

the class TaggingTest method sequenceOfDirectTypesTest.

@Test
public void sequenceOfDirectTypesTest() throws Exception {
    SequenceOfDirectTypes sequence = new SequenceOfDirectTypes();
    sequence.setUntaggedInt(new BerInteger(1));
    sequence.setExplicitlyTaggedInt(new BerInteger(2));
    sequence.setImplicitlyTaggedInt(new BerInteger(3));
    UntaggedChoice untaggedChoice = new UntaggedChoice();
    untaggedChoice.setMyBoolean(new BerBoolean(true));
    sequence.setUntaggedChoice(untaggedChoice);
    SequenceOfDirectTypes.TaggedChoice taggedChoice = new SequenceOfDirectTypes.TaggedChoice();
    taggedChoice.setMyInteger(new BerInteger(4));
    sequence.setTaggedChoice(taggedChoice);
    sequence.setTaggedAny(new BerAny(new byte[] { 2, 1, 1 }));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    sequence.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2B18020101A1030201028201038401FFA503830104A603020101"), os.getArray());
    sequence = new SequenceOfDirectTypes();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertEquals(1, sequence.getUntaggedInt().value.intValue());
    Assert.assertEquals(2, sequence.getExplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(3, sequence.getImplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(true, untaggedChoice.getMyBoolean().value);
    Assert.assertEquals(4, sequence.getTaggedChoice().getMyInteger().value.intValue());
    System.out.println(DatatypeConverter.printHexBinary(sequence.getTaggedAny().value));
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("020101"), sequence.getTaggedAny().value);
    Assert.assertNull(sequence.getUntaggedChoice2());
}
Also used : SequenceOfDirectTypes(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) UntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes.UntaggedChoice) RetaggedUntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice) TaggedChoice(org.openmuc.jasn1.compiler.tagging_test.TaggedChoice) ImplicitlyRetaggedTaggedChoice(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) BerAny(org.openmuc.jasn1.ber.types.BerAny) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 14 with BerInteger

use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.

the class TaggingTest method retaggedChoiceTest.

@Test
public void retaggedChoiceTest() throws Exception {
    RetaggedUntaggedChoice choice = new RetaggedUntaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2103830101"), os.getArray());
    choice = new RetaggedUntaggedChoice();
    choice.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(choice.getMyInteger());
    Assert.assertNull(choice.getMyBoolean());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RetaggedUntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 15 with BerInteger

use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.

the class ModulesTest method encodingDecoding.

@Test
public void encodingDecoding() throws IOException {
    ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
    MyDate1 dateOfHire = new MyDate1();
    // MyDate1 dateOfHire = new MyDate1("19710917");
    dateOfHire.value = new String("19710917").getBytes();
    dateOfHire.encode(berOS, true);
    MyInt2 myInt2Encode = new MyInt2(2);
    berOS.reset();
    myInt2Encode.encode(berOS, true);
    MyInt2 myInt2Decode = new MyInt2();
    byte[] code = HexConverter.fromShortHexString("a303020102");
    InputStream is = new ByteArrayInputStream(code);
    myInt2Decode.decode(is, true);
    Assert.assertEquals(myInt2Decode.value.intValue(), 2);
    PersonnelRecord pr = new PersonnelRecord();
    Name name = new Name();
    name.setGivenName(new BerVisibleString("givenName".getBytes()));
    name.setFamilyName(new BerVisibleString("familyName".getBytes()));
    name.setInitial(new BerVisibleString("initial".getBytes()));
    pr.setName(name);
    pr.setTitle(new BerVisibleString("title".getBytes()));
    pr.setNumber(new EmployeeNumberZ(1));
    pr.setDateOfHire(new Date("23121981".getBytes()));
    pr.setNameOfSpouse(name);
    ChildInformation child = new ChildInformation();
    child.setName(new Name("child name".getBytes()));
    child.setDateOfBirth(new Date("12121912".getBytes()));
    PersonnelRecord.Children children = new PersonnelRecord.Children();
    List<ChildInformation> childInformation = children.getChildInformation();
    childInformation.add(child);
    childInformation.add(child);
    pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
    pr.setTest(new MyInt(3));
    TestChoice testChoice = new TestChoice();
    testChoice.setChoiceElement1(child);
    pr.setTest2(testChoice);
    pr.setTest3(testChoice);
    pr.setTest4(testChoice);
    pr.setTest5(testChoice);
    pr.setTest6(testChoice);
    TestSequenceOf testSequenceOf = new TestSequenceOf();
    List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
    for (int i = 0; i < 10; i++) {
        berIntegers.add(new BerInteger(i));
    }
    pr.setTestSequenceOf(testSequenceOf);
    TestSequenceOf2 testSequenceOf2 = new TestSequenceOf2();
    List<SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
    for (int i = 0; i < 10; i++) {
        SEQUENCE sequence = new SEQUENCE();
        sequence.setTest1(new BerInteger(i++));
        sequence.setTest2(new BerInteger(i));
        sequences.add(sequence);
    }
    pr.setTestSequenceOf2(testSequenceOf2);
    BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
    pr.setEmbeddedPdv(berEmbeddedPdv);
    System.out.println("PersonnelRecord.toString():\n" + pr);
}
Also used : BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) PersonnelRecord(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord) EmployeeNumberZ(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Name(org.openmuc.jasn1.compiler.modules.module1.Name) BerEmbeddedPdv(org.openmuc.jasn1.ber.types.BerEmbeddedPdv) SEQUENCE(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE) BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) ChildInformation(org.openmuc.jasn1.compiler.modules.module1.ChildInformation) TestSequenceOf(org.openmuc.jasn1.compiler.modules.module1.TestSequenceOf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestChoice(org.openmuc.jasn1.compiler.modules.module1.TestChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) TestSequenceOf2(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2) Date(org.openmuc.jasn1.compiler.modules.module1.Date) MyDate1(org.openmuc.jasn1.compiler.modules.module1.MyDate1) ByteArrayInputStream(java.io.ByteArrayInputStream) MyInt(org.openmuc.jasn1.compiler.modules.module1.MyInt) MyInt2(org.openmuc.jasn1.compiler.modules.module1.MyInt2) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 TaggedChoice (org.openmuc.jasn1.compiler.tagging_test.TaggedChoice)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 BerLength (org.openmuc.jasn1.ber.BerLength)1 BerEmbeddedPdv (org.openmuc.jasn1.ber.types.BerEmbeddedPdv)1 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)1 AbstractSyntaxName (org.openmuc.jasn1.compiler.iso8823_presentation.AbstractSyntaxName)1 CPType (org.openmuc.jasn1.compiler.iso8823_presentation.CPType)1 CalledPresentationSelector (org.openmuc.jasn1.compiler.iso8823_presentation.CalledPresentationSelector)1 CallingPresentationSelector (org.openmuc.jasn1.compiler.iso8823_presentation.CallingPresentationSelector)1