Skip to content

Commit efea40a

Browse files
committed
protobuf: Add oneof groups test
Signed-off-by: Johannes Zottele <[email protected]>
1 parent c71fb2d commit efea40a

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

protobuf/protobuf-core/src/commonTest/kotlin/kotlinx/rpc/protobuf/test/ProtosTest.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import OneOfMsgInternal
99
import OneOfWithRequired
1010
import Outer
1111
import OuterInternal
12-
import WithGroups
13-
import WithGroupsInternal
1412
import asInternal
1513
import encodeWith
1614
import invoke
@@ -20,6 +18,9 @@ import kotlinx.rpc.protobuf.input.stream.asInputStream
2018
import kotlinx.rpc.protobuf.input.stream.asSource
2119
import kotlinx.rpc.protobuf.internal.ProtobufDecodingException
2220
import kotlinx.rpc.protobuf.internal.WireEncoder
21+
import test.groups.WithGroups
22+
import test.groups.WithGroupsInternal
23+
import test.groups.invoke
2324
import test.nested.NestedOuter
2425
import test.nested.NestedOuterInternal
2526
import test.nested.NotInside
@@ -436,12 +437,20 @@ class ProtosTest {
436437
value = "Second Item"
437438
}
438439
)
440+
oneOfWithGroup = WithGroups.OneOfWithGroup.Testgroup(WithGroups.TestGroup {
441+
value = 42u
442+
})
439443
}
440444

441445
val decoded = encodeDecode(msg, WithGroupsInternal.CODEC)
442446
assertEquals(msg.firstgroup.value, decoded.firstgroup.value)
443447
for ((i, group) in msg.secondgroup.withIndex()) {
444448
assertEquals(group.value, decoded.secondgroup[i].value)
445449
}
450+
assertTrue(decoded.oneOfWithGroup is WithGroups.OneOfWithGroup.Testgroup)
451+
assertEquals(
452+
(msg.oneOfWithGroup as WithGroups.OneOfWithGroup.Testgroup).value.value,
453+
(decoded.oneOfWithGroup as WithGroups.OneOfWithGroup.Testgroup).value.value
454+
)
446455
}
447456
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package test.groups;
2+
13
message WithGroups {
24
required group FirstGroup = 1 {
35
required fixed32 value = 2;
@@ -7,9 +9,10 @@ message WithGroups {
79
required string value = 2;
810
}
911

10-
// oneof test {
11-
// group TestGroup = 3 {
12-
// required fixed32 value = 2;
13-
// }
14-
// }
12+
oneof oneOfWithGroup {
13+
int32 anInt32 = 4;
14+
group TestGroup = 3 {
15+
required fixed32 value = 2;
16+
}
17+
}
1518
}

0 commit comments

Comments
 (0)