1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.protobuf
import kotlinx.serialization.loads
import kotlinx.serialization.test.isNative
import kotlinx.serialization.test.shouldBe
import kotlin.test.Ignore
import kotlin.test.Test
class ProtobufReaderTest {
@Test
fun readSimpleObject() {
ProtoBuf.loads<TestInt>(TestInt.serializer(), "08ab02") shouldBe t1
}
@Test
fun readObjectWithString() {
ProtoBuf.loads<TestString>(TestString.serializer(), "120774657374696E67") shouldBe t3
}
@Test
fun readObjectWithList() {
ProtoBuf.loads<TestList>(TestList.serializer(), "08960108E40108B90A") shouldBe t2
}
@Test
fun readInnerObject() {
ProtoBuf.loads<TestInner>(TestInner.serializer(), "1a0308ab02") shouldBe t4
}
@Test
fun readObjectWithUnorderedTags() {
ProtoBuf.loads<TestComplex>(TestComplex.serializer(), "120774657374696E67D0022A") shouldBe t5
}
@Test
fun readObjectsWithEmptyValues() {
ProtoBuf.loads<TestInt>(TestInt.serializer(), "0800") shouldBe t1e
ProtoBuf.loads<TestList>(TestList.serializer(), "") shouldBe t2e
ProtoBuf.loads<TestString>(TestString.serializer(), "1200") shouldBe t3e
}
@Test
fun readObjectWithUnknownFields() {
ProtoBuf.loads<TestInt>(TestInt.serializer(), "08960108E40108B90A08ab02120774657374696E67") shouldBe t1
}
@Test
fun readNumbers() {
ProtoBuf.loads<TestNumbers>(TestNumbers.serializer(), "0d9488010010ffffffffffffffff7f") shouldBe t6
}
@Test
fun mergeListIfSplitByAnotherField() {
if (isNative()) return // todo: support update on Native
ProtoBuf.loads<TestIntWithList>(TestIntWithList.serializer(), "500308960150045005") shouldBe TestIntWithList(150, listOf(3, 4, 5))
}
}
|