Integrated feedback from revision c97eeb8d933f

pull/288/head
csharptest 14 years ago committed by rogerk
parent 84f7e09f02
commit b5ba93bf3c
  1. 2
      protos/extest/unittest_extras_xmltest.proto
  2. 4
      src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs
  3. 23
      src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs
  4. 4
      src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs
  5. 4
      src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs
  6. 6
      src/ProtocolBuffers.Test/Compatibility/TestResources.Designer.cs
  7. 0
      src/ProtocolBuffers.Test/Compatibility/TestResources.resx
  8. 4
      src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs
  9. 4
      src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
  10. 0
      src/ProtocolBuffers.Test/Compatibility/google_message1.dat
  11. 0
      src/ProtocolBuffers.Test/Compatibility/google_message2.dat
  12. 20
      src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
  13. 12
      src/ProtocolBuffers/ExtensionRegistryLite.cs

@ -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"; import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile"; option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile";

@ -1,7 +1,7 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers.CompatTests namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class BinaryCompatibilityTests : CompatibilityTests public class BinaryCompatibilityTests : CompatibilityTests
@ -12,7 +12,7 @@ namespace Google.ProtocolBuffers.CompatTests
return bresult; 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); return builder.MergeFrom((byte[])message, registry);
} }

@ -2,15 +2,20 @@
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; 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 public abstract class CompatibilityTests
{ {
protected abstract object SerializeMessage<TMessage, TBuilder>(TMessage message) protected abstract object SerializeMessage<TMessage, TBuilder>(TMessage message)
where TMessage : IMessageLite<TMessage, TBuilder> where TMessage : IMessageLite<TMessage, TBuilder>
where TBuilder : IBuilderLite<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 TMessage : IMessageLite<TMessage, TBuilder>
where TBuilder : IBuilderLite<TMessage, TBuilder>; where TBuilder : IBuilderLite<TMessage, TBuilder>;
@ -25,7 +30,7 @@ namespace Google.ProtocolBuffers.CompatTests
SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build(); SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
object content = SerializeMessage<SizeMessage1, SizeMessage1.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(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(); SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
object content = SerializeMessage<SizeMessage2, SizeMessage2.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage2, SizeMessage2.Builder>(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(); SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
object content = SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(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(); SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
object content = SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(copy)); AssertOutputEquals(content, SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(copy));
@ -151,7 +156,7 @@ namespace Google.ProtocolBuffers.CompatTests
TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build(); TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build();
object content = SerializeMessage<TestAllTypes, TestAllTypes.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy)); AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
@ -164,7 +169,7 @@ namespace Google.ProtocolBuffers.CompatTests
TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build(); TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build();
object content = SerializeMessage<TestAllTypes, TestAllTypes.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy)); AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
@ -177,7 +182,7 @@ namespace Google.ProtocolBuffers.CompatTests
TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build(); TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build();
object content = SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(msg); 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); Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(copy)); AssertOutputEquals(content, SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(copy));

@ -5,7 +5,7 @@ using System.Text;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers.CompatTests namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class DictionaryCompatibilityTests : CompatibilityTests public class DictionaryCompatibilityTests : CompatibilityTests
@ -17,7 +17,7 @@ namespace Google.ProtocolBuffers.CompatTests
return writer.ToDictionary(); 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); new DictionaryReader((IDictionary<string, object>)message).Merge(builder);
return builder; return builder;

@ -3,7 +3,7 @@ using System.Text;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers.CompatTests namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class JsonCompatibilityTests : CompatibilityTests public class JsonCompatibilityTests : CompatibilityTests
@ -17,7 +17,7 @@ namespace Google.ProtocolBuffers.CompatTests
return sw.ToString(); 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); JsonFormatReader.CreateInstance((string)message).Merge(builder);
return builder; return builder;

@ -1,14 +1,14 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // 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 // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Google.ProtocolBuffers.CompatTests { namespace Google.ProtocolBuffers.Compatibility {
using System; using System;
@ -39,7 +39,7 @@ namespace Google.ProtocolBuffers.CompatTests {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { 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; resourceMan = temp;
} }
return resourceMan; return resourceMan;

@ -2,7 +2,7 @@ using System.ComponentModel;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers.CompatTests namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class TextCompatibilityTests : CompatibilityTests public class TextCompatibilityTests : CompatibilityTests
@ -14,7 +14,7 @@ namespace Google.ProtocolBuffers.CompatTests
return text.ToString(); 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); TextFormat.Merge(new StringReader((string)message), registry, (IBuilder)builder);
return builder; return builder;

@ -3,7 +3,7 @@ using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers.CompatTests namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class XmlCompatibilityTests : CompatibilityTests public class XmlCompatibilityTests : CompatibilityTests
@ -16,7 +16,7 @@ namespace Google.ProtocolBuffers.CompatTests
return text.ToString(); 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); XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message);
return reader.Merge("root", builder, registry); return reader.Merge("root", builder, registry);

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

@ -36,6 +36,8 @@
using System; using System;
using System.Collections.Generic; 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 namespace Google.ProtocolBuffers
{ {
@ -92,14 +94,6 @@ namespace Google.ProtocolBuffers
/// </remarks> /// </remarks>
public sealed partial class ExtensionRegistry 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( private static readonly ExtensionRegistry empty = new ExtensionRegistry(
new ExtensionByNameMap(), new ExtensionByNameMap(),
new ExtensionByIdMap(), new ExtensionByIdMap(),
@ -192,7 +186,7 @@ namespace Google.ProtocolBuffers
/// Nested type just used to represent a pair of MessageDescriptor and int, as /// Nested type just used to represent a pair of MessageDescriptor and int, as
/// the key into the "by number" map. /// the key into the "by number" map.
/// </summary> /// </summary>
private struct ExtensionIntPair : IEquatable<ExtensionIntPair> internal struct ExtensionIntPair : IEquatable<ExtensionIntPair>
{ {
private readonly object msgType; private readonly object msgType;
private readonly int number; private readonly int number;

Loading…
Cancel
Save