Skip to content

Commit

Permalink
Add test for multiple proto files with same name from a directory ref…
Browse files Browse the repository at this point in the history
…erenced by protobuf dependency.

For google#248
  • Loading branch information
zhangkun83 committed Jan 17, 2019
1 parent 49e7405 commit 6e21682
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 14 deletions.
6 changes: 3 additions & 3 deletions examples/exampleKotlinDslProject/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.provider.gradleKotlinDslOf
plugins {
java
idea
id("com.google.protobuf") version "0.8.8-SNAPSHOT"
id("com.google.protobuf") version "0.8.8"
}

repositories {
Expand All @@ -34,10 +34,10 @@ dependencies {
// Extra proto source files besides the ones residing under
// "src/main".
protobuf(files("lib/protos.tar.gz"))
protobuf(fileTree("ext/"))
protobuf(files("ext/"))

// Adding dependency for configuration from custom sourceSet
"sampleProtobuf"(fileTree("ext/"))
"sampleProtobuf"(files("ext/"))

testCompile("junit:junit:4.12")
// Extra proto source files for test besides the ones residing under
Expand Down
2 changes: 1 addition & 1 deletion examples/exampleProject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
// Extra proto source files besides the ones residing under
// "src/main".
protobuf files("lib/protos.tar.gz")
protobuf fileTree("ext/")
protobuf files("ext/")

testCompile 'junit:junit:4.12'
// Extra proto source files for test besides the ones residing under
Expand Down
6 changes: 4 additions & 2 deletions testProject/src/main/java/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public static List<MessageLite> getDefaultInstances() {
list.add(More.MoreMsg.getDefaultInstance());
list.add(More.Foo.getDefaultInstance());
// from ext/test1.proto
list.add(Test1.Test1Msg.getDefaultInstance());
list.add(test1.Test1.Test1Msg.getDefaultInstance());
// from ext/ext1/test1.proto
list.add(ext1.Ext1Test1.Ext1Test1Msg.getDefaultInstance());
// from ext/test2.proto
list.add(Test2.Test2Msg.getDefaultInstance());
list.add(test2.Test2.Test2Msg.getDefaultInstance());
return list;
}
}
2 changes: 1 addition & 1 deletion testProject/src/test/java/FooTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public class FooTest {
@org.junit.Test
public void testMainProtos() {
assertEquals(11, Foo.getDefaultInstances().size());
assertEquals(12, Foo.getDefaultInstances().size());
}

@org.junit.Test
Expand Down
2 changes: 1 addition & 1 deletion testProjectBase/build_base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def protobufDep = 'com.google.protobuf:protobuf-java:3.0.0'

dependencies {
protobuf files("lib/protos.tar.gz")
protobuf fileTree("ext/")
protobuf files("ext/")
testProtobuf files("lib/protos-test.tar.gz")

compile protobufDep
Expand Down
8 changes: 8 additions & 0 deletions testProjectBase/ext/ext1/test1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

option java_package = "ext1";
option java_outer_classname = "Ext1Test1";

message Ext1Test1Msg {
string bar = 1;
}
2 changes: 2 additions & 0 deletions testProjectBase/ext/test1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
syntax = "proto3";

option java_package = "test1";

message Test1Msg {
string bar = 1;
}
2 changes: 2 additions & 0 deletions testProjectBase/ext/test2.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
syntax = "proto3";

option java_package = "test2";

message Test2Msg {
string bar = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ option java_package = "com.example.tutorial";
option java_outer_classname = "OuterSample";
option java_multiple_files = true;

import "test1.proto";
import "ext1/test1.proto";
import "test2.proto";

message Msg {
string foo = 1;
SecondMsg blah = 2;
Test1Msg test1 = 3;
Test2Msg test2 = 4;
Ext1Test1Msg ext1test1 = 5;
}

message SecondMsg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class CallKotlinClass {
@org.junit.Test
public void testMainProtosKotlin() {
// call kotlin class from java
assertEquals(11, new KotlinFoo().getDefaultInstances().size());
assertEquals(12, new KotlinFoo().getDefaultInstances().size());
}
}
2 changes: 1 addition & 1 deletion testProjectJavaAndKotlin/src/test/kotlin/CallJavaClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.junit.Assert.assertTrue
class CallJavaClass {
@org.junit.Test
fun testCallJavaFoo() {
assertEquals(11, Foo.getDefaultInstances().size)
assertEquals(12, Foo.getDefaultInstances().size)
}
}
6 changes: 4 additions & 2 deletions testProjectKotlin/src/main/kotlin/KotlinFoo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class KotlinFoo {
list.add(More.MoreMsg.getDefaultInstance());
list.add(More.Foo.getDefaultInstance());
// from ext/test1.proto
list.add(Test1.Test1Msg.getDefaultInstance());
list.add(test1.Test1.Test1Msg.getDefaultInstance());
// from ext/ext1/test1.proto
list.add(ext1.Ext1Test1.Ext1Test1Msg.getDefaultInstance());
// from ext/test2.proto
list.add(Test2.Test2Msg.getDefaultInstance());
list.add(test2.Test2.Test2Msg.getDefaultInstance());
return list
}
}
2 changes: 1 addition & 1 deletion testProjectKotlin/src/test/kotlin/KotlinFooTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.junit.Assert.assertTrue
class KotlinFooTest {
@org.junit.Test
fun testMainProtos() {
assertEquals(11, KotlinFoo().getDefaultInstances().size)
assertEquals(12, KotlinFoo().getDefaultInstances().size)
}

@org.junit.Test
Expand Down
2 changes: 1 addition & 1 deletion testProjectKotlinDslBase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ val protobufDep = "com.google.protobuf:protobuf-java:3.0.0"

dependencies {
protobuf(files("lib/protos.tar.gz"))
protobuf(fileTree("ext/"))
protobuf(files("ext/"))
testProtobuf(files("lib/protos-test.tar.gz"))

compile(protobufDep)
Expand Down
1 change: 1 addition & 0 deletions testProjectLite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
compile 'com.google.protobuf:protobuf-lite:3.0.0'
protobuf files("ext/")
testCompile 'junit:junit:4.12'
}

Expand Down

0 comments on commit 6e21682

Please sign in to comment.