From b5ba93bf3c24b6c10468d98df3d1fb7f5cd2b3a0 Mon Sep 17 00:00:00 2001 From: csharptest Date: Thu, 14 Jul 2011 13:40:09 -0500 Subject: [PATCH] Integrated feedback from revision c97eeb8d933f --- protos/extest/unittest_extras_xmltest.proto | 2 -- .../BinaryCompatibilityTests.cs | 4 +-- .../CompatibilityTests.cs | 23 +++++++++++------- .../DictionaryCompatibilityTests.cs | 4 +-- .../JsonCompatibilityTests.cs | 4 +-- .../TestResources.Designer.cs | 6 ++--- .../TestResources.resx | 0 .../TextCompatibilityTests.cs | 4 +-- .../XmlCompatibilityTests.cs | 4 +-- .../google_message1.dat | Bin .../google_message2.dat | Bin .../ProtocolBuffers.Test.csproj | 20 +++++++-------- src/ProtocolBuffers/ExtensionRegistryLite.cs | 12 +++------ 13 files changed, 40 insertions(+), 43 deletions(-) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/BinaryCompatibilityTests.cs (66%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/CompatibilityTests.cs (79%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/DictionaryCompatibilityTests.cs (83%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/JsonCompatibilityTests.cs (75%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/TestResources.Designer.cs (92%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/TestResources.resx (100%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/TextCompatibilityTests.cs (81%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/XmlCompatibilityTests.cs (77%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/google_message1.dat (100%) rename src/ProtocolBuffers.Test/{CompatTests => Compatibility}/google_message2.dat (100%) diff --git a/protos/extest/unittest_extras_xmltest.proto b/protos/extest/unittest_extras_xmltest.proto index 331c6265f4..f00fb02780 100644 --- a/protos/extest/unittest_extras_xmltest.proto +++ b/protos/extest/unittest_extras_xmltest.proto @@ -1,5 +1,3 @@ -// Additional options required for C# generation. File from copyright -// line onwards is as per original distribution. import "google/protobuf/csharp_options.proto"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile"; diff --git a/src/ProtocolBuffers.Test/CompatTests/BinaryCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs similarity index 66% rename from src/ProtocolBuffers.Test/CompatTests/BinaryCompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs index c5b78bc975..e993efad6c 100644 --- a/src/ProtocolBuffers.Test/CompatTests/BinaryCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs @@ -1,7 +1,7 @@ using System; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { [TestFixture] public class BinaryCompatibilityTests : CompatibilityTests @@ -12,7 +12,7 @@ namespace Google.ProtocolBuffers.CompatTests return bresult; } - protected override TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected override TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) { return builder.MergeFrom((byte[])message, registry); } diff --git a/src/ProtocolBuffers.Test/CompatTests/CompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs similarity index 79% rename from src/ProtocolBuffers.Test/CompatTests/CompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs index 3f3d62cd2c..9b117f6f61 100644 --- a/src/ProtocolBuffers.Test/CompatTests/CompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs @@ -2,15 +2,20 @@ using Google.ProtocolBuffers.TestProtos; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { + /// + /// This abstract base implements several tests to ensure that well-known messages can be written + /// and read to/from various formats without loosing data. Implementations overload the two serailization + /// methods to provide the tests with the means to read and write for a given format. + /// public abstract class CompatibilityTests { protected abstract object SerializeMessage(TMessage message) where TMessage : IMessageLite where TBuilder : IBuilderLite; - protected abstract TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected abstract TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) where TMessage : IMessageLite where TBuilder : IBuilderLite; @@ -25,7 +30,7 @@ namespace Google.ProtocolBuffers.CompatTests SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build(); object content = SerializeMessage(msg); - SizeMessage1 copy = DeerializeMessage(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); + SizeMessage1 copy = DeserializeMessage(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -38,7 +43,7 @@ namespace Google.ProtocolBuffers.CompatTests SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build(); object content = SerializeMessage(msg); - SizeMessage2 copy = DeerializeMessage(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); + SizeMessage2 copy = DeserializeMessage(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -51,7 +56,7 @@ namespace Google.ProtocolBuffers.CompatTests SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build(); object content = SerializeMessage(msg); - SpeedMessage1 copy = DeerializeMessage(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); + SpeedMessage1 copy = DeserializeMessage(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -64,7 +69,7 @@ namespace Google.ProtocolBuffers.CompatTests SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build(); object content = SerializeMessage(msg); - SpeedMessage2 copy = DeerializeMessage(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); + SpeedMessage2 copy = DeserializeMessage(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -151,7 +156,7 @@ namespace Google.ProtocolBuffers.CompatTests TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build(); object content = SerializeMessage(msg); - TestAllTypes copy = DeerializeMessage(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); + TestAllTypes copy = DeserializeMessage(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -164,7 +169,7 @@ namespace Google.ProtocolBuffers.CompatTests TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build(); object content = SerializeMessage(msg); - TestAllTypes copy = DeerializeMessage(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); + TestAllTypes copy = DeserializeMessage(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); @@ -177,7 +182,7 @@ namespace Google.ProtocolBuffers.CompatTests TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build(); object content = SerializeMessage(msg); - TestPackedTypes copy = DeerializeMessage(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); + TestPackedTypes copy = DeserializeMessage(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); Assert.AreEqual(msg, copy); AssertOutputEquals(content, SerializeMessage(copy)); diff --git a/src/ProtocolBuffers.Test/CompatTests/DictionaryCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs similarity index 83% rename from src/ProtocolBuffers.Test/CompatTests/DictionaryCompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs index 8de82ea92d..188c5bc314 100644 --- a/src/ProtocolBuffers.Test/CompatTests/DictionaryCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs @@ -5,7 +5,7 @@ using System.Text; using Google.ProtocolBuffers.Serialization; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { [TestFixture] public class DictionaryCompatibilityTests : CompatibilityTests @@ -17,7 +17,7 @@ namespace Google.ProtocolBuffers.CompatTests return writer.ToDictionary(); } - protected override TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected override TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) { new DictionaryReader((IDictionary)message).Merge(builder); return builder; diff --git a/src/ProtocolBuffers.Test/CompatTests/JsonCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs similarity index 75% rename from src/ProtocolBuffers.Test/CompatTests/JsonCompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs index 23fa26386e..fb89504064 100644 --- a/src/ProtocolBuffers.Test/CompatTests/JsonCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs @@ -3,7 +3,7 @@ using System.Text; using Google.ProtocolBuffers.Serialization; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { [TestFixture] public class JsonCompatibilityTests : CompatibilityTests @@ -17,7 +17,7 @@ namespace Google.ProtocolBuffers.CompatTests return sw.ToString(); } - protected override TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected override TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) { JsonFormatReader.CreateInstance((string)message).Merge(builder); return builder; diff --git a/src/ProtocolBuffers.Test/CompatTests/TestResources.Designer.cs b/src/ProtocolBuffers.Test/Compatibility/TestResources.Designer.cs similarity index 92% rename from src/ProtocolBuffers.Test/CompatTests/TestResources.Designer.cs rename to src/ProtocolBuffers.Test/Compatibility/TestResources.Designer.cs index 8565ee80dd..1441cf39e3 100644 --- a/src/ProtocolBuffers.Test/CompatTests/TestResources.Designer.cs +++ b/src/ProtocolBuffers.Test/Compatibility/TestResources.Designer.cs @@ -1,14 +1,14 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.5444 +// Runtime Version:2.0.50727.5446 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ -namespace Google.ProtocolBuffers.CompatTests { +namespace Google.ProtocolBuffers.Compatibility { using System; @@ -39,7 +39,7 @@ namespace Google.ProtocolBuffers.CompatTests { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Google.ProtocolBuffers.CompatTests.TestResources", typeof(TestResources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Google.ProtocolBuffers.Compatibility.TestResources", typeof(TestResources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/ProtocolBuffers.Test/CompatTests/TestResources.resx b/src/ProtocolBuffers.Test/Compatibility/TestResources.resx similarity index 100% rename from src/ProtocolBuffers.Test/CompatTests/TestResources.resx rename to src/ProtocolBuffers.Test/Compatibility/TestResources.resx diff --git a/src/ProtocolBuffers.Test/CompatTests/TextCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs similarity index 81% rename from src/ProtocolBuffers.Test/CompatTests/TextCompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs index 0b575358b4..defec28e2f 100644 --- a/src/ProtocolBuffers.Test/CompatTests/TextCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs @@ -2,7 +2,7 @@ using System.ComponentModel; using System.IO; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { [TestFixture] public class TextCompatibilityTests : CompatibilityTests @@ -14,7 +14,7 @@ namespace Google.ProtocolBuffers.CompatTests return text.ToString(); } - protected override TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected override TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) { TextFormat.Merge(new StringReader((string)message), registry, (IBuilder)builder); return builder; diff --git a/src/ProtocolBuffers.Test/CompatTests/XmlCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs similarity index 77% rename from src/ProtocolBuffers.Test/CompatTests/XmlCompatibilityTests.cs rename to src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs index b7cfca6a1e..50ef6f0305 100644 --- a/src/ProtocolBuffers.Test/CompatTests/XmlCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs @@ -3,7 +3,7 @@ using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.TestProtos; using NUnit.Framework; -namespace Google.ProtocolBuffers.CompatTests +namespace Google.ProtocolBuffers.Compatibility { [TestFixture] public class XmlCompatibilityTests : CompatibilityTests @@ -16,7 +16,7 @@ namespace Google.ProtocolBuffers.CompatTests return text.ToString(); } - protected override TBuilder DeerializeMessage(object message, TBuilder builder, ExtensionRegistry registry) + protected override TBuilder DeserializeMessage(object message, TBuilder builder, ExtensionRegistry registry) { XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message); return reader.Merge("root", builder, registry); diff --git a/src/ProtocolBuffers.Test/CompatTests/google_message1.dat b/src/ProtocolBuffers.Test/Compatibility/google_message1.dat similarity index 100% rename from src/ProtocolBuffers.Test/CompatTests/google_message1.dat rename to src/ProtocolBuffers.Test/Compatibility/google_message1.dat diff --git a/src/ProtocolBuffers.Test/CompatTests/google_message2.dat b/src/ProtocolBuffers.Test/Compatibility/google_message2.dat similarity index 100% rename from src/ProtocolBuffers.Test/CompatTests/google_message2.dat rename to src/ProtocolBuffers.Test/Compatibility/google_message2.dat diff --git a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 04a02999c6..5e3198754e 100644 --- a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -75,17 +75,17 @@ - - - - - + + + + + True True TestResources.resx - - + + @@ -147,11 +147,11 @@ - - + + - + ResXFileCodeGenerator TestResources.Designer.cs diff --git a/src/ProtocolBuffers/ExtensionRegistryLite.cs b/src/ProtocolBuffers/ExtensionRegistryLite.cs index df0a7b257c..d1220e9ce6 100644 --- a/src/ProtocolBuffers/ExtensionRegistryLite.cs +++ b/src/ProtocolBuffers/ExtensionRegistryLite.cs @@ -36,6 +36,8 @@ using System; using System.Collections.Generic; +using ExtensionByNameMap = System.Collections.Generic.Dictionary>; +using ExtensionByIdMap = System.Collections.Generic.Dictionary; namespace Google.ProtocolBuffers { @@ -92,14 +94,6 @@ namespace Google.ProtocolBuffers /// public sealed partial class ExtensionRegistry { - private class ExtensionByNameMap : Dictionary> - { - } - - private class ExtensionByIdMap : Dictionary - { - } - private static readonly ExtensionRegistry empty = new ExtensionRegistry( new ExtensionByNameMap(), new ExtensionByIdMap(), @@ -192,7 +186,7 @@ namespace Google.ProtocolBuffers /// Nested type just used to represent a pair of MessageDescriptor and int, as /// the key into the "by number" map. /// - private struct ExtensionIntPair : IEquatable + internal struct ExtensionIntPair : IEquatable { private readonly object msgType; private readonly int number;