From eef241890a6a64bfe74471d7af2907e265423c0b Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 18 Mar 2021 23:52:11 +0000 Subject: [PATCH] Adding most recent work --- java/core/generate-test-sources-build.xml | 6 +- java/core/output.txt | 208 +++-------- java/core/pom.xml | 18 +- .../ExtendableMessageExtensionsLite.kt | 28 ++ .../kotlin/com/google/protobuf/DslListTest.kt | 98 +++++ .../kotlin/com/google/protobuf/DslMapTest.kt | 164 +++++++++ .../ExtendableMessageExtensionsTest.kt | 60 ++++ .../com/google/protobuf/ExtensionListTest.kt | 125 +++++++ .../kotlin/com/google/protobuf/Proto2Test.kt | 59 ++- .../kotlin/com/google/protobuf/Proto3Test.kt | 340 ++++++++++++++++++ .../google/protobuf/evil_names_proto3.proto | 5 +- ...proto => example_extensible_message.proto} | 4 +- ...oto3.proto => multiple_files_proto3.proto} | 4 +- java/lite/generate-test-sources-build.xml | 14 +- java/lite/pom.xml | 50 +++ .../ExtendableMessageLiteExtensionsTest.kt | 4 +- .../com/google/protobuf/Proto2LiteTest.kt | 85 ++--- 17 files changed, 1032 insertions(+), 240 deletions(-) create mode 100644 java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensionsLite.kt create mode 100644 java/core/src/test/kotlin/com/google/protobuf/DslListTest.kt create mode 100644 java/core/src/test/kotlin/com/google/protobuf/DslMapTest.kt create mode 100644 java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt create mode 100644 java/core/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt create mode 100644 java/core/src/test/kotlin/com/google/protobuf/Proto3Test.kt rename java/core/src/test/proto/com/google/protobuf/{test.proto => example_extensible_message.proto} (75%) rename java/core/src/test/proto/com/google/protobuf/{mutliple_files_proto3.proto => multiple_files_proto3.proto} (61%) diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index a2ae5a2917..e3a4a724a5 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -26,6 +26,7 @@ + @@ -35,6 +36,7 @@ + @@ -48,7 +50,6 @@ - @@ -70,7 +71,10 @@ + + + diff --git a/java/core/output.txt b/java/core/output.txt index 1cbf7a3569..93cb211ecf 100644 --- a/java/core/output.txt +++ b/java/core/output.txt @@ -52,6 +52,10 @@ main: [INFO] /usr/local/google/home/deannagarcia/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java: Some input files use unchecked or unsafe operations. [INFO] /usr/local/google/home/deannagarcia/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java: Recompile with -Xlint:unchecked for details. [INFO] +[INFO] --- kotlin-maven-plugin:1.4.31:compile (compile) @ protobuf-java --- +[WARNING] /usr/local/google/home/deannagarcia/protobuf/java/core/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt: (8, 2) This class can only be used with the compiler argument '-Xopt-in=kotlin.RequiresOptIn' +[WARNING] /usr/local/google/home/deannagarcia/protobuf/java/core/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt: (14, 11) This class can only be used with the compiler argument '-Xopt-in=kotlin.RequiresOptIn' +[INFO] [INFO] --- maven-antrun-plugin:1.8:run (generate-test-sources) @ protobuf-java --- [INFO] Executing tasks @@ -99,168 +103,66 @@ main: [INFO] [INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ protobuf-java --- [INFO] Changes detected - recompiling the module! -[INFO] Compiling 176 source files to /usr/local/google/home/deannagarcia/protobuf/java/core/target/test-classes +[INFO] Compiling 182 source files to /usr/local/google/home/deannagarcia/protobuf/java/core/target/test-classes [INFO] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java: Some input files use or override a deprecated API. [INFO] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java: Recompile with -Xlint:deprecation for details. [INFO] [INFO] --- kotlin-maven-plugin:1.4.31:test-compile (test-compile) @ protobuf-java --- -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (452, 52) Assignment operators ambiguity: -public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (453, 52) Assignment operators ambiguity: -public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (454, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (455, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (456, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (457, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (458, 54) Assignment operators ambiguity: -public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (459, 54) Assignment operators ambiguity: -public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (460, 55) Assignment operators ambiguity: -public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (461, 55) Assignment operators ambiguity: -public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (462, 52) Assignment operators ambiguity: -public operator fun Collection.plus(element: Float!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Float!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (463, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: Double!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Double!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (464, 51) Assignment operators ambiguity: -public operator fun Collection.plus(element: Boolean!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: Boolean!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (465, 53) Assignment operators ambiguity: -public operator fun Collection.plus(element: String!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (466, 52) Assignment operators ambiguity: -public operator fun Collection.plus(elements: Iterable): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: ByteString!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (467, 52) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.RepeatedGroup_extension!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.RepeatedGroup_extension!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (468, 60) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedMessage!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (470, 61) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.ForeignMessage!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.ForeignMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (471, 60) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestImport.ImportMessage!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestImport.ImportMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (473, 58) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedMessage!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (475, 57) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedEnum!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (476, 58) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestProto.ForeignEnum!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.ForeignEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (477, 57) Assignment operators ambiguity: -public operator fun Collection.plus(element: UnittestImport.ImportEnum!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: UnittestImport.ImportEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (478, 58) Assignment operators ambiguity: -public operator fun Collection.plus(element: String!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt: (479, 51) Assignment operators ambiguity: -public operator fun Collection.plus(element: String!): List defined in kotlin.collections -public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (15, 5) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , B : com.google.protobuf.GeneratedMessage.ExtendableBuilder, T> TypeVariable(B).set(extension: ExtensionLite, value: TypeVariable(T)): Unit defined in com.google.protobuf.kotlin +public operator fun , B : com.google.protobuf.GeneratedMessageLite.ExtendableBuilder, T> TypeVariable(B).set(extension: ExtensionLite, value: TypeVariable(T)): Unit defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (15, 12) No set method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (23, 16) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MOrBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder, T> TypeVariable(MOrBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder, T> TypeVariable(MorBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (23, 23) No get method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (31, 16) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MOrBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder, T> TypeVariable(MOrBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder, T> TypeVariable(MorBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (31, 23) No get method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (39, 41) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (46, 41) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (52, 41) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt: (58, 41) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ -[INFO] Total time: 01:20 min -[INFO] Finished at: 2021-03-11T22:25:24Z +[INFO] Total time: 01:24 min +[INFO] Finished at: 2021-03-18T23:34:30Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.4.31:test-compile (test-compile) on project protobuf-java: Compilation failure: Compilation failure: -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[452,52] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[453,52] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[454,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[455,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[456,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[457,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[458,54] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[459,54] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[460,55] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Int!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Int!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[461,55] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Long!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Long!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[462,52] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Float!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Float!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[463,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Double!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Double!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[464,51] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: Boolean!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: Boolean!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[465,53] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: String!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[466,52] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(elements: Iterable): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: ByteString!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[467,52] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.RepeatedGroup_extension!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.RepeatedGroup_extension!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[468,60] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedMessage!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[470,61] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.ForeignMessage!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.ForeignMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[471,60] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestImport.ImportMessage!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestImport.ImportMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[473,58] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedMessage!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedMessage!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[475,57] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.TestAllTypes.NestedEnum!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.TestAllTypes.NestedEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[476,58] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestProto.ForeignEnum!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestProto.ForeignEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[477,57] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: UnittestImport.ImportEnum!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: UnittestImport.ImportEnum!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[478,58] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: String!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl -[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt:[479,51] Assignment operators ambiguity: -[ERROR] public operator fun Collection.plus(element: String!): List defined in kotlin.collections -[ERROR] public final inline operator fun ExtensionList.plusAssign(value: String!): Unit defined in protobuf_unittest.TestAllExtensionsKt.Dsl +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[15,5] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , B : com.google.protobuf.GeneratedMessage.ExtendableBuilder, T> TypeVariable(B).set(extension: ExtensionLite, value: TypeVariable(T)): Unit defined in com.google.protobuf.kotlin +[ERROR] public operator fun , B : com.google.protobuf.GeneratedMessageLite.ExtendableBuilder, T> TypeVariable(B).set(extension: ExtensionLite, value: TypeVariable(T)): Unit defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[15,12] No set method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[23,16] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MOrBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder, T> TypeVariable(MOrBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder, T> TypeVariable(MorBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[23,23] No get method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[31,16] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MOrBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder, T> TypeVariable(MOrBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder, T> TypeVariable(MorBT).get(extension: ExtensionLite): TypeVariable(T) defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[31,23] No get method providing array access +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[39,41] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[46,41] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[52,41] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] /usr/local/google/home/deannagarcia/protobuf/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt:[58,41] Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin +[ERROR] public operator fun , MorBT : com.google.protobuf.GeneratedMessageLite.ExtendableMessageOrBuilder> TypeVariable(MorBT).contains(extension: ExtensionLite): Boolean defined in com.google.protobuf.kotlin [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. diff --git a/java/core/pom.xml b/java/core/pom.xml index f4ae7db601..fb68d9d665 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -41,20 +41,26 @@ guava test + + com.google.guava + guava-testlib + test + com.google.truth truth test - org.jetbrains.kotlin - kotlin-stdlib-jdk7 - ${kotlin.version} + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + ${kotlin.version} - org.jetbrains.kotlin - kotlin-reflect - ${kotlin.version} + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test diff --git a/java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensionsLite.kt b/java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensionsLite.kt new file mode 100644 index 0000000000..8bd8ed364f --- /dev/null +++ b/java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensionsLite.kt @@ -0,0 +1,28 @@ +package com.google.protobuf.kotlin + +import com.google.protobuf.ExtensionLite +import com.google.protobuf.GeneratedMessageLite + +/** Gets the value of the proto extension. */ +operator fun < + M : GeneratedMessageLite.ExtendableMessage, + MOrBT : GeneratedMessageLite.ExtendableMessageOrBuilder, + T + > MOrBT.get(extension: ExtensionLite): T = getExtension(extension) + +/** Sets the current value of the proto extension in this builder. */ +operator fun < + M : GeneratedMessageLite.ExtendableMessage, + B : GeneratedMessageLite.ExtendableBuilder, + T + > B.set(extension: ExtensionLite, value: T) { + setExtension(extension, value) +} + +/** Returns true if the specified extension is set. */ +operator fun < + M : GeneratedMessageLite.ExtendableMessage, + MorBT : GeneratedMessageLite.ExtendableMessageOrBuilder + > MorBT.contains( + extension: ExtensionLite +): Boolean = hasExtension(extension) diff --git a/java/core/src/test/kotlin/com/google/protobuf/DslListTest.kt b/java/core/src/test/kotlin/com/google/protobuf/DslListTest.kt new file mode 100644 index 0000000000..e5e6017c06 --- /dev/null +++ b/java/core/src/test/kotlin/com/google/protobuf/DslListTest.kt @@ -0,0 +1,98 @@ +package com.google.protobuf.kotlin + +import com.google.common.testing.EqualsTester +import com.google.common.truth.Truth.assertThat +import kotlin.test.assertFailsWith +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +/** Tests for [DslList]. */ +@RunWith(JUnit4::class) +@OptIn(OnlyForUseByGeneratedProtoCode::class) +class DslListTest { + class DummyProxy private constructor() : DslProxy() + + @Test + fun matchesList() { + assertThat(DslList(listOf(1, 2, 3))).containsExactly(1, 2, 3).inOrder() + } + + @Test + fun reflectsChangesInList() { + val mutableList = mutableListOf(1, 2, 3) + val dslList = DslList(mutableList) + mutableList.add(4) + assertThat(dslList).containsExactly(1, 2, 3, 4).inOrder() + } + + @Test + fun dslListIsNotMutable() { + val dslList = DslList(mutableListOf(1, 2, 3)) + assertThat(dslList is MutableList<*>).isFalse() + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslListIsNotEvenSecretlyMutable() { + val dslList = DslList(mutableListOf(1, 2, 3)) + val dslListAsJavaUtil = dslList as java.util.List + assertFailsWith { + dslListAsJavaUtil.add(4) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslList_IteratorIsNotEvenSecretlyMutable() { + val dslList = DslList(mutableListOf(1, 2, 3)) + val iterator = dslList.iterator() as java.util.Iterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslList_ListIteratorIsNotEvenSecretlyMutable() { + val dslList = DslList(mutableListOf(1, 2, 3)) + val iterator = dslList.listIterator() as java.util.ListIterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslList_ListIteratorIndexIsNotEvenSecretlyMutable() { + val dslList = DslList(mutableListOf(1, 2, 3)) + val iterator = dslList.listIterator(1) as java.util.ListIterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Test + fun expectedToString() { + assertThat(DslList(listOf(1, 2)).toString()).isEqualTo("[1, 2]") + } + + @Test + fun equality() { + EqualsTester() + .addEqualityGroup(DslList(listOf(1, 2)), listOf(1, 2)) + .addEqualityGroup(DslList(listOf(2, 2)), listOf(2, 2)) + .addEqualityGroup( + DslList(emptyList()), + DslList(emptyList()), + emptyList() + ) + .testEquals() + } +} diff --git a/java/core/src/test/kotlin/com/google/protobuf/DslMapTest.kt b/java/core/src/test/kotlin/com/google/protobuf/DslMapTest.kt new file mode 100644 index 0000000000..470e42e48a --- /dev/null +++ b/java/core/src/test/kotlin/com/google/protobuf/DslMapTest.kt @@ -0,0 +1,164 @@ +package com.google.protobuf.kotlin + +import com.google.common.testing.EqualsTester +import com.google.common.truth.Truth.assertThat +import kotlin.test.assertFailsWith +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +@OptIn(OnlyForUseByGeneratedProtoCode::class) +class DslMapTest { + class DummyProxy private constructor() : DslProxy() + + @Test + fun matchesMap() { + assertThat(DslMap(mapOf(1 to -1, 2 to -2))) + .containsExactly(1, -1, 2, -2) + } + + @Test + fun reflectsChangesInMap() { + val mutableMap = mutableMapOf(1 to -1, 2 to -2) + val dslMap = DslMap(mutableMap) + mutableMap[3] = -3 + assertThat(dslMap).containsExactly(1, -1, 2, -2, 3, -3).inOrder() + } + + @Test + fun dslMapIsNotMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + assertThat(dslMap is MutableMap<*, *>).isFalse() + } + + @Test + fun dslMapKeysAreNotMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + assertThat(dslMap.keys is MutableSet<*>).isFalse() + } + + @Test + fun dslMapValuesAreNotMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + assertThat(dslMap.values is MutableSet<*>).isFalse() + } + + @Test + fun dslMapEntriesAreNotMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + assertThat(dslMap.entries is MutableSet<*>).isFalse() + } + + @Test + fun dslMapEntryObjectsAreNotMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + assertThat(dslMap.entries.single() is MutableMap.MutableEntry<*, *>).isFalse() + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapIsNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapAsJavaUtilMap = dslMap as java.util.Map + assertFailsWith { + dslMapAsJavaUtilMap.put(2, -2) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapKeysAreNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapKeysAsJavaUtilSet = dslMap.keys as java.util.Set + assertFailsWith { + dslMapKeysAsJavaUtilSet.remove(1) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapKeysIteratorIsNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapKeysAsJavaUtilSet = dslMap.keys as java.util.Set + val itr = dslMapKeysAsJavaUtilSet.iterator() + itr.next() + assertFailsWith { + itr.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapValuesAreNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapValuesAsJavaUtilCollection = dslMap.values as java.util.Collection + assertFailsWith { + dslMapValuesAsJavaUtilCollection.remove(1) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapValuesIteratorIsNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapValuesAsJavaUtilCollection = dslMap.values as java.util.Collection + val itr = dslMapValuesAsJavaUtilCollection.iterator() + itr.next() + assertFailsWith { + itr.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapEntriesAreNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapEntriesAsJavaUtilSet = dslMap.entries as java.util.Set> + val entry = dslMap.entries.single() + assertFailsWith { + dslMapEntriesAsJavaUtilSet.remove(entry) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapEntriesIteratorIsNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapEntriesAsJavaUtilSet = dslMap.entries as java.util.Set> + val itr = dslMapEntriesAsJavaUtilSet.iterator() + itr.next() + assertFailsWith { + itr.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun dslMapEntryObjectsAreNotEvenSecretlyMutable() { + val dslMap = DslMap(mutableMapOf(1 to -1)) + val dslMapEntryAsJavaUtilMapEntry = dslMap.entries.single() as java.util.Map.Entry + assertFailsWith { + dslMapEntryAsJavaUtilMapEntry.value = 2 + } + } + + @Test + fun expectedToString() { + assertThat(DslMap(mapOf(1 to 2, 2 to 3)).toString()) + .isEqualTo("{1=2, 2=3}") + } + + @Test + fun equality() { + EqualsTester() + .addEqualityGroup(DslMap(mapOf(1 to 2, 2 to 3)), mapOf(1 to 2, 2 to 3)) + .addEqualityGroup(DslMap(mapOf(1 to 3, 2 to 3)), mapOf(1 to 3, 2 to 3)) + .addEqualityGroup( + DslMap(emptyMap()), + DslMap(emptyMap()), + emptyMap() + ) + .testEquals() + } +} diff --git a/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt b/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt new file mode 100644 index 0000000000..c8816eba7f --- /dev/null +++ b/java/core/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt @@ -0,0 +1,60 @@ +package com.google.protobuf.kotlin + +import com.google.common.truth.Truth.assertThat +import example_extensible_message.ExampleExtensibleMessage +import example_extensible_message.ExampleExtensibleMessageOuterClass as TestProto +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class ExtendableMessageExtensionsTest { + @Test + fun setOnBuilder() { + val builder = ExampleExtensibleMessage.newBuilder() + builder[TestProto.int32Extension] = 5 + assertThat(builder.build().getExtension(TestProto.int32Extension)).isEqualTo(5) + } + + @Test + fun getOnBuilder() { + val builder = ExampleExtensibleMessage.newBuilder() + .setExtension(TestProto.int32Extension, 6) + assertThat(builder[TestProto.int32Extension]).isEqualTo(6) + } + + @Test + fun getOnMessage() { + val message = ExampleExtensibleMessage.newBuilder() + .setExtension(TestProto.int32Extension, 6) + .build() + assertThat(message[TestProto.int32Extension]).isEqualTo(6) + } + + @Test + fun containsPositiveOnMessage() { + val message = ExampleExtensibleMessage.newBuilder() + .setExtension(TestProto.int32Extension, 6) + .build() + assertThat(TestProto.int32Extension in message).isTrue() + } + + @Test + fun containsPositiveOnBuilder() { + val builder = ExampleExtensibleMessage.newBuilder() + .setExtension(TestProto.int32Extension, 6) + assertThat(TestProto.int32Extension in builder).isTrue() + } + + @Test + fun containsNegativeOnMessage() { + val message = ExampleExtensibleMessage.newBuilder().build() + assertThat(TestProto.int32Extension in message).isFalse() + } + + @Test + fun containsNegativeOnBuilder() { + val builder = ExampleExtensibleMessage.newBuilder() + assertThat(TestProto.int32Extension in builder).isFalse() + } +} diff --git a/java/core/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt b/java/core/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt new file mode 100644 index 0000000000..e805e1e551 --- /dev/null +++ b/java/core/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt @@ -0,0 +1,125 @@ +package com.google.protobuf.kotlin + +import com.google.common.testing.EqualsTester +import com.google.common.truth.Truth.assertThat +import example_extensible_message.ExampleExtensibleMessage +import example_extensible_message.ExampleExtensibleMessageOuterClass as TestProto +import kotlin.test.assertFailsWith +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +/** Tests for [DslList]. */ +@RunWith(JUnit4::class) +@OptIn(OnlyForUseByGeneratedProtoCode::class) +class ExtensionListTest { + class DummyProxy private constructor() : DslProxy() + + @Test + fun matchesList() { + assertThat( + ExtensionList( + TestProto.repeatedExtension, listOf(1, 2, 3) + ) + ).containsExactly(1, 2, 3).inOrder() + } + + @Test + fun reflectsChangesInList() { + val mutableList = mutableListOf(1, 2, 3) + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableList + ) + mutableList.add(4) + assertThat(extensionList).containsExactly(1, 2, 3, 4).inOrder() + } + + @Test + fun extensionListIsNotMutable() { + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableListOf(1, 2, 3) + ) + assertThat(extensionList is MutableList<*>).isFalse() + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun extensionListIsNotEvenSecretlyMutable() { + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableListOf(1, 2, 3) + ) + val extensionListAsJavaUtil = extensionList as java.util.List + assertFailsWith { + extensionListAsJavaUtil.add(4) + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun extensionList_IteratorIsNotEvenSecretlyMutable() { + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableListOf(1, 2, 3) + ) + val iterator = extensionList.iterator() as java.util.Iterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun extensionList_ListIteratorIsNotEvenSecretlyMutable() { + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableListOf(1, 2, 3) + ) + val iterator = extensionList.listIterator() as java.util.ListIterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST") + @Test + fun extensionList_ListIteratorIndexIsNotEvenSecretlyMutable() { + val extensionList = ExtensionList( + TestProto.repeatedExtension, mutableListOf(1, 2, 3) + ) + val iterator = extensionList.listIterator(1) as java.util.ListIterator + iterator.next() + + assertFailsWith { + iterator.remove() + } + } + + @Test + fun expectedToString() { + assertThat( + ExtensionList(TestProto.repeatedExtension, listOf(1, 2)) + .toString() + ).isEqualTo("[1, 2]") + } + + @Test + fun equality() { + EqualsTester() + .addEqualityGroup( + ExtensionList(TestProto.repeatedExtension, listOf(1, 2)), + ExtensionList(TestProto.differentExtension, listOf(1, 2)), + listOf(1, 2) + ) + .addEqualityGroup( + ExtensionList(TestProto.repeatedExtension, listOf(2, 2)), + listOf(2, 2) + ) + .addEqualityGroup( + ExtensionList(TestProto.repeatedExtension, emptyList()), + emptyList() + ) + .testEquals() + } +} diff --git a/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt b/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt index f131d29bb3..72b9792b55 100644 --- a/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt +++ b/java/core/src/test/kotlin/com/google/protobuf/Proto2Test.kt @@ -44,7 +44,6 @@ import org.junit.runners.JUnit4 class Proto2Test { @Test fun testSetters() { - val myInt: Int = 301 assertThat( testAllTypes { optionalInt32 = 101 @@ -103,7 +102,7 @@ class Proto2Test { repeatedImportEnum.add(ImportEnum.IMPORT_BAR) repeatedStringPiece.add("224") repeatedCord.add("225") - repeatedInt32 += myInt + repeatedInt32 += 301 repeatedInt64 += 302 repeatedUint32 += 303 repeatedUint64 += 304 @@ -449,34 +448,34 @@ class Proto2Test { this[UnittestProto.repeatedImportEnumExtension].add(ImportEnum.IMPORT_BAR) this[UnittestProto.repeatedStringPieceExtension].add("224") this[UnittestProto.repeatedCordExtension].add("225") - this[UnittestProto.repeatedInt32Extension] += 301 - this[UnittestProto.repeatedInt64Extension] += 302L - this[UnittestProto.repeatedUint32Extension] += 303 - this[UnittestProto.repeatedUint64Extension] += 304L - this[UnittestProto.repeatedSint32Extension] += 305 - this[UnittestProto.repeatedSint64Extension] += 306L - this[UnittestProto.repeatedFixed32Extension] += 307 - this[UnittestProto.repeatedFixed64Extension] += 308L - this[UnittestProto.repeatedSfixed32Extension] += 309 - this[UnittestProto.repeatedSfixed64Extension] += 310L - this[UnittestProto.repeatedFloatExtension] += 311F - this[UnittestProto.repeatedDoubleExtension] += 312.0 - this[UnittestProto.repeatedBoolExtension] += false - this[UnittestProto.repeatedStringExtension] += "315" - this[UnittestProto.repeatedBytesExtension] += toBytes("316") - this[UnittestProto.repeatedGroupExtension] += repeatedGroupExtension { a = 317 } - this[UnittestProto.repeatedNestedMessageExtension] += - TestAllTypesKt.nestedMessage { bb = 318 } - this[UnittestProto.repeatedForeignMessageExtension] += foreignMessage { c = 319 } - this[UnittestProto.repeatedImportMessageExtension] += - ImportMessage.newBuilder().setD(320).build() - this[UnittestProto.repeatedLazyMessageExtension] += - TestAllTypesKt.nestedMessage { bb = 327 } - this[UnittestProto.repeatedNestedEnumExtension] += NestedEnum.BAZ - this[UnittestProto.repeatedForeignEnumExtension] += ForeignEnum.FOREIGN_BAZ - this[UnittestProto.repeatedImportEnumExtension] += ImportEnum.IMPORT_BAZ - this[UnittestProto.repeatedStringPieceExtension] += "324" - this[UnittestProto.repeatedCordExtension] += "325" + this[UnittestProto.repeatedInt32Extension].add(301) + this[UnittestProto.repeatedInt64Extension].add(302L) + this[UnittestProto.repeatedUint32Extension].add(303) + this[UnittestProto.repeatedUint64Extension].add(304L) + this[UnittestProto.repeatedSint32Extension].add(305) + this[UnittestProto.repeatedSint64Extension].add(306L) + this[UnittestProto.repeatedFixed32Extension].add(307) + this[UnittestProto.repeatedFixed64Extension].add(308L) + this[UnittestProto.repeatedSfixed32Extension].add(309) + this[UnittestProto.repeatedSfixed64Extension].add(310L) + this[UnittestProto.repeatedFloatExtension].add(311F) + this[UnittestProto.repeatedDoubleExtension].add(312.0) + this[UnittestProto.repeatedBoolExtension].add(false) + this[UnittestProto.repeatedStringExtension].add("315") + this[UnittestProto.repeatedBytesExtension].add(toBytes("316")) + this[UnittestProto.repeatedGroupExtension].add(repeatedGroupExtension { a = 317 }) + this[UnittestProto.repeatedNestedMessageExtension] + .add(TestAllTypesKt.nestedMessage { bb = 318 }) + this[UnittestProto.repeatedForeignMessageExtension].add(foreignMessage { c = 319 }) + this[UnittestProto.repeatedImportMessageExtension] + .add(ImportMessage.newBuilder().setD(320).build()) + this[UnittestProto.repeatedLazyMessageExtension] + .add(TestAllTypesKt.nestedMessage { bb = 327 }) + this[UnittestProto.repeatedNestedEnumExtension].add(NestedEnum.BAZ) + this[UnittestProto.repeatedForeignEnumExtension].add(ForeignEnum.FOREIGN_BAZ) + this[UnittestProto.repeatedImportEnumExtension].add(ImportEnum.IMPORT_BAZ) + this[UnittestProto.repeatedStringPieceExtension].add("324") + this[UnittestProto.repeatedCordExtension].add("325") this[UnittestProto.defaultInt32Extension] = 401 this[UnittestProto.defaultInt64Extension] = 402L this[UnittestProto.defaultUint32Extension] = 403 diff --git a/java/core/src/test/kotlin/com/google/protobuf/Proto3Test.kt b/java/core/src/test/kotlin/com/google/protobuf/Proto3Test.kt new file mode 100644 index 0000000000..b3fd336731 --- /dev/null +++ b/java/core/src/test/kotlin/com/google/protobuf/Proto3Test.kt @@ -0,0 +1,340 @@ +package com.google.protobuf.kotlin + +import com.google.common.truth.Truth.assertThat +import evil_names_proto3.EvilNamesProto3OuterClass.EvilNamesProto3 +import evil_names_proto3.EvilNamesProto3OuterClass.HardKeywordsAllTypes +import evil_names_proto3.EvilNamesProto3OuterClass.Class +import evil_names_proto3.HardKeywordsAllTypesKt +import evil_names_proto3.class_ +import evil_names_proto3.evilNamesProto3 +import evil_names_proto3.hardKeywordsAllTypes +import multiple_files_proto3.MultipleFilesMessageA +import multiple_files_proto3.MultipleFilesMessageB +import multiple_files_proto3.multipleFilesMessageA +import multiple_files_proto3.multipleFilesMessageB +import proto3_unittest.UnittestProto3 +import proto3_unittest.TestAllTypesKt +import proto3_unittest.TestAllTypesKt.nestedMessage +import proto3_unittest.UnittestProto3.TestAllTypes +import proto3_unittest.UnittestProto3.TestAllTypes.NestedEnum +import proto3_unittest.UnittestProto3.TestEmptyMessage +import proto3_unittest.copy +import proto3_unittest.testAllTypes +import proto3_unittest.testEmptyMessage +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class Proto3Test { + @Test + fun testGettersAndSetters() { + testAllTypes { + optionalInt32 = 101 + assertThat(optionalInt32).isEqualTo(101) + optionalString = "115" + assertThat(optionalString).isEqualTo("115") + optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } + assertThat(optionalNestedMessage).isEqualTo(TestAllTypesKt.nestedMessage { bb = 118 }) + optionalNestedEnum = NestedEnum.BAZ + assertThat(optionalNestedEnum).isEqualTo(NestedEnum.BAZ) + oneofUint32 = 601 + assertThat(oneofUint32).isEqualTo(601) + } + } + + @Test + fun testRepeatedGettersAndSetters() { + testAllTypes { + repeatedInt32.addAll(listOf(1, 2)) + assertThat(repeatedInt32).isEqualTo(listOf(1, 2)) + repeatedInt32 += listOf(3, 4) + assertThat(repeatedInt32).isEqualTo(listOf(1, 2, 3, 4)) + repeatedInt32[0] = 5 + assertThat(repeatedInt32).isEqualTo(listOf(5, 2, 3, 4)) + + repeatedString.addAll(listOf("1", "2")) + assertThat(repeatedString).isEqualTo(listOf("1", "2")) + repeatedString += listOf("3", "4") + assertThat(repeatedString).isEqualTo(listOf("1", "2", "3", "4")) + repeatedString[0] = "5" + assertThat(repeatedString).isEqualTo(listOf("5", "2", "3", "4")) + + repeatedNestedMessage.addAll(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 } + ) + ) + repeatedNestedMessage += listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } + ) + ) + repeatedNestedMessage[0] = nestedMessage { bb = 5 } + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 5 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } + ) + ) + + repeatedNestedEnum.addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) + assertThat(repeatedNestedEnum).isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) + repeatedNestedEnum += listOf(NestedEnum.BAZ, NestedEnum.FOO) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) + repeatedNestedEnum[0] = NestedEnum.BAR + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) + } + } + + @Test + fun testClears() { + assertThat( + testAllTypes { + optionalInt32 = 101 + clearOptionalInt32() + + optionalString = "115" + clearOptionalString() + + optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } + clearOptionalNestedMessage() + + optionalNestedEnum = NestedEnum.BAZ + clearOptionalNestedEnum() + + oneofUint32 = 601 + clearOneofUint32() + } + ).isEqualTo( + TestAllTypes.newBuilder().build() + ) + } + + @Test + fun testCopy() { + val message = testAllTypes { + optionalInt32 = 101 + optionalString = "115" + } + val modifiedMessage = message.copy { + optionalInt32 = 201 + } + + assertThat(message).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(101) + .setOptionalString("115") + .build() + ) + assertThat(modifiedMessage).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(201) + .setOptionalString("115") + .build() + ) + } + + @Test + fun testOneof() { + val message = testAllTypes { + oneofString = "foo" + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_STRING) + assertThat(oneofString).isEqualTo("foo") + clearOneofField() + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOFFIELD_NOT_SET) + oneofUint32 = 5 + } + + assertThat(message.getOneofFieldCase()) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_UINT32) + assertThat(message.getOneofUint32()).isEqualTo(5) + } + + @Test + fun testEmptyMessages() { + assertThat( + testEmptyMessage {} + ).isEqualTo( + TestEmptyMessage.newBuilder().build() + ) + } + + @Test + fun testEvilNames() { + assertThat( + evilNamesProto3 { + initialized = true + hasFoo = true + bar = "foo" + isInitialized = true + fooBar = "foo" + aLLCAPS += "foo" + aLLCAPSMAP[1] = true + hasUnderbarPrecedingNumeric1Foo = true + hasUnderbarPrecedingNumeric42Bar = true + hasUnderbarPrecedingNumeric123Foo42BarBaz = true + extension += "foo" + class_ = "foo" + int = 1.0 + long = true + boolean = 1L + sealed = "foo" + interface_ = 1F + in_ = 1 + object_ = "foo" + cachedSize_ = "foo" + serializedSize_ = true + value = "foo" + index = 1L + values += "foo" + newValues += "foo" + builder = true + k[1] = 1 + v["foo"] = "foo" + key["foo"] = 1 + map[1] = "foo" + pairs["foo"] = 1 + LeadingUnderscore = "foo" + option = 1 + } + ).isEqualTo( + EvilNamesProto3.newBuilder() + .setInitialized(true) + .setHasFoo(true) + .setBar("foo") + .setIsInitialized(true) + .setFooBar("foo") + .addALLCAPS("foo") + .putALLCAPSMAP(1, true) + .setHasUnderbarPrecedingNumeric1Foo(true) + .setHasUnderbarPrecedingNumeric42Bar(true) + .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) + .addExtension("foo") + .setClass_("foo") + .setInt(1.0) + .setLong(true) + .setBoolean(1L) + .setSealed("foo") + .setInterface(1F) + .setIn(1) + .setObject("foo") + .setCachedSize_("foo") + .setSerializedSize_(true) + .setValue("foo") + .setIndex(1L) + .addValues("foo") + .addNewValues("foo") + .setBuilder(true) + .putK(1, 1) + .putV("foo", "foo") + .putKey("foo", 1) + .putMap(1, "foo") + .putPairs("foo", 1) + .setLeadingUnderscore("foo") + .setOption(1) + .build() + ) + + assertThat(class_ {}).isEqualTo(Class.newBuilder().build()) + } + + @Test + fun testHardKeywordGettersAndSetters() { + hardKeywordsAllTypes { + as_ = 1 + assertThat(as_).isEqualTo(1) + + in_ = "foo" + assertThat(in_).isEqualTo("foo") + + break_ = HardKeywordsAllTypes.NestedEnum.FOO + assertThat(break_).isEqualTo(HardKeywordsAllTypes.NestedEnum.FOO) + + do_ = HardKeywordsAllTypesKt.nestedMessage { while_ = 1 } + assertThat(do_).isEqualTo(HardKeywordsAllTypesKt.nestedMessage { while_ = 1 }) + + continue_[1] = 1 + assertThat(continue_[1]).isEqualTo(1) + + else_ += 1 + assertThat(else_).isEqualTo(listOf(1)) + + for_ += "foo" + assertThat(for_).isEqualTo(listOf("foo")) + + fun_ += HardKeywordsAllTypes.NestedEnum.FOO + assertThat(fun_).isEqualTo(listOf(HardKeywordsAllTypes.NestedEnum.FOO)) + + if_ += HardKeywordsAllTypesKt.nestedMessage { while_ = 1 } + assertThat(if_).isEqualTo(listOf(HardKeywordsAllTypesKt.nestedMessage { while_ = 1 })) + } + } + + @Test + fun testHardKeywordHazzers() { + hardKeywordsAllTypes { + as_ = 1 + assertThat(hasAs_()).isTrue() + + in_ = "foo" + assertThat(hasIn_()).isTrue() + + break_ = HardKeywordsAllTypes.NestedEnum.FOO + assertThat(hasBreak_()).isTrue() + + do_ = HardKeywordsAllTypesKt.nestedMessage { while_ = 1 } + assertThat(hasDo_()).isTrue() + } + } + + @Test + fun testHardKeywordClears() { + hardKeywordsAllTypes { + as_ = 1 + clearAs_() + assertThat(hasAs_()).isFalse() + + in_ = "foo" + clearIn_() + assertThat(hasIn_()).isFalse() + + break_ = HardKeywordsAllTypes.NestedEnum.FOO + clearBreak_() + assertThat(hasBreak_()).isFalse() + + do_ = HardKeywordsAllTypesKt.nestedMessage { while_ = 1 } + clearDo_() + assertThat(hasDo_()).isFalse() + } + } + + @Test + fun testMultipleFiles() { + assertThat( + multipleFilesMessageA {} + ).isEqualTo( + MultipleFilesMessageA.newBuilder().build() + ) + + assertThat( + multipleFilesMessageB {} + ).isEqualTo( + MultipleFilesMessageB.newBuilder().build() + ) + } +} diff --git a/java/core/src/test/proto/com/google/protobuf/evil_names_proto3.proto b/java/core/src/test/proto/com/google/protobuf/evil_names_proto3.proto index f0faa1c10c..1b40e4d8c1 100644 --- a/java/core/src/test/proto/com/google/protobuf/evil_names_proto3.proto +++ b/java/core/src/test/proto/com/google/protobuf/evil_names_proto3.proto @@ -1,9 +1,8 @@ -// LINT: LEGACY_NAMES syntax = "proto3"; -package protobuf.kotlin.generator; +package evil_names_proto3; -option java_package = "com.google.protobuf.kotlin.generator"; +option java_package = "evil_names_proto3"; message EvilNamesProto3 { bool initialized = 1; diff --git a/java/core/src/test/proto/com/google/protobuf/test.proto b/java/core/src/test/proto/com/google/protobuf/example_extensible_message.proto similarity index 75% rename from java/core/src/test/proto/com/google/protobuf/test.proto rename to java/core/src/test/proto/com/google/protobuf/example_extensible_message.proto index 7416eb45a8..14f18dbdb1 100644 --- a/java/core/src/test/proto/com/google/protobuf/test.proto +++ b/java/core/src/test/proto/com/google/protobuf/example_extensible_message.proto @@ -1,8 +1,8 @@ syntax = "proto2"; -package protobuf.kotlin.test; +package example_extensible_message; -option java_package = "com.google.protobuf.kotlin.test"; +option java_package = "example_extensible_message"; option java_multiple_files = true; message ExampleExtensibleMessage { diff --git a/java/core/src/test/proto/com/google/protobuf/mutliple_files_proto3.proto b/java/core/src/test/proto/com/google/protobuf/multiple_files_proto3.proto similarity index 61% rename from java/core/src/test/proto/com/google/protobuf/mutliple_files_proto3.proto rename to java/core/src/test/proto/com/google/protobuf/multiple_files_proto3.proto index 1b14213291..82211ccd61 100644 --- a/java/core/src/test/proto/com/google/protobuf/mutliple_files_proto3.proto +++ b/java/core/src/test/proto/com/google/protobuf/multiple_files_proto3.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package protobuf.kotlin.generator; +package multiple_files_proto3; -option java_package = "com.google.protobuf.kotlin.generator"; +option java_package = "multiple_files_proto3"; option java_multiple_files = true; enum NestedEnum { FOO = 0; } diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 43de45426d..7653716d7e 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -4,6 +4,8 @@ + + @@ -20,6 +22,9 @@ + + + @@ -29,6 +34,7 @@ + @@ -52,7 +58,13 @@ - + + + + + + + diff --git a/java/lite/pom.xml b/java/lite/pom.xml index e5a98e7b9a..41690672c7 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -16,6 +16,10 @@ not guarantee API/ABI stability. + + 1.4.31 + + junit @@ -37,11 +41,26 @@ guava test + + com.google.guava + guava-testlib + test + com.google.truth truth test + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + @@ -179,6 +198,19 @@ Writer.java + + ${basedir}/../core/src/main/kotlin/com/google/protobuf + + DslList.kt + DslMap.kt + DslProxy.kt + ExtendableMessageLiteExtensions.kt + ExtensionList.kt + OnlyForUseByGeneratedProtoCode.kt + ProtoDslMarker.kt + UnmodifiableCollections.kt + + @@ -238,6 +270,13 @@ WireFormatTest.java + + ${basedir}/../core/src/test/kotlin/com/google/protobuf + + ExtendableMessageExtensionsTest.kt + Proto2Test.kt + + @@ -326,8 +365,19 @@ org.jetbrains.kotlin kotlin-maven-plugin + ${kotlin.version} true + + compile + compile + + + ${generated.sources.dir}/com/google/protobuf + ${project.basedir}/src/main/kotlin + + + test-compile test-compile diff --git a/java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt b/java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt index 9cf8c5975f..18933d1a34 100644 --- a/java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt +++ b/java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt @@ -1,8 +1,8 @@ package com.google.protobuf.kotlin import com.google.common.truth.Truth.assertThat -import com.google.protobuf.kotlin.test.ExampleExtensibleMessage -import com.google.protobuf.kotlin.test.Test as TestProto +import example_extensible_message.ExampleExtensibleMessage +import example_extensible_message.ExampleExtensibleMessageOuterClass as TestProto import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 diff --git a/java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt b/java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt index 470d978353..8726bbf9f9 100644 --- a/java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt +++ b/java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt @@ -16,22 +16,22 @@ import com.google.protobuf.UnittestLite.TestEmptyMessageLite import com.google.protobuf.UnittestLite.TestEmptyMessageWithExtensionsLite import com.google.protobuf.copy import com.google.protobuf.foreignMessageLite -import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.EvilNamesProto2 -import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.HardKeywordsAllTypes -import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.Interface -import com.google.protobuf.kotlin.generator.HardKeywordsAllTypesKt -import com.google.protobuf.kotlin.generator.evilNamesProto2 -import com.google.protobuf.kotlin.generator.hardKeywordsAllTypes -import com.google.protobuf.kotlin.generator.interface_ +import evil_names_proto2.EvilNamesProto2OuterClass.EvilNamesProto2 +import evil_names_proto2.EvilNamesProto2OuterClass.HardKeywordsAllTypes +import evil_names_proto2.EvilNamesProto2OuterClass.Interface +import evil_names_proto2.HardKeywordsAllTypesKt +import evil_names_proto2.evilNamesProto2 +import evil_names_proto2.hardKeywordsAllTypes +import evil_names_proto2.interface_ import com.google.protobuf.optionalGroupExtensionLite import com.google.protobuf.repeatedGroupExtensionLite import com.google.protobuf.testAllExtensionsLite import com.google.protobuf.testAllTypesLite import com.google.protobuf.testEmptyMessageLite import com.google.protobuf.testEmptyMessageWithExtensionsLite -import com.google.protos.proto2_unittest.MapLiteUnittest.MapEnumLite -import com.google.protos.proto2_unittest.MapLiteUnittest.TestMapLite -import com.google.protos.proto2_unittest.testMapLite +import protobuf_unittest.MapLiteUnittest.MapEnumLite +import protobuf_unittest.MapLiteUnittest.TestMapLite +import protobuf_unittest.testMapLite import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @@ -452,34 +452,37 @@ class Proto2LiteTest { this[UnittestLite.repeatedImportEnumExtensionLite].add(ImportEnumLite.IMPORT_LITE_BAR) this[UnittestLite.repeatedStringPieceExtensionLite].add("224") this[UnittestLite.repeatedCordExtensionLite].add("225") - this[UnittestLite.repeatedInt32ExtensionLite] += 301 - this[UnittestLite.repeatedInt64ExtensionLite] += 302L - this[UnittestLite.repeatedUint32ExtensionLite] += 303 - this[UnittestLite.repeatedUint64ExtensionLite] += 304L - this[UnittestLite.repeatedSint32ExtensionLite] += 305 - this[UnittestLite.repeatedSint64ExtensionLite] += 306L - this[UnittestLite.repeatedFixed32ExtensionLite] += 307 - this[UnittestLite.repeatedFixed64ExtensionLite] += 308L - this[UnittestLite.repeatedSfixed32ExtensionLite] += 309 - this[UnittestLite.repeatedSfixed64ExtensionLite] += 310L - this[UnittestLite.repeatedFloatExtensionLite] += 311F - this[UnittestLite.repeatedDoubleExtensionLite] += 312.0 - this[UnittestLite.repeatedBoolExtensionLite] += false - this[UnittestLite.repeatedStringExtensionLite] += "315" - this[UnittestLite.repeatedBytesExtensionLite] += toBytes("316") - this[UnittestLite.repeatedGroupExtensionLite] += repeatedGroupExtensionLite { a = 317 } - this[UnittestLite.repeatedNestedMessageExtensionLite] += + this[UnittestLite.repeatedInt32ExtensionLite].add(301) + this[UnittestLite.repeatedInt64ExtensionLite].add(302L) + this[UnittestLite.repeatedUint32ExtensionLite].add(303) + this[UnittestLite.repeatedUint64ExtensionLite].add(304L) + this[UnittestLite.repeatedSint32ExtensionLite].add(305) + this[UnittestLite.repeatedSint64ExtensionLite].add(306L) + this[UnittestLite.repeatedFixed32ExtensionLite].add(307) + this[UnittestLite.repeatedFixed64ExtensionLite].add(308L) + this[UnittestLite.repeatedSfixed32ExtensionLite].add(309) + this[UnittestLite.repeatedSfixed64ExtensionLite].add(310L) + this[UnittestLite.repeatedFloatExtensionLite].add(311F) + this[UnittestLite.repeatedDoubleExtensionLite].add(312.0) + this[UnittestLite.repeatedBoolExtensionLite].add(false) + this[UnittestLite.repeatedStringExtensionLite].add("315") + this[UnittestLite.repeatedBytesExtensionLite].add(toBytes("316")) + this[UnittestLite.repeatedGroupExtensionLite].add(repeatedGroupExtensionLite { a = 317 }) + this[UnittestLite.repeatedNestedMessageExtensionLite].add( TestAllTypesLiteKt.nestedMessage { bb = 318 } - this[UnittestLite.repeatedForeignMessageExtensionLite] += foreignMessageLite { c = 319 } - this[UnittestLite.repeatedImportMessageExtensionLite] += + ) + this[UnittestLite.repeatedForeignMessageExtensionLite].add(foreignMessageLite { c = 319 }) + this[UnittestLite.repeatedImportMessageExtensionLite].add( ImportMessageLite.newBuilder().setD(320).build() - this[UnittestLite.repeatedLazyMessageExtensionLite] += + ) + this[UnittestLite.repeatedLazyMessageExtensionLite].add( TestAllTypesLiteKt.nestedMessage { bb = 327 } - this[UnittestLite.repeatedNestedEnumExtensionLite] += NestedEnum.BAZ - this[UnittestLite.repeatedForeignEnumExtensionLite] += ForeignEnumLite.FOREIGN_LITE_BAZ - this[UnittestLite.repeatedImportEnumExtensionLite] += ImportEnumLite.IMPORT_LITE_BAZ - this[UnittestLite.repeatedStringPieceExtensionLite] += "324" - this[UnittestLite.repeatedCordExtensionLite] += "325" + ) + this[UnittestLite.repeatedNestedEnumExtensionLite].add(NestedEnum.BAZ) + this[UnittestLite.repeatedForeignEnumExtensionLite].add(ForeignEnumLite.FOREIGN_LITE_BAZ) + this[UnittestLite.repeatedImportEnumExtensionLite].add(ImportEnumLite.IMPORT_LITE_BAZ) + this[UnittestLite.repeatedStringPieceExtensionLite].add("324") + this[UnittestLite.repeatedCordExtensionLite].add("325") this[UnittestLite.defaultInt32ExtensionLite] = 401 this[UnittestLite.defaultInt64ExtensionLite] = 402L this[UnittestLite.defaultUint32ExtensionLite] = 403 @@ -539,14 +542,14 @@ class Proto2LiteTest { testAllExtensionsLite { this[UnittestLite.repeatedInt32ExtensionLite].addAll(listOf(1, 2)) assertThat(this[UnittestLite.repeatedInt32ExtensionLite]).isEqualTo(listOf(1, 2)) - this[UnittestLite.repeatedInt32ExtensionLite] += listOf(3, 4) + this[UnittestLite.repeatedInt32ExtensionLite].addAll(listOf(3, 4)) assertThat(this[UnittestLite.repeatedInt32ExtensionLite]).isEqualTo(listOf(1, 2, 3, 4)) this[UnittestLite.repeatedInt32ExtensionLite][0] = 5 assertThat(this[UnittestLite.repeatedInt32ExtensionLite]).isEqualTo(listOf(5, 2, 3, 4)) this[UnittestLite.repeatedStringExtensionLite].addAll(listOf("1", "2")) assertThat(this[UnittestLite.repeatedStringExtensionLite]).isEqualTo(listOf("1", "2")) - this[UnittestLite.repeatedStringExtensionLite] += listOf("3", "4") + this[UnittestLite.repeatedStringExtensionLite].addAll(listOf("3", "4")) assertThat(this[UnittestLite.repeatedStringExtensionLite]) .isEqualTo(listOf("1", "2", "3", "4")) this[UnittestLite.repeatedStringExtensionLite][0] = "5" @@ -565,11 +568,12 @@ class Proto2LiteTest { repeatedGroupExtensionLite { a = 2 } ) ) - this[UnittestLite.repeatedGroupExtensionLite] += + this[UnittestLite.repeatedGroupExtensionLite].addAll( listOf( repeatedGroupExtensionLite { a = 3 }, repeatedGroupExtensionLite { a = 4 } ) + ) assertThat(this[UnittestLite.repeatedGroupExtensionLite]).isEqualTo( listOf( repeatedGroupExtensionLite { a = 1 }, @@ -594,8 +598,9 @@ class Proto2LiteTest { assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]).isEqualTo( listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 }) ) - this[UnittestLite.repeatedNestedMessageExtensionLite] += + this[UnittestLite.repeatedNestedMessageExtensionLite].addAll( listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) + ) assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]).isEqualTo( listOf( nestedMessage { bb = 1 }, @@ -618,7 +623,7 @@ class Proto2LiteTest { .addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]) .isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) - this[UnittestLite.repeatedNestedEnumExtensionLite] += listOf(NestedEnum.BAZ, NestedEnum.FOO) + this[UnittestLite.repeatedNestedEnumExtensionLite].addAll(listOf(NestedEnum.BAZ, NestedEnum.FOO)) assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]).isEqualTo( listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) )