diff options
Diffstat (limited to 'tests/streams')
-rw-r--r-- | tests/streams/delimited_messages.in | 2 | ||||
-rw-r--r-- | tests/streams/dump_varint_negative.expected | 1 | ||||
-rw-r--r-- | tests/streams/dump_varint_positive.expected | 1 | ||||
-rw-r--r-- | tests/streams/java/.gitignore | 38 | ||||
-rw-r--r-- | tests/streams/java/pom.xml | 94 | ||||
-rw-r--r-- | tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java | 41 | ||||
-rw-r--r-- | tests/streams/java/src/main/java/aristaproto/Tests.java | 115 | ||||
-rw-r--r-- | tests/streams/java/src/main/proto/aristaproto/nested.proto | 27 | ||||
-rw-r--r-- | tests/streams/java/src/main/proto/aristaproto/oneof.proto | 19 | ||||
-rw-r--r-- | tests/streams/load_varint_cutoff.in | 1 | ||||
-rw-r--r-- | tests/streams/message_dump_file_multiple.expected | 2 | ||||
-rw-r--r-- | tests/streams/message_dump_file_single.expected | 1 |
12 files changed, 342 insertions, 0 deletions
diff --git a/tests/streams/delimited_messages.in b/tests/streams/delimited_messages.in new file mode 100644 index 0000000..5993ac6 --- /dev/null +++ b/tests/streams/delimited_messages.in @@ -0,0 +1,2 @@ +:bTesting:bTesting +
\ No newline at end of file diff --git a/tests/streams/dump_varint_negative.expected b/tests/streams/dump_varint_negative.expected new file mode 100644 index 0000000..0954822 --- /dev/null +++ b/tests/streams/dump_varint_negative.expected @@ -0,0 +1 @@ +ӝ
\ No newline at end of file diff --git a/tests/streams/dump_varint_positive.expected b/tests/streams/dump_varint_positive.expected new file mode 100644 index 0000000..8614b9d --- /dev/null +++ b/tests/streams/dump_varint_positive.expected @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/tests/streams/java/.gitignore b/tests/streams/java/.gitignore new file mode 100644 index 0000000..9b1ebba --- /dev/null +++ b/tests/streams/java/.gitignore @@ -0,0 +1,38 @@ +### Output ### +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +dependency-reduced-pom.xml +MANIFEST.MF + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store
\ No newline at end of file diff --git a/tests/streams/java/pom.xml b/tests/streams/java/pom.xml new file mode 100644 index 0000000..e39c567 --- /dev/null +++ b/tests/streams/java/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>aristaproto</groupId> + <artifactId>compatibility-test</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <protobuf.version>3.23.4</protobuf.version> + </properties> + + <dependencies> + <dependency> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> + <version>${protobuf.version}</version> + </dependency> + </dependencies> + + <build> + <extensions> + <extension> + <groupId>kr.motd.maven</groupId> + <artifactId>os-maven-plugin</artifactId> + <version>1.7.1</version> + </extension> + </extensions> + + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.5.0</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <mainClass>aristaproto.CompatibilityTest</mainClass> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.3.0</version> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <mainClass>aristaproto.CompatibilityTest</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.xolstice.maven.plugins</groupId> + <artifactId>protobuf-maven-plugin</artifactId> + <version>0.6.1</version> + <executions> + <execution> + <goals> + <goal>compile</goal> + </goals> + </execution> + </executions> + <configuration> + <protocArtifact> + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + </protocArtifact> + </configuration> + </plugin> + </plugins> + + <finalName>${project.artifactId}</finalName> + </build> + +</project>
\ No newline at end of file diff --git a/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java b/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java new file mode 100644 index 0000000..b0cff9f --- /dev/null +++ b/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java @@ -0,0 +1,41 @@ +package aristaproto; + +import java.io.IOException; + +public class CompatibilityTest { + public static void main(String[] args) throws IOException { + if (args.length < 2) + throw new RuntimeException("Attempted to run without the required arguments."); + else if (args.length > 2) + throw new RuntimeException( + "Attempted to run with more than the expected number of arguments (>1)."); + + Tests tests = new Tests(args[1]); + + switch (args[0]) { + case "single_varint": + tests.testSingleVarint(); + break; + + case "multiple_varints": + tests.testMultipleVarints(); + break; + + case "single_message": + tests.testSingleMessage(); + break; + + case "multiple_messages": + tests.testMultipleMessages(); + break; + + case "infinite_messages": + tests.testInfiniteMessages(); + break; + + default: + throw new RuntimeException( + "Attempted to run with unknown argument '" + args[0] + "'."); + } + } +} diff --git a/tests/streams/java/src/main/java/aristaproto/Tests.java b/tests/streams/java/src/main/java/aristaproto/Tests.java new file mode 100644 index 0000000..aabbac7 --- /dev/null +++ b/tests/streams/java/src/main/java/aristaproto/Tests.java @@ -0,0 +1,115 @@ +package aristaproto; + +import aristaproto.nested.NestedOuterClass; +import aristaproto.oneof.Oneof; + +import com.google.protobuf.CodedInputStream; +import com.google.protobuf.CodedOutputStream; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Tests { + String path; + + public Tests(String path) { + this.path = path; + } + + public void testSingleVarint() throws IOException { + // Read in the Python-generated single varint file + FileInputStream inputStream = new FileInputStream(path + "/py_single_varint.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + int value = codedInput.readUInt32(); + + inputStream.close(); + + // Write the value back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_single_varint.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + codedOutput.writeUInt32NoTag(value); + + codedOutput.flush(); + outputStream.close(); + } + + public void testMultipleVarints() throws IOException { + // Read in the Python-generated multiple varints file + FileInputStream inputStream = new FileInputStream(path + "/py_multiple_varints.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + int value1 = codedInput.readUInt32(); + int value2 = codedInput.readUInt32(); + long value3 = codedInput.readUInt64(); + + inputStream.close(); + + // Write the values back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_multiple_varints.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + codedOutput.writeUInt32NoTag(value1); + codedOutput.writeUInt64NoTag(value2); + codedOutput.writeUInt64NoTag(value3); + + codedOutput.flush(); + outputStream.close(); + } + + public void testSingleMessage() throws IOException { + // Read in the Python-generated single message file + FileInputStream inputStream = new FileInputStream(path + "/py_single_message.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + Oneof.Test message = Oneof.Test.parseFrom(codedInput); + + inputStream.close(); + + // Write the message back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_single_message.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + message.writeTo(codedOutput); + + codedOutput.flush(); + outputStream.close(); + } + + public void testMultipleMessages() throws IOException { + // Read in the Python-generated multi-message file + FileInputStream inputStream = new FileInputStream(path + "/py_multiple_messages.out"); + + Oneof.Test oneof = Oneof.Test.parseDelimitedFrom(inputStream); + NestedOuterClass.Test nested = NestedOuterClass.Test.parseDelimitedFrom(inputStream); + + inputStream.close(); + + // Write the messages back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_multiple_messages.out"); + + oneof.writeDelimitedTo(outputStream); + nested.writeDelimitedTo(outputStream); + + outputStream.flush(); + outputStream.close(); + } + + public void testInfiniteMessages() throws IOException { + // Read in as many messages as are present in the Python-generated file and write them back + FileInputStream inputStream = new FileInputStream(path + "/py_infinite_messages.out"); + FileOutputStream outputStream = new FileOutputStream(path + "/java_infinite_messages.out"); + + Oneof.Test current = Oneof.Test.parseDelimitedFrom(inputStream); + while (current != null) { + current.writeDelimitedTo(outputStream); + current = Oneof.Test.parseDelimitedFrom(inputStream); + } + + inputStream.close(); + outputStream.flush(); + outputStream.close(); + } +} diff --git a/tests/streams/java/src/main/proto/aristaproto/nested.proto b/tests/streams/java/src/main/proto/aristaproto/nested.proto new file mode 100644 index 0000000..46a5783 --- /dev/null +++ b/tests/streams/java/src/main/proto/aristaproto/nested.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package nested; +option java_package = "aristaproto.nested"; + +// A test message with a nested message inside of it. +message Test { + // This is the nested type. + message Nested { + // Stores a simple counter. + int32 count = 1; + } + // This is the nested enum. + enum Msg { + NONE = 0; + THIS = 1; + } + + Nested nested = 1; + Sibling sibling = 2; + Sibling sibling2 = 3; + Msg msg = 4; +} + +message Sibling { + int32 foo = 1; +}
\ No newline at end of file diff --git a/tests/streams/java/src/main/proto/aristaproto/oneof.proto b/tests/streams/java/src/main/proto/aristaproto/oneof.proto new file mode 100644 index 0000000..44a8949 --- /dev/null +++ b/tests/streams/java/src/main/proto/aristaproto/oneof.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package oneof; +option java_package = "aristaproto.oneof"; + +message Test { + oneof foo { + int32 pitied = 1; + string pitier = 2; + } + + int32 just_a_regular_field = 3; + + oneof bar { + int32 drinks = 11; + string bar_name = 12; + } +} + diff --git a/tests/streams/load_varint_cutoff.in b/tests/streams/load_varint_cutoff.in new file mode 100644 index 0000000..52b9bf1 --- /dev/null +++ b/tests/streams/load_varint_cutoff.in @@ -0,0 +1 @@ +ȁ
\ No newline at end of file diff --git a/tests/streams/message_dump_file_multiple.expected b/tests/streams/message_dump_file_multiple.expected new file mode 100644 index 0000000..b5fdf9c --- /dev/null +++ b/tests/streams/message_dump_file_multiple.expected @@ -0,0 +1,2 @@ +:bTesting:bTesting +
\ No newline at end of file diff --git a/tests/streams/message_dump_file_single.expected b/tests/streams/message_dump_file_single.expected new file mode 100644 index 0000000..9b7bafb --- /dev/null +++ b/tests/streams/message_dump_file_single.expected @@ -0,0 +1 @@ +:bTesting
\ No newline at end of file |