From 23fb7fa19f8ef66650404ed4f509a7fade270779 Mon Sep 17 00:00:00 2001 From: dsavvinov Date: Wed, 17 Aug 2016 12:42:33 +0300 Subject: [PATCH] Protobuf. Added more JS tests --- .../kt_js_tests/src/tests/BaseExtendedTest.kt | 123 +++++++++ .../src/tests/BaseExtendedTests.kt | 240 ------------------ .../kt_js_tests/src/tests/ConnectTest.kt | 37 +++ .../kt_js_tests/src/tests/CrossBranchTest.kt | 66 +++++ .../kt_js_tests/src/tests/LocationTest.kt | 51 ++++ .../src/tests/MultipleMessagesTest.kt | 46 ++++ .../src/tests/RepeatedZigZagTest.kt | 36 +++ .../kt_js_tests/src/tests/TagOrderTest.kt | 65 +++++ .../kt_js_tests/src/tests/VarintsTest.kt | 16 +- .../kt_js_tests/src/tests/main.kt | 24 ++ 10 files changed, 456 insertions(+), 248 deletions(-) create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTest.kt delete mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTests.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/ConnectTest.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/CrossBranchTest.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/LocationTest.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/MultipleMessagesTest.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/RepeatedZigZagTest.kt create mode 100644 proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/TagOrderTest.kt diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTest.kt new file mode 100644 index 00000000000..20e2c68d708 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTest.kt @@ -0,0 +1,123 @@ +package tests + +import Base +import CodedInputStream +import Extended + + +object BaseExtendedTest { + fun generateKtBaseMessage(): Base { + val arrSize = Util.nextInt(1000) + val arr = LongArray(arrSize) + for (i in 0..(arrSize - 1)) { + arr[i] = Util.nextLong() + } + + val flag = if (Util.nextInt() % 2 == 0) false else true + + val int = Util.nextInt() + + return Base.BuilderBase(arr, flag, int).build() + } + + fun generateKtExtendedMessage(): Extended { + val arrSize = Util.nextInt(1000) + val arr = LongArray(arrSize) + for (i in 0..(arrSize - 1)) { + arr[i] = Util.nextLong() + } + + val flag = if (Util.nextInt() % 2 == 0) false else true + + val int = Util.nextInt() + + val long = Util.nextLong() + + val longsSize = Util.nextInt(1000) + val longs = LongArray(longsSize) + for (i in 0..(longsSize - 1)) { + longs[i] = Util.nextLong() + } + + return Extended.BuilderExtended(arr, longs, flag, long, int).build() + } + + fun compareBases(kt: Base, jv: Base): Boolean { + return kt.flag == jv.flag && + kt.int == jv.int && + Util.compareArrays(kt.arr.asIterable(), jv.arr.asIterable()) + } + + fun compareExtended(kt: Extended, jv: Extended): Boolean { + return kt.flag == jv.flag && + kt.int == jv.int && + Util.compareArrays(kt.arr.asIterable(), jv.arr.asIterable()) && + Util.compareArrays(kt.arr_longs.asIterable(), jv.arr_longs.asIterable()) && + kt.long == jv.long + } + + fun compareBaseExtended(kt1: Base, kt2: Extended): Boolean { + return kt1.flag == kt2.flag && + kt1.int == kt2.int && + Util.compareArrays(kt1.arr.asIterable(), kt2.arr.asIterable()) + } + + fun baseToBaseOnce() { + val msg = generateKtBaseMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = Base.BuilderBase(LongArray(0), false, 0).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareBases(msg, readMsg)) + } + + fun extendedToExtendedOnce() { + val msg = generateKtExtendedMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = Extended.BuilderExtended(LongArray(0), LongArray(0), false, 0L, 0).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareExtended(msg, readMsg)) + } + + fun baseToExtendedOnce() { + val msg = generateKtBaseMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = Extended.BuilderExtended(LongArray(0), LongArray(0), false, 0L, 0).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareBaseExtended(msg, readMsg)) + } + + fun extendedToBaseOnce() { + val msg = generateKtExtendedMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = Base.BuilderBase(LongArray(0), false, 0).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareBaseExtended(readMsg, msg)) + } + + val testRuns = 1000 + fun runTests() { + for (i in 0..testRuns) { + baseToBaseOnce() + extendedToExtendedOnce() + + baseToExtendedOnce() +// extendedToBaseOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTests.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTests.kt deleted file mode 100644 index d80f5bda2b8..00000000000 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/BaseExtendedTests.kt +++ /dev/null @@ -1,240 +0,0 @@ -//package tests -//import Base -//import Extended -// -// -// -//object BaseExtendedTest { -// fun generateKtBaseMessage(): Base { -// val arrSize = Util.nextInt(1000) -// val arr = LongArray(arrSize) -// for (i in 0..(arrSize - 1)) { -// arr[i] = Util.nextLong() -// } -// -// val flag = if (Util.nextInt() % 2 == 0) false else true -// -// val int = Util.nextInt() -// -// return Base.BuilderBase(arr, flag, int).build() -// } -// -// fun generateKtExtendedMessage(): Extended { -// val arrSize = Util.nextInt(1000) -// val arr = LongArray(arrSize) -// for (i in 0..(arrSize - 1)) { -// arr[i] = Util.nextLong() -// } -// -// val flag = if (Util.nextInt() % 2 == 0) false else true -// -// val int = Util.nextInt() -// -// val long = Util.nextLong() -// -// val longsSize = Util.nextInt(1000) -// val longs = LongArray(longsSize) -// for (i in 0..(longsSize - 1)) { -// longs[i] = Util.nextLong() -// } -// -// return Extended.BuilderExtended(arr, longs, flag, long, int).build() -// } -// -// fun generateJvBaseMessage(): BaseMessage.Base { -// val arrSize = RandomGen.rnd.nextInt(1000) -// val arr = LongArray(arrSize) -// for (i in 0..(arrSize - 1)) { -// arr[i] = RandomGen.rnd.nextLong() -// } -// -// val flag = if (RandomGen.rnd.nextInt() % 2 == 0) false else true -// -// val int = RandomGen.rnd.nextInt() -// -// return BaseMessage.Base.newBuilder() -// .addAllArr(arr.asIterable()) -// .setFlag(flag) -// .setInt(int) -// .build() -// } -// -// fun generateJvExtendedMessage(): ExtendedMessage.Extended { -// val arrSize = RandomGen.rnd.nextInt(1000) -// val arr = LongArray(arrSize) -// for (i in 0..(arrSize - 1)) { -// arr[i] = RandomGen.rnd.nextLong() -// } -// -// val flag = if (RandomGen.rnd.nextInt() % 2 == 0) false else true -// -// val int = RandomGen.rnd.nextInt() -// -// val long = RandomGen.rnd.nextLong() -// -// val longsSize = RandomGen.rnd.nextInt(1000) -// val longs = LongArray(longsSize) -// for (i in 0..(longsSize - 1)) { -// longs[i] = RandomGen.rnd.nextLong() -// } -// -// return ExtendedMessage.Extended.newBuilder() -// .addAllArr(arr.asIterable()) -// .addAllArrLongs(longs.asIterable()) -// .setFlag(flag) -// .setInt(int) -// .setLong(long) -// .build() -// } -// -// fun compareBases(kt1: Base, jv: BaseMessage.Base): Boolean { -// return kt1.flag == jv.flag && -// kt1.int == jv.int && -// Util.compareArrays(kt1.arr.asIterable(), jv.arrList) -// } -// -// fun compareExtended(kt1: Extended, jv: ExtendedMessage.Extended): Boolean { -// return kt1.flag == jv.flag && -// kt1.int == jv.int && -// Util.compareArrays(kt1.arr.asIterable(), jv.arrList) && -// Util.compareArrays(kt1.arr_longs.asIterable(), jv.arrLongsList) && -// kt1.long == jv.long -// } -// -// fun compareBaseKtToJavaExtended(kt1: Base, jv: ExtendedMessage.Extended): Boolean { -// return kt1.flag == jv.flag && -// kt1.int == jv.int && -// Util.compareArrays(kt1.arr.asIterable(), jv.arrList) -// } -// -// fun compareExtendedKtToJavaBase(kt1: Extended, jv: BaseMessage.Base): Boolean { -// return kt1.flag == jv.flag && -// kt1.int == jv.int && -// Util.compareArrays(kt1.arr.asIterable(), jv.arrList) -// } -// -// fun baseKtToBaseJavaOnce() { -// val kt1 = generateKtBaseMessage() -// val outs = Util.getKtOutputStream(kt1.getSizeNoTag()) -// kt1.writeTo(outs) -// -// val ins = Util.KtOutputStreamToInputStream(outs) -// val jv = BaseMessage.Base.parseFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareBases(kt1, jv)) -// } -// -// fun baseJavaToBaseKtOnce() { -// val outs = ByteArrayOutputStream(100000) -// -// val jv = generateJvBaseMessage() -// jv.writeTo(outs) -// val ins = CodedInputStream(outs.toByteArray()) -// val kt1 = Base.BuilderBase(LongArray(0), false, 0).build() -// kt1.mergeFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareBases(kt1, jv)) -// } -// -// fun baseKtToExtendedJavaOnce() { -// val kt1 = generateKtBaseMessage() -// val outs = Util.getKtOutputStream(kt1.getSizeNoTag()) -// kt1.writeTo(outs) -// -// val ins = Util.KtOutputStreamToInputStream(outs) -// val jv = ExtendedMessage.Extended.parseFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareBaseKtToJavaExtended(kt1, jv)) -// } -// -// fun extendedJavaToBaseKtOnce() { -// val outs = ByteArrayOutputStream(100000) -// -// val jv = generateJvExtendedMessage() -// jv.writeTo(outs) -// -// val ins = CodedInputStream(outs.toByteArray()) -// -// val kt1 = Base.BuilderBase(LongArray(0), false, 0).build() -// kt1.mergeFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareBaseKtToJavaExtended(kt1, jv)) -// } -// -// fun extendedKtToBaseJavaOnce() { -// val kt1 = generateKtExtendedMessage() -// val outs = Util.getKtOutputStream(kt1.getSizeNoTag()) -// kt1.writeTo(outs) -// -// val ins = Util.KtOutputStreamToInputStream(outs) -// val jv = BaseMessage.Base.parseFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareExtendedKtToJavaBase(kt1, jv)) -// } -// -// fun baseJavaToExtendedKtOnce() { -// val outs = ByteArrayOutputStream(100000) -// -// val jv = generateJvBaseMessage() -// jv.writeTo(outs) -// -// val ins = CodedInputStream(outs.toByteArray()) -// -// val kt1 = Extended.BuilderExtended(LongArray(0), LongArray(0), false, 0L, 0).build() -// kt1.mergeFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareExtendedKtToJavaBase(kt1, jv)) -// } -// -// fun extendedKtToExtendedJavaOnce() { -// val kt1 = generateKtExtendedMessage() -// val outs = Util.getKtOutputStream(kt1.getSizeNoTag()) -// kt1.writeTo(outs) -// -// val ins = Util.KtOutputStreamToInputStream(outs) -// val jv = ExtendedMessage.Extended.parseFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareExtended(kt1, jv)) -// } -// -// fun extendedJavaToExtendedKtOnce() { -// val outs = ByteArrayOutputStream(100000) -// -// val jv = generateJvExtendedMessage() -// jv.writeTo(outs) -// val ins = CodedInputStream(outs.toByteArray()) -// val kt1 = Extended.BuilderExtended(LongArray(0), LongArray(0), false, 0L, 0).build() -// kt1.mergeFrom(ins) -// -// Util.assert(kt1.errorCode == 0) -// Util.assert(compareExtended(kt1, jv)) -// } -// -// val testRuns = 1000 -// fun runTests() { -// for (i in 0..testRuns) { -// // base - base -// baseJavaToBaseKtOnce() -// baseKtToBaseJavaOnce() -// -// // base - extended -// baseKtToExtendedJavaOnce() -// // extendedJavaToBaseKtOnce() - currently failing, proper parsing of unknown fields is needed. -// -// // extended - base -// baseJavaToExtendedKtOnce() -// extendedKtToBaseJavaOnce() -// -// // extended - extended -// extendedJavaToExtendedKtOnce() -// extendedKtToExtendedJavaOnce() -// } -// } -//} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/ConnectTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/ConnectTest.kt new file mode 100644 index 00000000000..22d374fab62 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/ConnectTest.kt @@ -0,0 +1,37 @@ +package tests + +import CodedInputStream +import ConnectionRequest + +object ConnectTest { + fun generateKotlinConnectionRequestMessage(): ConnectionRequest { + val arr = Util.generateIntArray() + val port = Util.nextInt() + return ConnectionRequest.BuilderConnectionRequest(arr, port).build() + } + + fun compareConnectionRequests(kt1: ConnectionRequest, kt2: ConnectionRequest): Boolean { + return Util.compareArrays(kt1.ip.asIterable(), kt2.ip.asIterable()) && + kt1.port == kt2.port + } + + fun ktToKtOnce() { + val msg = generateKotlinConnectionRequestMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = ConnectionRequest.BuilderConnectionRequest(IntArray(0), 0).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareConnectionRequests(msg, readMsg)) + } + + val testRuns = 1000 + + fun runTests() { + for (i in 0..testRuns) { + ktToKtOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/CrossBranchTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/CrossBranchTest.kt new file mode 100644 index 00000000000..a7fd3883c09 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/CrossBranchTest.kt @@ -0,0 +1,66 @@ +package tests + +import CodedInputStream +import CrossBranch + +object CrossBranchTest { + fun generateKtGrandFather(): CrossBranch.Grandfather { + fun generateKtRightFather(): CrossBranch.Grandfather.RightFather { + fun generateKtRightLeftSon(): CrossBranch.Grandfather.RightFather.RightLeftSon { + fun generateKtLeftLeftSon(): CrossBranch.Grandfather.LeftFather.LeftLeftSon { + return CrossBranch.Grandfather.LeftFather.LeftLeftSon.BuilderLeftLeftSon(Util.nextInt()).build() + } + + val msg = CrossBranch.Grandfather.RightFather.RightLeftSon.BuilderRightLeftSon( + generateKtLeftLeftSon() + ).build() + return msg + } + + fun generateKtRightRightSon(): CrossBranch.Grandfather.RightFather.RightRightSon { + fun generateKtLeftRightSon(): CrossBranch.Grandfather.LeftFather.LeftRightSon { + return CrossBranch.Grandfather.LeftFather.LeftRightSon.BuilderLeftRightSon(Util.nextInt()).build() + } + + return CrossBranch.Grandfather.RightFather.RightRightSon.BuilderRightRightSon( + generateKtLeftRightSon() + ).build() + } + + val msg = CrossBranch.Grandfather.RightFather.BuilderRightFather( + generateKtRightLeftSon(), + generateKtRightRightSon() + ).build() + + return msg + } + + return CrossBranch.Grandfather.BuilderGrandfather(generateKtRightFather()).build() + } + + fun compareGrandFathers(kt1: CrossBranch.Grandfather, kt2: CrossBranch.Grandfather): Boolean { + return kt1.rf.rls.son_field.son_field == kt2.rf.rls.son_field.son_field && + kt1.rf.rrs.son_field.son_field == kt2.rf.rrs.son_field.son_field + } + + val testRuns = 1000 + + fun ktToKtOnce() { + val msg = generateKtGrandFather() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = generateKtGrandFather() + readMsg.mergeFrom(ins) // caution: not correct in presence of repeated fields. In this particular case it's ok + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareGrandFathers(msg, readMsg)) + } + + fun runTests() { + for (i in 0..testRuns) { + ktToKtOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/LocationTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/LocationTest.kt new file mode 100644 index 00000000000..dec5577f8d5 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/LocationTest.kt @@ -0,0 +1,51 @@ +package tests + +import CodedInputStream +import LocationResponse + +object LocationTest { + fun generateKtLocationResponse(): LocationResponse { + fun generateKtLocationData(): LocationResponse.LocationData { + return LocationResponse.LocationData.BuilderLocationData( + Util.nextInt(), + Util.nextInt(), + Util.nextInt() + ).build() + } + + return LocationResponse.BuilderLocationResponse( + generateKtLocationData(), + Util.nextInt(), + Util.nextInt() + ).build() + } + + fun compareLocationResponses(kt1: LocationResponse, kt2: LocationResponse): Boolean { + fun compareLocationDatas(kt1: LocationResponse.LocationData, kt2: LocationResponse.LocationData): Boolean { + return kt1.x == kt2.x && kt1.y == kt2.y && kt1.angle == kt2.angle + } + + return kt1.code == kt2.code && compareLocationDatas(kt1.locationResponseData, kt2.locationResponseData) + } + + fun ktToKtOnce() { + val msg = generateKtLocationResponse() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = LocationResponse.BuilderLocationResponse(LocationResponse.LocationData.BuilderLocationData(0, 0, 0).build(), 0, 0).build() + readMsg.mergeFrom(ins) + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareLocationResponses(msg, readMsg)) + } + + val testRuns = 1000 + + fun runTests() { + for (i in 0..testRuns) { + ktToKtOnce() + } + } +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/MultipleMessagesTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/MultipleMessagesTest.kt new file mode 100644 index 00000000000..f2ef0d1d259 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/MultipleMessagesTest.kt @@ -0,0 +1,46 @@ +package tests + +import CodedInputStream +import FirstMessage +import SecondMessage +import ThirdMessage + +object MultipleMessagesTest { + fun generateKtFirstMessage(): FirstMessage { + return FirstMessage.BuilderFirstMessage(Util.nextInt()).build() + } + + fun generateKtSecondMessage(): SecondMessage { + return SecondMessage.BuilderSecondMessage(generateKtFirstMessage()).build() + } + + fun generateKtThirdMessage(): ThirdMessage { + return ThirdMessage.BuilderThirdMessage(generateKtSecondMessage()).build() + } + + fun compareThirdMessages(kt1: ThirdMessage, kt2: ThirdMessage): Boolean { + return kt1.second_msg.first_msg.int_field == kt2.second_msg.first_msg.int_field + } + + fun ktToKtOnce() { + val msg = generateKtThirdMessage() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = ThirdMessage.BuilderThirdMessage(SecondMessage.BuilderSecondMessage(FirstMessage.BuilderFirstMessage(0).build()).build()).build() + readMsg.mergeFrom(ins) + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareThirdMessages(msg, readMsg)) + } + + + val testRuns = 1000 + + fun runTests() { + for (i in 0..testRuns) { + ktToKtOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/RepeatedZigZagTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/RepeatedZigZagTest.kt new file mode 100644 index 00000000000..c7d559a6fd2 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/RepeatedZigZagTest.kt @@ -0,0 +1,36 @@ +package tests +import CodedInputStream +import MessageRepeatedZigZag + +object RepeatedZigZagTest { + fun generateKtRepeatedZigZag(): MessageRepeatedZigZag { + val int = Util.generateIntArray() + val long = Util.generateLongArray() + return MessageRepeatedZigZag.BuilderMessageRepeatedZigZag(int, long).build() + } + + fun compareRepeatedZigZags(kt1: MessageRepeatedZigZag, kt2: MessageRepeatedZigZag): Boolean { + return Util.compareArrays(kt1.int.asIterable(), kt2.int.asIterable()) && + Util.compareArrays(kt1.long.asIterable(), kt2.long.asIterable()) + } + + fun ktToKtOnce() { + val msg = generateKtRepeatedZigZag() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = MessageRepeatedZigZag.BuilderMessageRepeatedZigZag(IntArray(0), LongArray(0)).parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareRepeatedZigZags(msg, readMsg)) + } + + val testRuns = 1000 + + fun runTests() { + for (i in 0..testRuns) { + ktToKtOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/TagOrderTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/TagOrderTest.kt new file mode 100644 index 00000000000..479432c9408 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/TagOrderTest.kt @@ -0,0 +1,65 @@ +package tests + +import CodedInputStream +import TagOrder +import TagOrderShuffled + +object TagOrderTest { + fun generateKtTag(): TagOrder { + val int = Util.nextInt() + val slong_array = Util.generateLongArray() + val sint = Util.nextInt() + val enum = TagOrder.Enum.fromIntToEnum(Util.nextInt(2)) + return TagOrder.BuilderTagOrder(int, sint, slong_array, enum).build() + } + + fun generateKtTagShuffled(): TagOrderShuffled { + val int = Util.nextInt() + val slong_array = Util.generateLongArray() + val sint = Util.nextInt() + val enum = TagOrderShuffled.Enum.fromIntToEnum(Util.nextInt(2)) + + return TagOrderShuffled.BuilderTagOrderShuffled(int, sint, slong_array, enum).build() + } + + fun compareTagAndShuffledTag(kt1: TagOrder, kt2: TagOrderShuffled): Boolean { + return kt1.enum_field.id == kt2.enum_field.id && + kt1.int == kt2.int && + kt1.sint == kt2.sint && + Util.compareArrays(kt1.slong_array.asIterable(), kt2.slong_array.asIterable()) + } + + fun tagToShuffledOnce() { + val msg = generateKtTag() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = TagOrderShuffled.BuilderTagOrderShuffled(0, 0, LongArray(0), TagOrderShuffled.Enum.first_val) + .parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareTagAndShuffledTag(msg, readMsg)) + } + + fun shuffledToTagOnce() { + val msg = generateKtTagShuffled() + val outs = Util.getKtOutputStream(msg.getSizeNoTag()) + msg.writeTo(outs) + + val ins = CodedInputStream(outs.buffer) + val readMsg = TagOrder.BuilderTagOrder(0, 0, LongArray(0), TagOrder.Enum.first_val) + .parseFrom(ins).build() + + Util.assert(readMsg.errorCode == 0) + Util.assert(compareTagAndShuffledTag(readMsg, msg)) + } + + val testRuns = 1000 + fun runTests() { + for (i in 0..testRuns) { + tagToShuffledOnce() + shuffledToTagOnce() + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/VarintsTest.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/VarintsTest.kt index d39b6f56341..290f0597513 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/VarintsTest.kt +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/VarintsTest.kt @@ -19,14 +19,14 @@ object VarintsTest { } fun compareVarints(kt1: MessageVarints, kt2: MessageVarints): Boolean { - return kt1.int == kt2.int //&& -// kt1.long.toString() == kt2.long.toString() && -// kt1.sint == kt2.sint && -// kt1.slong.toString() == kt2.slong.toString() && -// kt1.bl == kt2.bl && -// kt1.uint == kt2.uint && -// kt1.ulong.toString() == kt2.ulong.toString() && -// kt1.enumField.id == kt2.enumField.id + return kt1.int == kt2.int && + kt1.long.toString() == kt2.long.toString() && + kt1.sint == kt2.sint && + kt1.slong.toString() == kt2.slong.toString() && + kt1.bl == kt2.bl && + kt1.uint == kt2.uint && + kt1.ulong.toString() == kt2.ulong.toString() && + kt1.enumField.id == kt2.enumField.id } fun ktToKtOnce() { diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/main.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/main.kt index 48ac13716d3..4691afce092 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/main.kt +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc-tests/kt_js_tests/src/tests/main.kt @@ -12,4 +12,28 @@ fun main(args: Array) { print("Repeated VarInts test... ") RepeatedVarintsTest.runTests() println("OK!") + + print("Repeated ZigZags test... ") + RepeatedZigZagTest.runTests() + println("OK!") + + print("Tag order test... ") + TagOrderTest.runTests() + println("OK!") + + print("Cross-branch access test... ") + CrossBranchTest.runTests() + println("OK!") + + print("Location.proto test... ") + LocationTest.runTests() + println("OK!") + + print("Connect.proto test... ") + ConnectTest.runTests() + println("OK!") + + print("Base & Extended test... ") + BaseExtendedTest.runTests() + println("OK!") } \ No newline at end of file