You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertFailsWith(SerializationException::class) { ProtoBuf.encodeToByteArray(NullableMapKey(mapOf(null to 42))) }
33
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of a list element in ProtoBuf") { ProtoBuf.encodeToByteArray(NullableListElement(listOf(null))) }
36
34
}
37
35
38
36
@Test
@@ -54,15 +52,46 @@ class ProtobufCollectionsTest {
54
52
}
55
53
56
54
@Test
57
-
funtestEncodeNullAsMapValue() {
58
-
assertFailsWith(SerializationException::class) { ProtoBuf.encodeToByteArray(NullableMapValue(mapOf(42 to null))) }
55
+
funtestNullMap() {
56
+
val keyNull =NullableMap(mapOf(null to 42))
57
+
val valueNull =NullableMap(mapOf(42 to null))
58
+
val bothNull =NullableMap(mapOf(null to null))
59
+
60
+
val encodedKeyNull =ProtoBuf.encodeToHexString(keyNull)
61
+
val encodedValueNull =ProtoBuf.encodeToHexString(valueNull)
62
+
val encodedBothNull =ProtoBuf.encodeToHexString(bothNull)
63
+
assertEquals(encodedKeyNull, "0a02102a")
64
+
assertEquals(encodedValueNull, "0a02082a")
65
+
assertEquals(encodedBothNull, "0a00")
66
+
67
+
val decodedKeyNull =ProtoBuf.decodeFromHexString<NullableMap>(encodedKeyNull)
68
+
val decodedValueNull =ProtoBuf.decodeFromHexString<NullableMap>(encodedValueNull)
69
+
val decodedBothNull =ProtoBuf.decodeFromHexString<NullableMap>(encodedBothNull)
70
+
assertEquals(decodedKeyNull, keyNull)
71
+
assertEquals(decodedValueNull, valueNull)
72
+
assertEquals(decodedBothNull, bothNull)
73
+
}
74
+
75
+
@Test
76
+
funtestRepeatNullKeyInMap() {
77
+
// there are two entries in message: (null to 42) and (null to 43), the last one is used
78
+
val decoded =ProtoBuf.decodeFromHexString<NullableMap>("0a04102a102b")
79
+
assertEquals(NullableMap(mapOf(null to 43)), decoded)
80
+
}
81
+
82
+
@Test
83
+
funtestCollectionsInNullableMap() {
84
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(null to listOf(42))) ) }
85
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(listOf(42) to null)) ) }
86
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedMaps(mapOf(null to mapOf("key" to 42))) ) }
87
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedMaps(mapOf(mapOf("key" to 42) to null)) ) }
59
88
}
60
89
61
90
@Test
62
91
funtestEncodeMapWithNullableValue() {
63
-
val map =NullableMapValue(mapOf(42 to 43))
92
+
val map =NullableMap(mapOf(42 to 43))
64
93
val bytes =ProtoBuf.encodeToByteArray(map)
65
-
val decoded =ProtoBuf.decodeFromByteArray<NullableMapValue>(bytes)
94
+
val decoded =ProtoBuf.decodeFromByteArray<NullableMap>(bytes)
66
95
assertEquals(map, decoded)
67
96
}
68
97
@@ -76,7 +105,9 @@ class ProtobufCollectionsTest {
@@ -97,8 +128,8 @@ class ProtobufCollectionsTest {
97
128
98
129
@Test
99
130
funtestNestedListsAreNullInMap() {
100
-
assertFailsWith(SerializationException::class) { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(null to emptyList()))) }
101
-
assertFailsWith(SerializationException::class) { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(emptyList<Int>() to null))) }
102
-
assertFailsWith(SerializationException::class) { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(null to null))) }
131
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(null to emptyList()))) }
132
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(emptyList<Int>() to null))) }
133
+
assertFailsWithMessage<SerializationException> ("'null' is not supported as the value of collection types in ProtoBuf") { ProtoBuf.encodeToByteArray(MapWithNullableNestedLists(mapOf(null to null))) }
0 commit comments