aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
diff options
context:
space:
mode:
authorJan Tattermusch <jtattermusch@users.noreply.github.com>2016-01-12 20:55:47 -0800
committerJan Tattermusch <jtattermusch@users.noreply.github.com>2016-01-12 20:55:47 -0800
commit73c003c309235485c0e53f2075242567c88a72bc (patch)
tree6cebc5a786a171f341e386a567e9d058354d5c24 /csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
parent937ef23acd2cb7554224b4f9cc33c436e54bddf1 (diff)
parent9e4f354f14775061ed098c896170d3a2d01a3895 (diff)
downloadprotobuf-73c003c309235485c0e53f2075242567c88a72bc.tar.gz
protobuf-73c003c309235485c0e53f2075242567c88a72bc.tar.bz2
protobuf-73c003c309235485c0e53f2075242567c88a72bc.zip
Merge pull request #1089 from jskeet/map-null
Prohibit null values in maps
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs36
1 files changed, 35 insertions, 1 deletions
diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
index 1163f524..cda7f885 100644
--- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
+++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
@@ -221,7 +221,7 @@ namespace Google.Protobuf
},
MapInt32ForeignMessage = {
{ 0, new ForeignMessage { C = 10 } },
- { 5, null },
+ { 5, new ForeignMessage() },
},
MapInt32Enum = {
{ 1, MapEnum.MAP_ENUM_BAR },
@@ -269,6 +269,40 @@ namespace Google.Protobuf
}
[Test]
+ public void MapWithOnlyKey_PrimitiveValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32DoubleFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(0.0, parsed.MapInt32Double[key]);
+ }
+
+ [Test]
+ public void MapWithOnlyKey_MessageValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(new ForeignMessage(), parsed.MapInt32ForeignMessage[key]);
+ }
+
+ [Test]
public void MapIgnoresExtraFieldsWithinEntryMessages()
{
// Hand-craft the stream to contain a single entry with three fields