31 package com.google.protobuf;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertTrue;
36 import static org.junit.Assert.fail;
39 import java.io.ByteArrayInputStream;
40 import java.io.ByteArrayOutputStream;
41 import java.io.FilterInputStream;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.junit.runners.JUnit4;
57 @RunWith(JUnit4.class)
61 DescriptorProto
parse(InputStream in)
throws IOException;
67 serializedProto = DescriptorProto.getDescriptor().toProto().toByteArray();
71 ByteArrayOutputStream bos =
new ByteArrayOutputStream();
73 DescriptorProto.getDescriptor().toProto().writeDelimitedTo(bos);
74 }
catch (IOException e) {
75 fail(
"Exception not expected: " + e);
77 serializedProto = bos.toByteArray();
86 public DescriptorProto
parse(InputStream in)
throws IOException {
87 return DescriptorProto.parseFrom(in);
98 public DescriptorProto
parse(InputStream in)
throws IOException {
110 public DescriptorProto
parse(InputStream in)
throws IOException {
122 public DescriptorProto
parse(InputStream in)
throws IOException {
123 return DescriptorProto.parseFrom(
135 public DescriptorProto
parse(InputStream in)
throws IOException {
136 return DescriptorProto.parseDelimitedFrom(in);
147 public DescriptorProto
parse(InputStream in)
throws IOException {
159 public DescriptorProto
parse(InputStream in)
throws IOException {
160 return DescriptorProto.newBuilder().mergeFrom(in).build();
171 public DescriptorProto
parse(InputStream in)
throws IOException {
172 return DescriptorProto.newBuilder()
185 public DescriptorProto
parse(InputStream in)
throws IOException {
197 public DescriptorProto
parse(InputStream in)
throws IOException {
198 return DescriptorProto.newBuilder()
211 public DescriptorProto
parse(InputStream in)
throws IOException {
212 DescriptorProto.Builder builder = DescriptorProto.newBuilder();
213 builder.mergeDelimitedFrom(in);
214 return builder.build();
221 byte[] body =
new byte[80];
228 ByteArrayInputStream bais =
new ByteArrayInputStream(body);
230 DescriptorProto.parseDelimitedFrom(bais);
242 public DescriptorProto
parse(InputStream in)
throws IOException {
243 DescriptorProto.Builder builder = DescriptorProto.newBuilder();
245 return builder.build();
254 DescriptorProto.getDescriptor().toProto(),
255 parseTester.
parse(
new ByteArrayInputStream(serializedProto)));
256 }
catch (IOException e) {
257 fail(
"No exception expected: " + e);
263 parseTester.
parse(broken(
new ByteArrayInputStream(serializedProto)));
264 fail(
"IOException expected but not thrown");
265 }
catch (IOException e) {
272 for (
int i = 0;
i < 50;
i++) {
273 serializedProto[
i] = -1;
275 parseTester.
parse(
new ByteArrayInputStream(serializedProto));
276 fail(
"InvalidProtocolBufferException expected but not thrown");
277 }
catch (IOException e) {
283 return new FilterInputStream(
i) {
287 public int read()
throws IOException {
289 throw new IOException(
"I'm broken!");
295 public int read(
byte[]
b,
int off,
int len)
throws IOException {
297 throw new IOException(
"I'm broken!");
299 return super.read(
b, off,
len);