@Test public void testEncodeDecodeSequence() throws Exception { final ASN1Writer writer = getWriter(); writer.writeStartSequence(); writer.writeBoolean(true); writer.writeBoolean(false); writer.writeInteger(0); writer.writeInteger(10L); writer.writeNull(); writer.writeOctetString("test value"); writer.writeOctetString("skip value"); writer.writeStartSequence(); writer.writeOctetString("nested sequence"); writer.writeEndSequence(); writer.writeStartSet(); writer.writeOctetString("nested set"); writer.writeEndSet(); writer.writeEndSequence(); final ASN1Reader reader = getReader(getEncodedBytes()); assertEquals(reader.peekType(), ASN1.UNIVERSAL_SEQUENCE_TYPE); assertEquals(reader.peekLength(), 71); assertTrue(reader.hasNextElement()); reader.readStartSequence(); assertTrue(reader.hasNextElement()); assertEquals(true, reader.readBoolean()); assertEquals(false, reader.readBoolean()); assertEquals(0, reader.readInteger()); assertEquals(10, reader.readInteger()); reader.readNull(); assertEquals("test value", reader.readOctetStringAsString()); reader.skipElement(); assertEquals(reader.peekLength(), 17); assertEquals(reader.peekType(), ASN1.UNIVERSAL_SEQUENCE_TYPE); reader.readStartSequence(); assertEquals("nested sequence", reader.readOctetStringAsString()); reader.readEndSequence(); assertEquals(reader.peekLength(), 12); assertEquals(reader.peekType(), ASN1.UNIVERSAL_SET_TYPE); reader.readStartSequence(); assertEquals("nested set", reader.readOctetStringAsString()); reader.readEndSequence(); assertFalse(reader.hasNextElement()); reader.readEndSequence(); assertFalse(reader.elementAvailable()); }
/** * Tests the <CODE>write/readInteger</CODE> methods with Java longs. * * @param l The long value to use for the test. */ @Test(dataProvider = "longValues") public void testEncodeDecodeInteger(final long l, final int length) throws Exception { getWriter().writeInteger(l); final ASN1Reader r = getReader(getEncodedBytes()); assertEquals(r.peekLength(), length); assertEquals(r.peekType(), ASN1.UNIVERSAL_INTEGER_TYPE); assertEquals(r.readInteger(), l); }
/** * Tests the <CODE>write/readInteger</CODE> methods with Java ints. * * @param i The integer value to use for the test. */ @Test(dataProvider = "intValues") public void testEncodeDecodeEnuerated(final int i, final int length) throws Exception { getWriter().writeEnumerated(i); final ASN1Reader r = getReader(getEncodedBytes()); assertEquals(r.peekLength(), length); assertEquals(r.peekType(), ASN1.UNIVERSAL_ENUMERATED_TYPE); assertEquals(r.readInteger(), i); }
/** * Tests the <CODE>write/readInteger</CODE> methods wiht JavaLongs. * * @param l The long value to use for the test. */ @Test(dataProvider = "longValues") public void testEncodeDecodeIntegerType(final long l, final int length) throws Exception { for (final byte type : testTypes) { getWriter().writeInteger(type, l); final ASN1Reader r = getReader(getEncodedBytes()); assertEquals(r.peekLength(), length); assertEquals(r.peekType(), type); assertEquals(r.readInteger(), l); } }