31 package com.google.protobuf;
33 import static org.junit.Assert.assertEquals;
37 import java.io.IOException;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.junit.runners.JUnit4;
43 @RunWith(JUnit4.class)
49 Protobuf.getInstance()
56 byte[] expectedBytes = expected.toByteArray();
59 Proto3Message result = fromByteArray(expectedBytes, Proto3Message.class);
60 assertEquals(expected, result);
63 byte[] actualBytes = toByteArray(result, expectedBytes.length);
66 Proto3Message actual = Proto3Message.parseFrom(actualBytes);
67 assertEquals(expected, actual);
73 byte[] expectedBytes = expected.toByteArray();
76 Proto2Message result = fromByteArray(expectedBytes, Proto2Message.class);
77 assertEquals(expected, result);
80 byte[] actualBytes = toByteArray(result, expectedBytes.length);
83 Proto2Message actual = Proto2Message.parseFrom(actualBytes);
84 assertEquals(expected, actual);
88 Schema<T> schema = Protobuf.getInstance().schemaFor(msg);
89 byte[] out =
new byte[
size];
90 CodedOutputStreamWriter writer =
92 schema.writeTo(msg, writer);
93 assertEquals(out.length, writer.getTotalBytesWritten());
98 Schema<T> schema = Protobuf.getInstance().schemaFor(messageType);
100 T msg = schema.newInstance();
106 }
catch (IOException e) {
107 throw new RuntimeException(e);