aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-08-04 11:26:48 +0100
committerJon Skeet <jonskeet@google.com>2015-08-05 07:09:41 +0100
commit9df2defa295e1a3b315ed2a88791db51ff1f53e7 (patch)
tree5a0b130c7e82321c99954c4e86e29983e88d3bb6 /csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
parentb6defa7c115a19d3671b2a6c5ebab2a471d273ea (diff)
downloadprotobuf-9df2defa295e1a3b315ed2a88791db51ff1f53e7.tar.gz
protobuf-9df2defa295e1a3b315ed2a88791db51ff1f53e7.tar.bz2
protobuf-9df2defa295e1a3b315ed2a88791db51ff1f53e7.zip
Consume unknown fields when parsing.
This is expected to be the cause of the conformance test failures. Generated code in next commit.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
index 2b6265c1..1ef3d753 100644
--- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
+++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
@@ -36,6 +36,8 @@ using Google.Protobuf.TestProtos;
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
+using Google.Protobuf.WellKnownTypes;
namespace Google.Protobuf
{
@@ -590,5 +592,32 @@ namespace Google.Protobuf
Assert.AreEqual(message, message2);
Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
}
+
+ [Test]
+ public void IgnoreUnknownFields_RealDataStillRead()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var unusedFieldNumber = 23456;
+ Assert.IsFalse(TestAllTypes.Descriptor.Fields.InDeclarationOrder().Select(x => x.FieldNumber).Contains(unusedFieldNumber));
+ output.WriteTag(unusedFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteString("ignore me");
+ message.WriteTo(output);
+ output.Flush();
+
+ stream.Position = 0;
+ var parsed = TestAllTypes.Parser.ParseFrom(stream);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void IgnoreUnknownFields_AllTypes()
+ {
+ // Simple way of ensuring we can skip all kinds of fields.
+ var data = SampleMessages.CreateFullTestAllTypes().ToByteArray();
+ var empty = Empty.Parser.ParseFrom(data);
+ Assert.AreEqual(new Empty(), empty);
+ }
}
}