use of org.openmuc.jasn1.ber.types.BerAny in project jasn1 by openmuc.
the class PresentationLayerTest method encodingDecoding.
@Test
public void encodingDecoding() throws IOException {
ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
List<TransferSyntaxName> berObjectIdentifierList = new ArrayList<>(1);
berObjectIdentifierList.add(new TransferSyntaxName(new int[] { 2, 1, 1 }));
ContextList.SEQUENCE.TransferSyntaxNameList tsnl = new ContextList.SEQUENCE.TransferSyntaxNameList(berObjectIdentifierList);
ContextList.SEQUENCE context_listSubSeq = new ContextList.SEQUENCE(new PresentationContextIdentifier(1), new AbstractSyntaxName(new int[] { 2, 2, 1, 0, 1 }), tsnl);
ContextList.SEQUENCE context_listSubSeq2 = new ContextList.SEQUENCE(new PresentationContextIdentifier(3), new AbstractSyntaxName(new int[] { 1, 0, 9506, 2, 1 }), tsnl);
List<ContextList.SEQUENCE> context_listSubSeqList = new ArrayList<>(2);
context_listSubSeqList.add(context_listSubSeq);
context_listSubSeqList.add(context_listSubSeq2);
PresentationContextDefinitionList context_list = new PresentationContextDefinitionList(context_listSubSeqList);
PDVList.PresentationDataValues presDataValues = new PDVList.PresentationDataValues(new BerAny(new byte[] { 2, 1, 1 }), null, null);
PDVList pdvList = new PDVList(null, new PresentationContextIdentifier(1), presDataValues);
List<PDVList> pdvListList = new ArrayList<>(1);
pdvListList.add(pdvList);
FullyEncodedData fullyEncodedData = new FullyEncodedData(pdvListList);
UserData userData = new UserData(null, fullyEncodedData);
CPType.NormalModeParameters normalModeParameter = new CPType.NormalModeParameters(null, new CallingPresentationSelector(new byte[] { 0, 0, 0, 1 }), new CalledPresentationSelector(new byte[] { 0, 0, 0, 1 }), context_list, null, null, null, userData);
ModeSelector modeSelector = new ModeSelector(new BerInteger(1));
CPType cpType = new CPType(modeSelector, normalModeParameter);
cpType.encode(berOS, true);
ByteArrayInputStream bais = new ByteArrayInputStream(berOS.getArray());
CPType cpType_decoded = new CPType();
cpType_decoded.decode(bais, true);
Assert.assertEquals("2.2.1.0.1", cpType_decoded.normalModeParameters.presentationContextDefinitionList.seqOf.get(0).abstractSyntaxName.toString());
}
use of org.openmuc.jasn1.ber.types.BerAny 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());
}
Aggregations