Просмотр исходного кода

Integrated feedback from revision c97eeb8d933f

csharptest 14 лет назад
Родитель
Сommit
b5ba93bf3c

+ 0 - 2
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";

+ 2 - 2
src/ProtocolBuffers.Test/CompatTests/BinaryCompatibilityTests.cs → 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<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
         {
             return builder.MergeFrom((byte[])message, registry);
         }

+ 14 - 9
src/ProtocolBuffers.Test/CompatTests/CompatibilityTests.cs → 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
 {
+    /// <summary>
+    /// 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.
+    /// </summary>
     public abstract class CompatibilityTests
     {
         protected abstract object SerializeMessage<TMessage, TBuilder>(TMessage message)
             where TMessage : IMessageLite<TMessage, TBuilder>
             where TBuilder : IBuilderLite<TMessage, TBuilder>;
 
-        protected abstract TBuilder DeerializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected abstract TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
             where TMessage : IMessageLite<TMessage, TBuilder>
             where TBuilder : IBuilderLite<TMessage, TBuilder>;
 
@@ -25,7 +30,7 @@ namespace Google.ProtocolBuffers.CompatTests
             SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
             object content = SerializeMessage<SizeMessage1, SizeMessage1.Builder>(msg);
 
-            SizeMessage1 copy = DeerializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
@@ -38,7 +43,7 @@ namespace Google.ProtocolBuffers.CompatTests
             SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
             object content = SerializeMessage<SizeMessage2, SizeMessage2.Builder>(msg);
 
-            SizeMessage2 copy = DeerializeMessage<SizeMessage2, SizeMessage2.Builder>(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            SizeMessage2 copy = DeserializeMessage<SizeMessage2, SizeMessage2.Builder>(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<SizeMessage2, SizeMessage2.Builder>(copy));
@@ -51,7 +56,7 @@ namespace Google.ProtocolBuffers.CompatTests
             SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
             object content = SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(msg);
 
-            SpeedMessage1 copy = DeerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
@@ -64,7 +69,7 @@ namespace Google.ProtocolBuffers.CompatTests
             SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
             object content = SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(msg);
 
-            SpeedMessage2 copy = DeerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            SpeedMessage2 copy = DeserializeMessage<SpeedMessage2, SpeedMessage2.Builder>(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(copy));
@@ -151,7 +156,7 @@ namespace Google.ProtocolBuffers.CompatTests
             TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build();
             object content = SerializeMessage<TestAllTypes, TestAllTypes.Builder>(msg);
 
-            TestAllTypes copy = DeerializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
@@ -164,7 +169,7 @@ namespace Google.ProtocolBuffers.CompatTests
             TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build();
             object content = SerializeMessage<TestAllTypes, TestAllTypes.Builder>(msg);
 
-            TestAllTypes copy = DeerializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
@@ -177,7 +182,7 @@ namespace Google.ProtocolBuffers.CompatTests
             TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build();
             object content = SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(msg);
 
-            TestPackedTypes copy = DeerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
+            TestPackedTypes copy = DeserializeMessage<TestPackedTypes, TestPackedTypes.Builder>(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
 
             Assert.AreEqual(msg, copy);
             AssertOutputEquals(content, SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(copy));

+ 2 - 2
src/ProtocolBuffers.Test/CompatTests/DictionaryCompatibilityTests.cs → 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<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
         {
             new DictionaryReader((IDictionary<string, object>)message).Merge(builder);
             return builder;

+ 2 - 2
src/ProtocolBuffers.Test/CompatTests/JsonCompatibilityTests.cs → 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<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
         {
             JsonFormatReader.CreateInstance((string)message).Merge(builder);
             return builder;

+ 3 - 3
src/ProtocolBuffers.Test/CompatTests/TestResources.Designer.cs → src/ProtocolBuffers.Test/Compatibility/TestResources.Designer.cs

@@ -1,14 +1,14 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     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.
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-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;

+ 0 - 0
src/ProtocolBuffers.Test/CompatTests/TestResources.resx → src/ProtocolBuffers.Test/Compatibility/TestResources.resx


+ 2 - 2
src/ProtocolBuffers.Test/CompatTests/TextCompatibilityTests.cs → 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<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
         {
             TextFormat.Merge(new StringReader((string)message), registry, (IBuilder)builder);
             return builder;

+ 2 - 2
src/ProtocolBuffers.Test/CompatTests/XmlCompatibilityTests.cs → 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<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
         {
             XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message);
             return reader.Merge("root", builder, registry);

+ 0 - 0
src/ProtocolBuffers.Test/CompatTests/google_message1.dat → src/ProtocolBuffers.Test/Compatibility/google_message1.dat


+ 0 - 0
src/ProtocolBuffers.Test/CompatTests/google_message2.dat → src/ProtocolBuffers.Test/Compatibility/google_message2.dat


+ 10 - 10
src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj

@@ -75,17 +75,17 @@
     <Compile Include="CodedInputStreamTest.cs" />
     <Compile Include="CodedOutputStreamTest.cs" />
     <Compile Include="Collections\PopsicleListTest.cs" />
-    <Compile Include="CompatTests\BinaryCompatibilityTests.cs" />
-    <Compile Include="CompatTests\CompatibilityTests.cs" />
-    <Compile Include="CompatTests\DictionaryCompatibilityTests.cs" />
-    <Compile Include="CompatTests\JsonCompatibilityTests.cs" />
-    <Compile Include="CompatTests\TestResources.Designer.cs">
+    <Compile Include="Compatibility\BinaryCompatibilityTests.cs" />
+    <Compile Include="Compatibility\CompatibilityTests.cs" />
+    <Compile Include="Compatibility\DictionaryCompatibilityTests.cs" />
+    <Compile Include="Compatibility\JsonCompatibilityTests.cs" />
+    <Compile Include="Compatibility\TestResources.Designer.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
       <DependentUpon>TestResources.resx</DependentUpon>
     </Compile>
-    <Compile Include="CompatTests\TextCompatibilityTests.cs" />
-    <Compile Include="CompatTests\XmlCompatibilityTests.cs" />
+    <Compile Include="Compatibility\TextCompatibilityTests.cs" />
+    <Compile Include="Compatibility\XmlCompatibilityTests.cs" />
     <Compile Include="CSharpOptionsTest.cs" />
     <Compile Include="DescriptorsTest.cs" />
     <Compile Include="Descriptors\MessageDescriptorTest.cs" />
@@ -147,11 +147,11 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
-    <None Include="CompatTests\google_message1.dat" />
-    <None Include="CompatTests\google_message2.dat" />
+    <None Include="Compatibility\google_message1.dat" />
+    <None Include="Compatibility\google_message2.dat" />
   </ItemGroup>
   <ItemGroup>
-    <EmbeddedResource Include="CompatTests\TestResources.resx">
+    <EmbeddedResource Include="Compatibility\TestResources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>TestResources.Designer.cs</LastGenOutput>
     </EmbeddedResource>

+ 3 - 9
src/ProtocolBuffers/ExtensionRegistryLite.cs

@@ -36,6 +36,8 @@
 
 using System;
 using System.Collections.Generic;
+using ExtensionByNameMap = System.Collections.Generic.Dictionary<object, System.Collections.Generic.Dictionary<string, Google.ProtocolBuffers.IGeneratedExtensionLite>>;
+using ExtensionByIdMap = System.Collections.Generic.Dictionary<Google.ProtocolBuffers.ExtensionRegistry.ExtensionIntPair, Google.ProtocolBuffers.IGeneratedExtensionLite>;
 
 namespace Google.ProtocolBuffers
 {
@@ -92,14 +94,6 @@ namespace Google.ProtocolBuffers
     /// </remarks>
     public sealed partial class ExtensionRegistry
     {
-        private class ExtensionByNameMap : Dictionary<object, Dictionary<string, IGeneratedExtensionLite>>
-        {
-        }
-
-        private class ExtensionByIdMap : Dictionary<ExtensionIntPair, IGeneratedExtensionLite>
-        {
-        }
-
         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.
         /// </summary>
-        private struct ExtensionIntPair : IEquatable<ExtensionIntPair>
+        internal struct ExtensionIntPair : IEquatable<ExtensionIntPair>
         {
             private readonly object msgType;
             private readonly int number;