Skip to content

Commit bc516ef

Browse files
committed
Support repeated entries in byte arrays: failing test
1 parent 47ff61c commit bc516ef

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/java/interop/interop_test.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ message InteropBoxOneOf {
5555
sint32 f = 6;
5656
}
5757
}
58+
59+
message SubInteropRepeatedUint {
60+
repeated uint32 repeated_values = 1 [packed = true];
61+
}
62+
63+
message InteropRepeatedUint {
64+
optional SubInteropRepeatedUint sub_message = 1;
65+
}

wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/kotlin/interop/interop_test.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ message InteropBoxOneOf {
5555
sint32 f = 6;
5656
}
5757
}
58+
59+
message SubInteropRepeatedUint {
60+
repeated uint32 repeated_values = 1 [packed = true];
61+
}
62+
63+
message InteropRepeatedUint {
64+
optional SubInteropRepeatedUint sub_message = 1;
65+
}
66+

wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto2WireProtocCompatibilityTests.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import okio.ByteString.Companion.decodeHex
2727
import org.junit.Test
2828
import squareup.proto2.java.empty.EmptyLength as EmptyLengthJ
2929
import squareup.proto2.java.interop.InteropMessage as InteropMessageJ
30+
import squareup.proto2.java.interop.InteropRepeatedUint as InteropRepeatedUintJ2
31+
import squareup.proto2.java.interop.InteropTest.InteropRepeatedUint as InteropRepeatedUintP2
32+
import squareup.proto2.java.interop.InteropTest.SubInteropRepeatedUint as SubInteropRepeatedUintP2
33+
import squareup.proto2.java.interop.SubInteropRepeatedUint as SubInteropRepeatedUintJ2
3034
import squareup.proto2.java.interop.type.EnumProto2 as EnumProto2J
3135
import squareup.proto2.java.interop.type.MessageProto2 as MessageProto2J
3236
import squareup.proto2.kotlin.MapTypes
@@ -49,10 +53,12 @@ import squareup.proto2.kotlin.interop.InteropMessageOuterClass.extRepProto2Enum
4953
import squareup.proto2.kotlin.interop.InteropMessageOuterClass.extRepProto2Message
5054
import squareup.proto2.kotlin.interop.InteropMessageOuterClass.extRepProto3Enum
5155
import squareup.proto2.kotlin.interop.InteropMessageOuterClass.extRepProto3Message
56+
import squareup.proto2.kotlin.interop.InteropRepeatedUint as InteropRepeatedUintK2
5257
import squareup.proto2.kotlin.interop.Quilt
5358
import squareup.proto2.kotlin.interop.QuiltColor
5459
import squareup.proto2.kotlin.interop.QuiltContainer
5560
import squareup.proto2.kotlin.interop.RepeatedEnum
61+
import squareup.proto2.kotlin.interop.SubInteropRepeatedUint as SubInteropRepeatedUintK2
5662
import squareup.proto2.kotlin.interop.type.EnumProto2 as EnumProto2K
5763
import squareup.proto2.kotlin.interop.type.InteropTypes.EnumProto2
5864
import squareup.proto2.kotlin.interop.type.InteropTypes.MessageProto2
@@ -183,6 +189,35 @@ class Proto2WireProtocCompatibilityTests {
183189
assertThat(mapTypeWire.map_string_string[""]).isEqualTo("ed")
184190
}
185191

192+
@Test fun decodingRepeatedEntries() {
193+
// ── 1 ┐
194+
// ├─ 1: 1
195+
// ╰- 1: 1
196+
val byteArray = byteArrayOf(10, 3, 10, 1, 1, 10, 3, 10, 1, 1)
197+
assertThat(InteropRepeatedUintP2.parseFrom(byteArray))
198+
.isEqualTo(
199+
InteropRepeatedUintP2.newBuilder()
200+
.setSubMessage(
201+
SubInteropRepeatedUintP2.newBuilder().addAllRepeatedValues(listOf(1, 1)).build(),
202+
)
203+
.build(),
204+
)
205+
assertThat(InteropRepeatedUintJ2.ADAPTER.decode(byteArray)).isEqualTo(
206+
InteropRepeatedUintJ2.Builder()
207+
.sub_message(
208+
SubInteropRepeatedUintJ2.Builder().repeated_values(listOf(1, 1)).build(),
209+
)
210+
.build(),
211+
)
212+
assertThat(InteropRepeatedUintK2.ADAPTER.decode(byteArray)).isEqualTo(
213+
InteropRepeatedUintK2.Builder()
214+
.sub_message(
215+
SubInteropRepeatedUintK2.Builder().repeated_values(listOf(1, 1)).build(),
216+
)
217+
.build(),
218+
)
219+
}
220+
186221
/**
187222
* The TS-proto library encodes enums differently from Wire or Protoc. Protoc is fine with this,
188223
* but it causes Wire to crash. The fix is to make Wire accept this format also.

0 commit comments

Comments
 (0)