Commit ce66c5f1 authored by Jon Skeet's avatar Jon Skeet

Updated set of unit tests and unit test protos.

This commit includes changes to the C#-specific protos, and rebuilt versions of the "stock" protos.
The stock protos have been locally updated to have a specific C# namespace, but this is expected to change soon, so hasn't been committed.
Four areas are currently not tested:
1) Serialization - we may restore this at some point, possibly optionally.
2) Services - currently nothing is generated for this; will need to see how it interacts with GRPC
3) Fields beginning with _{digit} - see https://github.com/google/protobuf/issues/308
4) Fields with names which conflict with the declaring type in nasty ways - see https://github.com/google/protobuf/issues/309
parent f3504cf3
// 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 = "UnitTestExtrasProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra;
option java_package = "com.google.protobuf";
message TestUnpackedExtensions {
extensions 1 to max;
}
extend TestUnpackedExtensions {
repeated int32 unpacked_int32_extension = 90;
repeated int64 unpacked_int64_extension = 91;
repeated uint32 unpacked_uint32_extension = 92;
repeated uint64 unpacked_uint64_extension = 93;
repeated sint32 unpacked_sint32_extension = 94;
repeated sint64 unpacked_sint64_extension = 95;
repeated fixed32 unpacked_fixed32_extension = 96;
repeated fixed64 unpacked_fixed64_extension = 97;
repeated sfixed32 unpacked_sfixed32_extension = 98;
repeated sfixed64 unpacked_sfixed64_extension = 99;
repeated float unpacked_float_extension = 100;
repeated double unpacked_double_extension = 101;
repeated bool unpacked_bool_extension = 102;
repeated UnpackedExtensionsForeignEnum unpacked_enum_extension = 103;
}
enum UnpackedExtensionsForeignEnum {
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
}
// Additional options required for C# generation. File from copyright syntax = "proto2";
// 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 = "UnitTestExtrasFullProtoFile";
package protobuf_unittest_extra; package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = CODE_SIZE; option optimize_for = CODE_SIZE;
option java_package = "com.google.protobuf"; option java_package = "com.google.protobuf";
message TestInteropPerson { message TestInteropPerson {
...@@ -45,7 +41,10 @@ message TestInteropEmployeeId { ...@@ -45,7 +41,10 @@ message TestInteropEmployeeId {
} }
extend TestInteropPerson { extend TestInteropPerson {
required TestInteropEmployeeId employee_id = 126; // Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeId employee_id = 126;
} }
message TestMissingFieldsA { message TestMissingFieldsA {
......
// Additional options required for C# generation. File from copyright syntax = "proto2";
// 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 = "UnitTestExtrasLiteProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra; package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
option java_package = "com.google.protobuf"; option java_package = "com.google.protobuf";
message TestRequiredLite { message TestRequiredLite {
...@@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite { ...@@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite {
} }
extend TestInteropPersonLite { extend TestInteropPersonLite {
required TestInteropEmployeeIdLite employee_id_lite = 126; // Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeIdLite employee_id_lite = 126;
} }
/* Removed from unittest_lite.proto and added back here */ /* Removed from unittest_lite.proto and added back here */
......
import "google/protobuf/csharp_options.proto"; syntax = "proto2";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile"; option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra; package protobuf_unittest_extra;
......
syntax = "proto2";
// Additional options required for C# generation. File from copyright // Additional options required for C# generation. File from copyright
// line onwards is as per original distribution. // line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
import "google/protobuf/unittest.proto"; import "google/protobuf/unittest.proto";
import "google/protobuf/unittest_custom_options.proto"; import "google/protobuf/unittest_custom_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestGenericServices";
option (google.protobuf.csharp_file_options).service_generator_type = GENERIC; option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
// option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;
// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;
option optimize_for = SPEED; option optimize_for = SPEED;
service TestGenericService { service TestGenericService {
rpc Foo(FooRequest) returns (FooResponse); rpc Foo(FooRequest) returns (FooResponse);
rpc Bar(BarRequest) returns (BarResponse); rpc Bar(BarRequest) returns (BarResponse);
} }
service TestGenericServiceWithCustomOptions { service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210; option (service_opt1) = -9876543210;
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) { rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2; option (method_opt1) = METHODOPT1_VAL2;
} }
} }
syntax = "proto2";
// These proto descriptors have at one time been reported as an issue or defect. // These proto descriptors have at one time been reported as an issue or defect.
// They are kept here to replicate the issue, and continue to verify the fix. // They are kept here to replicate the issue, and continue to verify the fix.
import "google/protobuf/csharp_options.proto";
// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified // Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
option (google.protobuf.csharp_file_options).namespace = "UnitTest.Issues.TestProtos"; option csharp_namespace = "UnitTest.Issues.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasIssuesProtoFile";
package unittest_issues; package unittest_issues;
option optimize_for = SPEED; option optimize_for = SPEED;
...@@ -67,24 +67,28 @@ service TestGenericService { ...@@ -67,24 +67,28 @@ service TestGenericService {
rpc Bar(TestBasicNoFields) returns (TestBasicMessage); rpc Bar(TestBasicNoFields) returns (TestBasicMessage);
} }
*/ */
// Issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// New issue 309: https://github.com/google/protobuf/issues/309
message A { // message A {
optional int32 _A = 1; // optional int32 _A = 1;
} // }
message B { // message B {
optional int32 B_ = 1; // optional int32 B_ = 1;
} // }
message AB { //message AB {
optional int32 a_b = 1; // optional int32 a_b = 1;
} //}
// Similar issue with numeric names // Similar issue with numeric names
message NumberField { // Java code failed too, so probably best for this to be a restriction.
optional int32 _01 = 1; // See https://github.com/google/protobuf/issues/308
} // message NumberField {
// optional int32 _01 = 1;
// }
// Issue 28: Circular message dependencies result in null defaults for DefaultInstance // Issue 28: Circular message dependencies result in null defaults for DefaultInstance
......
...@@ -132,8 +132,8 @@ namespace Google.ProtocolBuffers ...@@ -132,8 +132,8 @@ namespace Google.ProtocolBuffers
{ {
byte[] bytes = TestUtil.GetPackedSet().ToByteArray(); byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry); Unittest.RegisterAllExtensions(registry);
UnitTestExtrasProtoFile.RegisterAllExtensions(registry); UnittestImport.RegisterAllExtensions(registry);
TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry); TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertUnpackedExtensionsSet(message); TestUtil.AssertUnpackedExtensionsSet(message);
} }
...@@ -143,7 +143,7 @@ namespace Google.ProtocolBuffers ...@@ -143,7 +143,7 @@ namespace Google.ProtocolBuffers
{ {
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray(); byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry); Unittest.RegisterAllExtensions(registry);
TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry); TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertPackedExtensionsSet(message); TestUtil.AssertPackedExtensionsSet(message);
} }
...@@ -250,7 +250,7 @@ namespace Google.ProtocolBuffers ...@@ -250,7 +250,7 @@ namespace Google.ProtocolBuffers
TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build(); TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build();
TestAllExtensions e = TestUtil.GetAllExtensionsSet(); TestAllExtensions e = TestUtil.GetAllExtensionsSet();
TestAllExtensions f = TestAllExtensions.CreateBuilder(e) TestAllExtensions f = TestAllExtensions.CreateBuilder(e)
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 999).Build(); .AddExtension(Unittest.RepeatedInt32Extension, 999).Build();
CheckEqualsIsConsistent(a); CheckEqualsIsConsistent(a);
CheckEqualsIsConsistent(b); CheckEqualsIsConsistent(b);
......
...@@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Compatibility
{ {
/// <summary> /// <summary>
/// This abstract base implements several tests to ensure that well-known messages can be written /// 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 /// and read to/from various formats without losing data. Implementations overload the two serailization
/// methods to provide the tests with the means to read and write for a given format. /// methods to provide the tests with the means to read and write for a given format.
/// </summary> /// </summary>
public abstract class CompatibilityTests public abstract class CompatibilityTests
......
...@@ -398,24 +398,24 @@ namespace Google.ProtocolBuffers ...@@ -398,24 +398,24 @@ namespace Google.ProtocolBuffers
{ {
// ClearExtension() is not actually used in TestUtil, so try it manually. // ClearExtension() is not actually used in TestUtil, so try it manually.
Assert.IsFalse(TestAllExtensions.CreateBuilder() Assert.IsFalse(TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1) .SetExtension(Unittest.OptionalInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.OptionalInt32Extension) .ClearExtension(Unittest.OptionalInt32Extension)
.HasExtension(UnitTestProtoFile.OptionalInt32Extension)); .HasExtension(Unittest.OptionalInt32Extension));
Assert.AreEqual(0, TestAllExtensions.CreateBuilder() Assert.AreEqual(0, TestAllExtensions.CreateBuilder()
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 1) .AddExtension(Unittest.RepeatedInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.RepeatedInt32Extension) .ClearExtension(Unittest.RepeatedInt32Extension)
.GetExtensionCount(UnitTestProtoFile.RepeatedInt32Extension)); .GetExtensionCount(Unittest.RepeatedInt32Extension));
} }
[TestMethod] [TestMethod]
public void ExtensionMergeFrom() public void ExtensionMergeFrom()
{ {
TestAllExtensions original = TestAllExtensions.CreateBuilder() TestAllExtensions original = TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1).Build(); .SetExtension(Unittest.OptionalInt32Extension, 1).Build();
TestAllExtensions merged = TestAllExtensions merged =
TestAllExtensions.CreateBuilder().MergeFrom(original).Build(); TestAllExtensions.CreateBuilder().MergeFrom(original).Build();
Assert.IsTrue((merged.HasExtension(UnitTestProtoFile.OptionalInt32Extension))); Assert.IsTrue((merged.HasExtension(Unittest.OptionalInt32Extension)));
Assert.AreEqual(1, (int) merged.GetExtension(UnitTestProtoFile.OptionalInt32Extension)); Assert.AreEqual(1, (int) merged.GetExtension(Unittest.OptionalInt32Extension));
} }
/* Removed multiple files option for the moment /* Removed multiple files option for the moment
...@@ -430,13 +430,13 @@ namespace Google.ProtocolBuffers ...@@ -430,13 +430,13 @@ namespace Google.ProtocolBuffers
.Build(); .Build();
Assert.AreEqual(message, MessageWithNoOuter.ParseFrom(message.ToByteString())); Assert.AreEqual(message, MessageWithNoOuter.ParseFrom(message.ToByteString()));
Assert.AreEqual(MultiFileProto.Descriptor, MessageWithNoOuter.Descriptor.File); Assert.AreEqual(MultiFileProto.DescriptorProtoFile, MessageWithNoOuter.DescriptorProtoFile.File);
FieldDescriptor field = MessageWithNoOuter.Descriptor.FindDescriptor<FieldDescriptor>("foreign_enum"); FieldDescriptor field = MessageWithNoOuter.DescriptorProtoFile.FindDescriptor<FieldDescriptor>("foreign_enum");
Assert.AreEqual(MultiFileProto.Descriptor.FindTypeByName<EnumDescriptor>("EnumWithNoOuter") Assert.AreEqual(MultiFileProto.DescriptorProtoFile.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
.FindValueByNumber((int)EnumWithNoOuter.BAR), message[field]); .FindValueByNumber((int)EnumWithNoOuter.BAR), message[field]);
Assert.AreEqual(MultiFileProto.Descriptor, ServiceWithNoOuter.Descriptor.File); Assert.AreEqual(MultiFileProto.DescriptorProtoFile, ServiceWithNoOuter.DescriptorProtoFile.File);
Assert.IsFalse(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter)); Assert.IsFalse(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter));
}*/ }*/
...@@ -512,14 +512,14 @@ namespace Google.ProtocolBuffers ...@@ -512,14 +512,14 @@ namespace Google.ProtocolBuffers
{ {
Assert.AreEqual(TestRequired.SingleFieldNumber, 1000); Assert.AreEqual(TestRequired.SingleFieldNumber, 1000);
Assert.AreEqual(TestRequired.MultiFieldNumber, 1001); Assert.AreEqual(TestRequired.MultiFieldNumber, 1001);
Assert.AreEqual(UnitTestProtoFile.OptionalInt32ExtensionFieldNumber, 1); Assert.AreEqual(Unittest.OptionalInt32ExtensionFieldNumber, 1);
Assert.AreEqual(UnitTestProtoFile.OptionalGroupExtensionFieldNumber, 16); Assert.AreEqual(Unittest.OptionalGroupExtensionFieldNumber, 16);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedMessageExtensionFieldNumber, 18); Assert.AreEqual(Unittest.OptionalNestedMessageExtensionFieldNumber, 18);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedEnumExtensionFieldNumber, 21); Assert.AreEqual(Unittest.OptionalNestedEnumExtensionFieldNumber, 21);
Assert.AreEqual(UnitTestProtoFile.RepeatedInt32ExtensionFieldNumber, 31); Assert.AreEqual(Unittest.RepeatedInt32ExtensionFieldNumber, 31);
Assert.AreEqual(UnitTestProtoFile.RepeatedGroupExtensionFieldNumber, 46); Assert.AreEqual(Unittest.RepeatedGroupExtensionFieldNumber, 46);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedMessageExtensionFieldNumber, 48); Assert.AreEqual(Unittest.RepeatedNestedMessageExtensionFieldNumber, 48);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedEnumExtensionFieldNumber, 51); Assert.AreEqual(Unittest.RepeatedNestedEnumExtensionFieldNumber, 51);
} }
[TestMethod] [TestMethod]
......
...@@ -82,9 +82,20 @@ ...@@ -82,9 +82,20 @@
<Compile Include="Compatibility\TextCompatibilityTests.cs" /> <Compile Include="Compatibility\TextCompatibilityTests.cs" />
<Compile Include="Compatibility\XmlCompatibilityTests.cs" /> <Compile Include="Compatibility\XmlCompatibilityTests.cs" />
<Compile Include="SerializableAttribute.cs" /> <Compile Include="SerializableAttribute.cs" />
<Compile Include="TestProtos\UnitTestExtrasProtoFile.cs" /> <Compile Include="TestProtos\GoogleSize.cs" />
<Compile Include="TestProtos\GoogleSpeed.cs" />
<Compile Include="TestProtos\Unittest.cs" />
<Compile Include="TestProtos\UnittestCustomOptions.cs" />
<Compile Include="TestProtos\UnittestDropUnknownFields.cs" />
<Compile Include="TestProtos\UnittestEnormousDescriptor.cs" />
<Compile Include="TestProtos\UnittestExtrasXmltest.cs" />
<Compile Include="TestProtos\UnittestImport.cs" />
<Compile Include="TestProtos\UnittestImportPublic.cs" />
<Compile Include="TestProtos\UnittestIssues.cs" />
<Compile Include="TestProtos\UnittestMset.cs" />
<Compile Include="TestProtos\UnittestOptimizeFor.cs" />
<Compile Include="TestProtos\UnknownEnumTest.cs" />
<Compile Include="TestResources.cs" /> <Compile Include="TestResources.cs" />
<Compile Include="TestRpcForMimeTypes.cs" />
<Compile Include="TestReaderForUrlEncoded.cs" /> <Compile Include="TestReaderForUrlEncoded.cs" />
<Compile Include="DeprecatedMemberTest.cs" /> <Compile Include="DeprecatedMemberTest.cs" />
<Compile Include="DescriptorsTest.cs" /> <Compile Include="DescriptorsTest.cs" />
...@@ -102,26 +113,8 @@ ...@@ -102,26 +113,8 @@
<Compile Include="ReflectionTester.cs" /> <Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" /> <Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableTest.cs" /> <Compile Include="SerializableTest.cs" />
<Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.cs" /> <Compile Include="TestCornerCases.cs" />
<Compile Include="TestMimeMessageFormats.cs" /> <Compile Include="TestMimeMessageFormats.cs" />
<Compile Include="TestProtos\UnitTestCSharpOptionsProtoFile.cs" />
<Compile Include="TestProtos\UnitTestCustomOptionsProtoFile.cs" />
<Compile Include="TestProtos\UnitTestEmbedOptimizeForProtoFile.cs" />
<Compile Include="TestProtos\UnitTestEmptyProtoFile.cs" />
<Compile Include="TestProtos\UnitTestExtrasIssuesProtoFile.cs" />
<Compile Include="TestProtos\UnitTestGenericServices.cs" />
<Compile Include="TestProtos\UnitTestGoogleSizeProtoFile.cs" />
<Compile Include="TestProtos\UnitTestGoogleSpeedProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportProtoFile.cs" />
<Compile Include="TestProtos\UnitTestMessageSetProtoFile.cs" />
<Compile Include="TestProtos\UnitTestNoGenericServicesProtoFile.cs" />
<Compile Include="TestProtos\UnitTestOptimizeForProtoFile.cs" />
<Compile Include="TestProtos\UnitTestProtoFile.cs" />
<Compile Include="TestProtos\UnitTestRpcInterop.cs" />
<Compile Include="TestProtos\UnitTestXmlSerializerTestProtoFile.cs" />
<Compile Include="TestRpcGenerator.cs" />
<Compile Include="TestUtil.cs" /> <Compile Include="TestUtil.cs" />
<Compile Include="TestWriterFormatJson.cs" /> <Compile Include="TestWriterFormatJson.cs" />
<Compile Include="TestWriterFormatXml.cs" /> <Compile Include="TestWriterFormatXml.cs" />
...@@ -160,6 +153,7 @@ ...@@ -160,6 +153,7 @@
<EmbeddedResource Include="Compatibility\google_message1.dat" /> <EmbeddedResource Include="Compatibility\google_message1.dat" />
<EmbeddedResource Include="Compatibility\google_message2.dat" /> <EmbeddedResource Include="Compatibility\google_message2.dat" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -97,10 +97,8 @@ namespace Google.ProtocolBuffers ...@@ -97,10 +97,8 @@ namespace Google.ProtocolBuffers
this.extensionRegistry = extensionRegistry; this.extensionRegistry = extensionRegistry;
this.file = baseDescriptor.File; this.file = baseDescriptor.File;
// TODO(jonskeet): We've got 2 dependencies, not 1 - because of the C# options. Hmm. Assert.AreEqual(1, file.Dependencies.Count);
// Assert.AreEqual(1, file.Dependencies.Count); this.importFile = file.Dependencies[0];
// TODO(jonskeet): Find dependency by name instead of number?
this.importFile = file.Dependencies[1];
MessageDescriptor testAllTypes; MessageDescriptor testAllTypes;
if (baseDescriptor.Name == "TestAllTypes") if (baseDescriptor.Name == "TestAllTypes")
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Hosting;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
...@@ -20,6 +21,7 @@ namespace Google.ProtocolBuffers ...@@ -20,6 +21,7 @@ namespace Google.ProtocolBuffers
public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder(); public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder();
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainMessage() public void TestPlainMessage()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
...@@ -53,6 +55,7 @@ namespace Google.ProtocolBuffers ...@@ -53,6 +55,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestMessageWithExtensions() public void TestMessageWithExtensions()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
...@@ -74,16 +77,16 @@ namespace Google.ProtocolBuffers ...@@ -74,16 +77,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder() .AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE) .AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3]))) .SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
.Build(); .Build();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, message); new BinaryFormatter().Serialize(ms, message);
...@@ -98,6 +101,7 @@ namespace Google.ProtocolBuffers ...@@ -98,6 +101,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainBuilder() public void TestPlainBuilder()
{ {
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder() TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
...@@ -131,6 +135,7 @@ namespace Google.ProtocolBuffers ...@@ -131,6 +135,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestBuilderWithExtensions() public void TestBuilderWithExtensions()
{ {
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder() TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
...@@ -152,16 +157,16 @@ namespace Google.ProtocolBuffers ...@@ -152,16 +157,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder() .AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE) .AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3]))) .SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
; ;
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, builder); new BinaryFormatter().Serialize(ms, builder);
......
This diff is collapsed.
// Generated by ProtoGen, Version=2.4.1.555, Culture=neutral, PublicKeyToken=55f7125234beb589. DO NOT EDIT!
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
namespace Google.ProtocolBuffers.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static partial class UnitTestEmptyProtoFile {
#region Extension registration
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
}
#endregion
#region Static variables
#endregion
#region Descriptor
public static pbd::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbd::FileDescriptor descriptor;
static UnitTestEmptyProtoFile() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CiRnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfZW1wdHkucHJvdG8aJGdvb2ds",
"ZS9wcm90b2J1Zi9jc2hhcnBfb3B0aW9ucy5wcm90b0I+wj47CiFHb29nbGUu",
"UHJvdG9jb2xCdWZmZXJzLlRlc3RQcm90b3MSFlVuaXRUZXN0RW1wdHlQcm90",
"b0ZpbGU="));
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root;
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
RegisterAllExtensions(registry);
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry);
return registry;
};
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbd::FileDescriptor[] {
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor,
}, assigner);
}
#endregion
}
}
#endregion Designer generated code
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -315,7 +315,7 @@ namespace Google.ProtocolBuffers ...@@ -315,7 +315,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionText() public void TestXmlWithExtensionText()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -324,7 +324,7 @@ namespace Google.ProtocolBuffers ...@@ -324,7 +324,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -334,7 +334,7 @@ namespace Google.ProtocolBuffers ...@@ -334,7 +334,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionMessage() public void TestXmlWithExtensionMessage()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, .SetExtension(UnittestExtrasXmltest.ExtensionMessage,
new TestXmlExtension.Builder().SetNumber(42).Build()).Build(); new TestXmlExtension.Builder().SetNumber(42).Build()).Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -343,7 +343,7 @@ namespace Google.ProtocolBuffers ...@@ -343,7 +343,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -353,9 +353,9 @@ namespace Google.ProtocolBuffers ...@@ -353,9 +353,9 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionArray() public void TestXmlWithExtensionArray()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -364,7 +364,7 @@ namespace Google.ProtocolBuffers ...@@ -364,7 +364,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -374,7 +374,7 @@ namespace Google.ProtocolBuffers ...@@ -374,7 +374,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionEnum() public void TestXmlWithExtensionEnum()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -383,7 +383,7 @@ namespace Google.ProtocolBuffers ...@@ -383,7 +383,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
......
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