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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations