Commit cb7fc657 authored by csharptest's avatar csharptest

Tests and fixes

parent 272cb8ae
......@@ -47,3 +47,26 @@ message TestInteropEmployeeId {
extend TestInteropPerson {
required TestInteropEmployeeId employee_id = 126;
}
message TestMissingFieldsA {
required string name = 1;
required int32 id = 2;
optional string email = 3;
message SubA {
required int32 count = 5;
repeated string values = 6;
}
optional SubA testA = 11;
}
message TestMissingFieldsB {
required string name = 1;
required int32 id = 2;
optional string website = 4;
message SubB {
repeated string values = 7;
}
optional SubB testB = 12;
}
......@@ -38,7 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "unittest", "unittest", "{C8
..\protos\google\protobuf\unittest_embed_optimize_for.proto = ..\protos\google\protobuf\unittest_embed_optimize_for.proto
..\protos\google\protobuf\unittest_empty.proto = ..\protos\google\protobuf\unittest_empty.proto
..\protos\google\protobuf\unittest_enormous_descriptor.proto = ..\protos\google\protobuf\unittest_enormous_descriptor.proto
..\protos\extest\unittest_extras_full.proto = ..\protos\extest\unittest_extras_full.proto
..\..\..\DotNet\ProtoFiles\Test\Protos\SampleComplex.proto = ..\..\..\DotNet\ProtoFiles\Test\Protos\SampleComplex.proto
..\protos\extest\unittest_extras_lite.proto = ..\protos\extest\unittest_extras_lite.proto
..\protos\google\protobuf\unittest_import.proto = ..\protos\google\protobuf\unittest_import.proto
..\protos\google\protobuf\unittest_import_lite.proto = ..\protos\google\protobuf\unittest_import_lite.proto
......
......@@ -129,6 +129,10 @@ namespace Google.ProtocolBuffers {
this[field] = entry.Value;
}
}
//Fix for unknown fields not merging, see java's AbstractMessage.Builder<T> line 236
MergeUnknownFields(other.UnknownFields);
return ThisBuilder;
}
......
......@@ -158,6 +158,10 @@ namespace Google.ProtocolBuffers {
this[field] = entry.Value;
}
}
//Fix for unknown fields not merging, see java's AbstractMessage.Builder<T> line 236
MergeUnknownFields(other.UnknownFields);
return ThisBuilder;
}
......
......@@ -221,5 +221,47 @@ namespace Google.ProtocolBuffers {
Assert.AreEqual(2, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1));
}
[Test]
public void TestMissingExtensionsLite()
{
const int optionalInt32 = 12345678;
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
builder.SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, optionalInt32);
builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.1);
builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.2);
builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.3);
TestAllExtensionsLite msg = builder.Build();
Assert.IsTrue(msg.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
Assert.AreEqual(3, msg.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite));
byte[] bits = msg.ToByteArray();
TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
Assert.IsFalse(copy.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
Assert.AreEqual(0, copy.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite));
Assert.AreNotEqual(msg, copy);
//The lite runtime removes all unknown fields and extensions
byte[] copybits = copy.ToByteArray();
Assert.AreEqual(0, copybits.Length);
}
[Test]
public void TestMissingFieldsLite()
{
TestAllTypesLite msg = TestAllTypesLite.CreateBuilder()
.SetOptionalInt32(123)
.SetOptionalString("123")
.Build();
byte[] bits = msg.ToByteArray();
TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
Assert.AreNotEqual(msg, copy);
//The lite runtime removes all unknown fields and extensions
byte[] copybits = copy.ToByteArray();
Assert.AreEqual(0, copybits.Length);
}
}
}
This diff is collapsed.
......@@ -63,6 +63,7 @@
<Compile Include="ExtendableMessageLiteTest.cs" />
<Compile Include="InteropLiteTest.cs" />
<Compile Include="LiteTest.cs" />
<Compile Include="MissingFieldAndExtensionTest.cs" />
<Compile Include="TestLiteByApi.cs" />
<Compile Include="TestProtos\UnitTestExtrasFullProtoFile.cs" />
<Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" />
......
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