1 /* 2 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 package kotlinx.serialization.protobuf 5 6 import kotlinx.serialization.* 7 import kotlin.test.* 8 9 /* 10 * TODO improve these tests: 11 * * All primitive types 12 * * All nullable types 13 * * Built-in types (TBD) 14 * * Primitives nullability 15 */ 16 class ProtobufPrimitiveWrappersTest { 17 18 @Test testSignedIntegernull19 fun testSignedInteger() { 20 assertSerializedToBinaryAndRestored(TestInt(-150), TestInt.serializer(), ProtoBuf, hexResultToCheck = "08AB02") 21 } 22 23 @Test testIntListnull24 fun testIntList() { 25 assertSerializedToBinaryAndRestored( 26 TestList(listOf(1, 2, 3)), 27 TestList.serializer(), ProtoBuf, hexResultToCheck = "080108020803" 28 ) 29 } 30 31 @Test testStringnull32 fun testString() { 33 assertSerializedToBinaryAndRestored( 34 TestString("testing"), 35 TestString.serializer(), ProtoBuf, hexResultToCheck = "120774657374696E67" 36 ) 37 } 38 39 @Test testTwiceNestednull40 fun testTwiceNested() { 41 assertSerializedToBinaryAndRestored( 42 TestInner(TestInt(-150)), 43 TestInner.serializer(), ProtoBuf, hexResultToCheck = "1A0308AB02" 44 ) 45 } 46 47 @Test testMixedTagsnull48 fun testMixedTags() { 49 assertSerializedToBinaryAndRestored( 50 TestComplex(42, "testing"), 51 TestComplex.serializer(), ProtoBuf, hexResultToCheck = "D0022A120774657374696E67" 52 ) 53 } 54 55 @Test testDefaultPrimitiveValuesnull56 fun testDefaultPrimitiveValues() { 57 assertSerializedToBinaryAndRestored(TestInt(0), TestInt.serializer(), ProtoBuf, hexResultToCheck = "0800") 58 assertSerializedToBinaryAndRestored(TestList(listOf()), TestList.serializer(), ProtoBuf, hexResultToCheck = "") 59 assertSerializedToBinaryAndRestored( 60 TestString(""), 61 TestString.serializer(), ProtoBuf, hexResultToCheck = "1200" 62 ) 63 } 64 65 @Test testFixedIntWithLongnull66 fun testFixedIntWithLong() { 67 assertSerializedToBinaryAndRestored( 68 TestNumbers(100500, Long.MAX_VALUE), 69 TestNumbers.serializer(), ProtoBuf, hexResultToCheck = "0D9488010010FFFFFFFFFFFFFFFF7F" 70 ) 71 } 72 } 73