Commit 19ed9c07 authored by Jon Skeet's avatar Jon Skeet

UnknownFieldSet tests, and a fix to repeated extension elements.

parent a80a37cc
...@@ -58,8 +58,11 @@ namespace Google.ProtocolBuffers { ...@@ -58,8 +58,11 @@ namespace Google.ProtocolBuffers {
Assert.AreEqual(MergeResultText, result.ToString()); Assert.AreEqual(MergeResultText, result.ToString());
} }
/** Test merging two DynamicMessages. */ /// <summary>
public void testDynamicMergeFrom() { /// Test merging two DynamicMessages.
/// </summary>
[Test]
public void DynamicMergeFrom() {
DynamicMessage result = (DynamicMessage) DynamicMessage.CreateBuilder(MergeDest) DynamicMessage result = (DynamicMessage) DynamicMessage.CreateBuilder(MergeDest)
.MergeFrom((DynamicMessage) DynamicMessage.CreateBuilder(MergeSource).Build()) .MergeFrom((DynamicMessage) DynamicMessage.CreateBuilder(MergeSource).Build())
.Build(); .Build();
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<Compile Include="MessageTest.cs" /> <Compile Include="MessageTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionTester.cs" /> <Compile Include="ReflectionTester.cs" />
<Compile Include="ServiceTest.cs" />
<Compile Include="TestProtos\EnumWithNoOuter.cs" /> <Compile Include="TestProtos\EnumWithNoOuter.cs" />
<Compile Include="TestProtos\MessageWithNoOuter.cs" /> <Compile Include="TestProtos\MessageWithNoOuter.cs" />
<Compile Include="TestProtos\MultiFileProto.cs" /> <Compile Include="TestProtos\MultiFileProto.cs" />
...@@ -64,6 +65,8 @@ ...@@ -64,6 +65,8 @@
<Compile Include="TestProtos\UnitTestOptimizeForProtoFile.cs" /> <Compile Include="TestProtos\UnitTestOptimizeForProtoFile.cs" />
<Compile Include="TestProtos\UnitTestProtoFile.cs" /> <Compile Include="TestProtos\UnitTestProtoFile.cs" />
<Compile Include="TestUtil.cs" /> <Compile Include="TestUtil.cs" />
<Compile Include="TextFormatTest.cs" />
<Compile Include="UnknownFieldSetTest.cs" />
<Compile Include="WireFormatTest.cs" /> <Compile Include="WireFormatTest.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace Google.ProtocolBuffers {
[TestFixture]
public class ServiceTest {
}
}
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace Google.ProtocolBuffers {
[TestFixture]
public class TextFormatTest {
}
}
This diff is collapsed.
...@@ -84,6 +84,11 @@ namespace Google.ProtocolBuffers { ...@@ -84,6 +84,11 @@ namespace Google.ProtocolBuffers {
} }
#endregion #endregion
public TBuilder SetUnknownFields(UnknownFieldSet fields) {
UnknownFields = fields;
return ThisBuilder;
}
public virtual TBuilder Clear() { public virtual TBuilder Clear() {
foreach(FieldDescriptor field in AllFields.Keys) { foreach(FieldDescriptor field in AllFields.Keys) {
ClearField(field); ClearField(field);
......
...@@ -78,7 +78,8 @@ namespace Google.ProtocolBuffers { ...@@ -78,7 +78,8 @@ namespace Google.ProtocolBuffers {
} }
case MappedType.Enum: case MappedType.Enum:
// Just return a boxed int - that can be unboxed to the enum // Just return a boxed int - that can be unboxed to the enum
return ((EnumValueDescriptor) value).Number; EnumValueDescriptor enumValue = (EnumValueDescriptor) value;
return enumValue.Number;
default: default:
return value; return value;
} }
......
...@@ -31,7 +31,7 @@ namespace Google.ProtocolBuffers { ...@@ -31,7 +31,7 @@ namespace Google.ProtocolBuffers {
// Must convert the whole list. // Must convert the whole list.
List<TExtensionElement> result = new List<TExtensionElement>(); List<TExtensionElement> result = new List<TExtensionElement>();
foreach (object element in (IEnumerable) value) { foreach (object element in (IEnumerable) value) {
((IList) result).Add(SingularFromReflectionType(element)); result.Add((TExtensionElement) SingularFromReflectionType(element));
} }
return result; return result;
} else { } else {
......
...@@ -123,6 +123,9 @@ namespace Google.ProtocolBuffers { ...@@ -123,6 +123,9 @@ namespace Google.ProtocolBuffers {
public interface IBuilder<TMessage, TBuilder> : IBuilder public interface IBuilder<TMessage, TBuilder> : IBuilder
where TMessage : IMessage<TMessage, TBuilder> where TMessage : IMessage<TMessage, TBuilder>
where TBuilder : IBuilder<TMessage, TBuilder> { where TBuilder : IBuilder<TMessage, TBuilder> {
TBuilder SetUnknownFields(UnknownFieldSet unknownFields);
/// <summary> /// <summary>
/// Resets all fields to their default values. /// Resets all fields to their default values.
/// </summary> /// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment