@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/readBoolean</CODE> methods. * * @param b The boolean value to use in the test. */ @Test(dataProvider = "booleanValues") public void testEncodeDecodeBoolean(final boolean b) throws Exception { getWriter().writeBoolean(b); final ASN1Reader r = getReader(getEncodedBytes()); assertEquals(r.peekLength(), 1); assertEquals(r.peekType(), ASN1.UNIVERSAL_BOOLEAN_TYPE); assertEquals(r.readBoolean(), b); }
/** * Tests the <CODE>write/readBoolean</CODE> methods. * * @param b The boolean value to use in the test. */ @Test(dataProvider = "booleanValues") public void testEncodeDecodeBooleanType(final boolean b) throws Exception { for (final byte type : testTypes) { getWriter().writeBoolean(type, b); final ASN1Reader r = getReader(getEncodedBytes()); assertEquals(r.peekLength(), 1); assertEquals(r.peekType(), type); assertEquals(r.readBoolean(), b); } }