diff options
author | Jon Skeet <skeet@pobox.com> | 2009-02-18 16:06:22 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2009-02-18 16:06:22 +0000 |
commit | 25a28580a6f307cb8eb040367f5671e678e9896b (patch) | |
tree | 6ce918e09f644733ad514eac706208be2d5f7883 /src/ProtocolBuffers.Test/WireFormatTest.cs | |
parent | 0ca3fecfafe6b2f7b6de4a5e1b978353fcaae83b (diff) | |
download | protobuf-25a28580a6f307cb8eb040367f5671e678e9896b.tar.gz protobuf-25a28580a6f307cb8eb040367f5671e678e9896b.tar.bz2 protobuf-25a28580a6f307cb8eb040367f5671e678e9896b.zip |
Support packed primitive types
Diffstat (limited to 'src/ProtocolBuffers.Test/WireFormatTest.cs')
-rw-r--r-- | src/ProtocolBuffers.Test/WireFormatTest.cs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/ProtocolBuffers.Test/WireFormatTest.cs b/src/ProtocolBuffers.Test/WireFormatTest.cs index 891cf357..b519d7a7 100644 --- a/src/ProtocolBuffers.Test/WireFormatTest.cs +++ b/src/ProtocolBuffers.Test/WireFormatTest.cs @@ -63,11 +63,19 @@ namespace Google.ProtocolBuffers { } [Test] + public void SerializationPacked() { + TestPackedTypes message = TestUtil.GetPackedSet(); + ByteString rawBytes = message.ToByteString(); + Assert.AreEqual(rawBytes.Length, message.SerializedSize); + TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes); + TestUtil.AssertPackedFieldsSet(message2); + } + + [Test] public void SerializeExtensions() { // TestAllTypes and TestAllExtensions should have compatible wire formats, - // so if we serealize a TestAllExtensions then parse it as TestAllTypes + // so if we serialize a TestAllExtensions then parse it as TestAllTypes // it should work. - TestAllExtensions message = TestUtil.GetAllExtensionsSet(); ByteString rawBytes = message.ToByteString(); Assert.AreEqual(rawBytes.Length, message.SerializedSize); @@ -78,6 +86,19 @@ namespace Google.ProtocolBuffers { } [Test] + public void SerializePackedExtensions() { + // TestPackedTypes and TestPackedExtensions should have compatible wire + // formats; check that they serialize to the same string. + TestPackedExtensions message = TestUtil.GetPackedExtensionsSet(); + ByteString rawBytes = message.ToByteString(); + + TestPackedTypes message2 = TestUtil.GetPackedSet(); + ByteString rawBytes2 = message2.ToByteString(); + + Assert.AreEqual(rawBytes, rawBytes2); + } + + [Test] public void ParseExtensions() { // TestAllTypes and TestAllExtensions should have compatible wire formats, // so if we serealize a TestAllTypes then parse it as TestAllExtensions @@ -90,13 +111,24 @@ namespace Google.ProtocolBuffers { TestUtil.RegisterAllExtensions(registry); registry = registry.AsReadOnly(); - TestAllExtensions message2 = - TestAllExtensions.ParseFrom(rawBytes, registry); + TestAllExtensions message2 = TestAllExtensions.ParseFrom(rawBytes, registry); TestUtil.AssertAllExtensionsSet(message2); } [Test] + public void ParsePackedExtensions() { + // Ensure that packed extensions can be properly parsed. + TestPackedExtensions message = TestUtil.GetPackedExtensionsSet(); + ByteString rawBytes = message.ToByteString(); + + ExtensionRegistry registry = TestUtil.CreateExtensionRegistry(); + + TestPackedExtensions message2 = TestPackedExtensions.ParseFrom(rawBytes, registry); + TestUtil.AssertPackedExtensionsSet(message2); + } + + [Test] public void ExtensionsSerializedSize() { Assert.AreEqual(TestUtil.GetAllSet().SerializedSize, TestUtil.GetAllExtensionsSet().SerializedSize); } |