diff options
Diffstat (limited to 'conformance')
-rw-r--r-- | conformance/ConformanceJava.java | 2 | ||||
-rw-r--r-- | conformance/ConformanceJavaLite.java | 125 | ||||
-rw-r--r-- | conformance/Makefile.am | 20 |
3 files changed, 145 insertions, 2 deletions
diff --git a/conformance/ConformanceJava.java b/conformance/ConformanceJava.java index a983ba3c..43787ffc 100644 --- a/conformance/ConformanceJava.java +++ b/conformance/ConformanceJava.java @@ -129,7 +129,7 @@ class ConformanceJava { typeRegistry = TypeRegistry.newBuilder().add( Conformance.TestAllTypes.getDescriptor()).build(); while (doTestIo()) { - // Empty. + this.testCount++; } System.err.println("ConformanceJava: received EOF from test runner after " + diff --git a/conformance/ConformanceJavaLite.java b/conformance/ConformanceJavaLite.java new file mode 100644 index 00000000..121dc7d1 --- /dev/null +++ b/conformance/ConformanceJavaLite.java @@ -0,0 +1,125 @@ + +import com.google.protobuf.conformance.Conformance; +import com.google.protobuf.InvalidProtocolBufferException; + +class ConformanceJavaLite { + private int testCount = 0; + + private boolean readFromStdin(byte[] buf, int len) throws Exception { + int ofs = 0; + while (len > 0) { + int read = System.in.read(buf, ofs, len); + if (read == -1) { + return false; // EOF + } + ofs += read; + len -= read; + } + + return true; + } + + private void writeToStdout(byte[] buf) throws Exception { + System.out.write(buf); + } + + // Returns -1 on EOF (the actual values will always be positive). + private int readLittleEndianIntFromStdin() throws Exception { + byte[] buf = new byte[4]; + if (!readFromStdin(buf, 4)) { + return -1; + } + return (buf[0] & 0xff) + | ((buf[1] & 0xff) << 8) + | ((buf[2] & 0xff) << 16) + | ((buf[3] & 0xff) << 24); + } + + private void writeLittleEndianIntToStdout(int val) throws Exception { + byte[] buf = new byte[4]; + buf[0] = (byte)val; + buf[1] = (byte)(val >> 8); + buf[2] = (byte)(val >> 16); + buf[3] = (byte)(val >> 24); + writeToStdout(buf); + } + + private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) { + Conformance.TestAllTypes testMessage; + + switch (request.getPayloadCase()) { + case PROTOBUF_PAYLOAD: { + try { + testMessage = Conformance.TestAllTypes.parseFrom(request.getProtobufPayload()); + } catch (InvalidProtocolBufferException e) { + return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build(); + } + break; + } + case JSON_PAYLOAD: { + return Conformance.ConformanceResponse.newBuilder().setSkipped( + "Lite runtime does not suport Json Formant.").build(); + } + case PAYLOAD_NOT_SET: { + throw new RuntimeException("Request didn't have payload."); + } + + default: { + throw new RuntimeException("Unexpected payload case."); + } + } + + switch (request.getRequestedOutputFormat()) { + case UNSPECIFIED: + throw new RuntimeException("Unspecified output format."); + + case PROTOBUF: + return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(testMessage.toByteString()).build(); + + case JSON: + return Conformance.ConformanceResponse.newBuilder().setSkipped( + "Lite runtime does not suport Json Formant.").build(); + + default: { + throw new RuntimeException("Unexpected request output."); + } + } + } + + private boolean doTestIo() throws Exception { + int bytes = readLittleEndianIntFromStdin(); + + if (bytes == -1) { + return false; // EOF + } + + byte[] serializedInput = new byte[bytes]; + + if (!readFromStdin(serializedInput, bytes)) { + throw new RuntimeException("Unexpected EOF from test program."); + } + + Conformance.ConformanceRequest request = + Conformance.ConformanceRequest.parseFrom(serializedInput); + Conformance.ConformanceResponse response = doTest(request); + byte[] serializedOutput = response.toByteArray(); + + writeLittleEndianIntToStdout(serializedOutput.length); + writeToStdout(serializedOutput); + + return true; + } + + public void run() throws Exception { + while (doTestIo()) { + this.testCount++; + } + + System.err.println("ConformanceJavaLite: received EOF from test runner after " + + this.testCount + " tests"); + } + + public static void main(String[] args) throws Exception { + new ConformanceJavaLite().run(); + } +} diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 2a43113b..abb1c00d 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -19,6 +19,7 @@ protoc_outputs = \ other_language_protoc_outputs = \ conformance.rb \ com/google/protobuf/conformance/Conformance.java \ + lite/com/google/protobuf/conformance/Conformance.java \ conformance_pb2.py \ Conformance.pbobjc.h \ Conformance.pbobjc.m @@ -30,6 +31,7 @@ bin_PROGRAMS = conformance-test-runner conformance-cpp # automatically. EXTRA_DIST = \ ConformanceJava.java \ + ConformanceJavaLite.java \ README.md \ conformance.proto \ conformance_python.py \ @@ -88,6 +90,7 @@ if USE_EXTERNAL_PROTOC protoc_middleman: $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. $(conformance_protoc_inputs) $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. $(well_known_type_protoc_inputs) + $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) touch protoc_middleman else @@ -98,6 +101,8 @@ else protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd $(conformance_protoc_inputs) ) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd $(well_known_type_protoc_inputs) ) + @mkdir -p lite + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) ) touch protoc_middleman endif @@ -108,7 +113,7 @@ $(other_language_protoc_outputs): protoc_middleman BUILT_SOURCES = $(protoc_outputs) $(other_language_protoc_outputs) -CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java conformance-csharp $(other_language_protoc_outputs) +CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java javac_middleman_lite conformance-java-lite conformance-csharp $(other_language_protoc_outputs) MAINTAINERCLEANFILES = \ Makefile.in @@ -123,6 +128,16 @@ conformance-java: javac_middleman @jar=`ls ../java/util/target/*jar-with-dependencies.jar` && echo java -classpath .:../java/target/classes:$$jar ConformanceJava '$$@' >> conformance-java @chmod +x conformance-java +javac_middleman_lite: ConformanceJavaLite.java protoc_middleman $(other_language_protoc_outputs) + javac -classpath ../java/lite/target/classes:lite ConformanceJavaLite.java lite/com/google/protobuf/conformance/Conformance.java + @touch javac_middleman_lite + +conformance-java-lite: javac_middleman_lite + @echo "Writing shortcut script conformance-java-lite..." + @echo '#! /bin/sh' > conformance-java-lite + @echo java -classpath .:../java/lite/target/classes:lite ConformanceJavaLite '$$@' >> conformance-java-lite + @chmod +x conformance-java-lite + # Currently the conformance code is alongside the rest of the C# # source, as it's easier to maintain there. We assume we've already # built that, so we just need a script to run it. @@ -139,6 +154,9 @@ test_cpp: protoc_middleman conformance-test-runner conformance-cpp test_java: protoc_middleman conformance-test-runner conformance-java ./conformance-test-runner --failure_list failure_list_java.txt ./conformance-java +test_java_lite: protoc_middleman conformance-test-runner conformance-java-lite + ./conformance-test-runner ./conformance-java-lite + test_csharp: protoc_middleman conformance-test-runner conformance-csharp ./conformance-test-runner --failure_list failure_list_csharp.txt ./conformance-csharp |