5 class ConformanceJavaLite {
6 private int testCount = 0;
8 private boolean readFromStdin(
byte[]
buf,
int len)
throws Exception {
22 private void writeToStdout(
byte[]
buf)
throws Exception {
23 System.out.write(
buf);
27 private int readLittleEndianIntFromStdin() throws Exception {
28 byte[]
buf =
new byte[4];
29 if (!readFromStdin(
buf, 4)) {
32 return (
buf[0] & 0xff)
33 | ((
buf[1] & 0xff) << 8)
34 | ((
buf[2] & 0xff) << 16)
35 | ((
buf[3] & 0xff) << 24);
38 private void writeLittleEndianIntToStdout(
int val)
throws Exception {
39 byte[]
buf =
new byte[4];
47 private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest
request) {
48 Conformance.TestAllTypes testMessage;
50 switch (
request.getPayloadCase()) {
51 case PROTOBUF_PAYLOAD: {
53 testMessage = Conformance.TestAllTypes.parseFrom(
request.getProtobufPayload());
55 return Conformance.ConformanceResponse.newBuilder().setParseError(
e.getMessage()).build();
60 return Conformance.ConformanceResponse.newBuilder().setSkipped(
61 "Lite runtime does not support JSON format.").build();
63 case PAYLOAD_NOT_SET: {
64 throw new RuntimeException(
"Request didn't have payload.");
68 throw new RuntimeException(
"Unexpected payload case.");
72 switch (
request.getRequestedOutputFormat()) {
74 throw new RuntimeException(
"Unspecified output format.");
77 return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(testMessage.toByteString()).build();
80 return Conformance.ConformanceResponse.newBuilder().setSkipped(
81 "Lite runtime does not support JSON format.").build();
84 throw new RuntimeException(
"Unexpected request output.");
89 private boolean doTestIo() throws Exception {
90 int bytes = readLittleEndianIntFromStdin();
96 byte[] serializedInput =
new byte[
bytes];
98 if (!readFromStdin(serializedInput,
bytes)) {
99 throw new RuntimeException(
"Unexpected EOF from test program.");
102 Conformance.ConformanceRequest
request =
103 Conformance.ConformanceRequest.parseFrom(serializedInput);
105 byte[] serializedOutput =
response.toByteArray();
107 writeLittleEndianIntToStdout(serializedOutput.length);
108 writeToStdout(serializedOutput);
113 public void run() throws Exception {
118 System.err.println(
"ConformanceJavaLite: received EOF from test runner after " +
119 this.testCount +
" tests");
122 public static void main(String[]
args)
throws Exception {
123 new ConformanceJavaLite().run();