Commit 8bae6c09 authored by Jie Luo's avatar Jie Luo

Merge pull request #1 from google/csharp

Csharp update
parents 8a3ec53e 32ead755
......@@ -74,3 +74,8 @@ src/**/*.trs
# JavaBuild output.
java/target
javanano/target
# Windows native output.
vsprojects/Debug
vsprojects/Release
// 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
// 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";
syntax = "proto2";
package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = CODE_SIZE;
option java_package = "com.google.protobuf";
message TestInteropPerson {
......@@ -45,7 +41,10 @@ message TestInteropEmployeeId {
}
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 {
......
// 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 = "UnitTestExtrasLiteProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
syntax = "proto2";
package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = LITE_RUNTIME;
option java_package = "com.google.protobuf";
message TestRequiredLite {
......@@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite {
}
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 */
......
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";
option (google.protobuf.csharp_file_options).add_serializable = true;
syntax = "proto2";
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
package protobuf_unittest_extra;
......
syntax = "proto2";
// 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/unittest.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;
service TestGenericService {
rpc Foo(FooRequest) returns (FooResponse);
rpc Bar(BarRequest) returns (BarResponse);
}
service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210;
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2;
}
}
service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210;
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2;
}
}
syntax = "proto2";
// 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.
import "google/protobuf/csharp_options.proto";
// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
option (google.protobuf.csharp_file_options).namespace = "UnitTest.Issues.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasIssuesProtoFile";
option csharp_namespace = "UnitTest.Issues.TestProtos";
package unittest_issues;
option optimize_for = SPEED;
......@@ -67,24 +67,28 @@ service TestGenericService {
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 {
optional int32 _A = 1;
}
// message A {
// optional int32 _A = 1;
// }
message B {
optional int32 B_ = 1;
}
// message B {
// optional int32 B_ = 1;
// }
message AB {
optional int32 a_b = 1;
}
//message AB {
// optional int32 a_b = 1;
//}
// Similar issue with numeric names
message NumberField {
optional int32 _01 = 1;
}
// Java code failed too, so probably best for this to be a restriction.
// 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
......
......@@ -132,8 +132,8 @@ namespace Google.ProtocolBuffers
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry);
UnitTestExtrasProtoFile.RegisterAllExtensions(registry);
Unittest.RegisterAllExtensions(registry);
UnittestImport.RegisterAllExtensions(registry);
TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertUnpackedExtensionsSet(message);
}
......@@ -143,7 +143,7 @@ namespace Google.ProtocolBuffers
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry);
Unittest.RegisterAllExtensions(registry);
TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertPackedExtensionsSet(message);
}
......@@ -250,7 +250,7 @@ namespace Google.ProtocolBuffers
TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build();
TestAllExtensions e = TestUtil.GetAllExtensionsSet();
TestAllExtensions f = TestAllExtensions.CreateBuilder(e)
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 999).Build();
.AddExtension(Unittest.RepeatedInt32Extension, 999).Build();
CheckEqualsIsConsistent(a);
CheckEqualsIsConsistent(b);
......
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using Google.ProtocolBuffers.DescriptorProtos;
using Google.ProtocolBuffers.Descriptors;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers
{
[TestClass]
public class DescriptorUtilTest
{
[TestMethod]
public void ExplicitNamespace()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder
{
Name = "x",
Package = "pack",
Options =
new FileOptions.Builder().SetExtension(
CSharpOptions.CSharpFileOptions,
new CSharpFileOptions.Builder {Namespace = "Foo.Bar"}.Build()).
Build()
}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("Foo.Bar", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void NoNamespaceFallsBackToPackage()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x", Package = "pack"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("pack", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void NoNamespaceOrPackageFallsBackToEmptyString()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void ExplicitlyNamedFileClass()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder
{
Name = "x",
Options =
new FileOptions.Builder().SetExtension(
CSharpOptions.CSharpFileOptions,
new CSharpFileOptions.Builder {UmbrellaClassname = "Foo"}.Build())
.Build()
}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("Foo", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithProtoSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar.proto"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithProtoDevelSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar.protodevel"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithNoSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithDirectoryStructure()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x/y/foo_bar"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ 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
/// 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.
/// </summary>
public abstract class CompatibilityTests
......
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.Descriptors
{
[TestClass]
public class MessageDescriptorTest
{
[TestMethod]
public void FindPropertyWithDefaultName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.NormalFieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("Normal"));
}
[TestMethod]
public void FindPropertyWithAutoModifiedName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.OptionsMessage_FieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("OptionsMessage_"));
}
[TestMethod]
public void FindPropertyWithCustomizedName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.CustomNameFieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("CustomName"));
}
[TestMethod]
public void FindPropertyWithInvalidName()
{
Assert.IsNull(OptionsMessage.Descriptor.FindFieldByPropertyName("Bogus"));
}
}
}
\ No newline at end of file
......@@ -398,24 +398,24 @@ namespace Google.ProtocolBuffers
{
// ClearExtension() is not actually used in TestUtil, so try it manually.
Assert.IsFalse(TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.OptionalInt32Extension)
.HasExtension(UnitTestProtoFile.OptionalInt32Extension));
.SetExtension(Unittest.OptionalInt32Extension, 1)
.ClearExtension(Unittest.OptionalInt32Extension)
.HasExtension(Unittest.OptionalInt32Extension));
Assert.AreEqual(0, TestAllExtensions.CreateBuilder()
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.RepeatedInt32Extension)
.GetExtensionCount(UnitTestProtoFile.RepeatedInt32Extension));
.AddExtension(Unittest.RepeatedInt32Extension, 1)
.ClearExtension(Unittest.RepeatedInt32Extension)
.GetExtensionCount(Unittest.RepeatedInt32Extension));
}
[TestMethod]
public void ExtensionMergeFrom()
{
TestAllExtensions original = TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1).Build();
.SetExtension(Unittest.OptionalInt32Extension, 1).Build();
TestAllExtensions merged =
TestAllExtensions.CreateBuilder().MergeFrom(original).Build();
Assert.IsTrue((merged.HasExtension(UnitTestProtoFile.OptionalInt32Extension)));
Assert.AreEqual(1, (int) merged.GetExtension(UnitTestProtoFile.OptionalInt32Extension));
Assert.IsTrue((merged.HasExtension(Unittest.OptionalInt32Extension)));
Assert.AreEqual(1, (int) merged.GetExtension(Unittest.OptionalInt32Extension));
}
/* Removed multiple files option for the moment
......@@ -430,13 +430,13 @@ namespace Google.ProtocolBuffers
.Build();
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");
Assert.AreEqual(MultiFileProto.Descriptor.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
FieldDescriptor field = MessageWithNoOuter.DescriptorProtoFile.FindDescriptor<FieldDescriptor>("foreign_enum");
Assert.AreEqual(MultiFileProto.DescriptorProtoFile.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
.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));
}*/
......@@ -512,14 +512,14 @@ namespace Google.ProtocolBuffers
{
Assert.AreEqual(TestRequired.SingleFieldNumber, 1000);
Assert.AreEqual(TestRequired.MultiFieldNumber, 1001);
Assert.AreEqual(UnitTestProtoFile.OptionalInt32ExtensionFieldNumber, 1);
Assert.AreEqual(UnitTestProtoFile.OptionalGroupExtensionFieldNumber, 16);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedMessageExtensionFieldNumber, 18);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedEnumExtensionFieldNumber, 21);
Assert.AreEqual(UnitTestProtoFile.RepeatedInt32ExtensionFieldNumber, 31);
Assert.AreEqual(UnitTestProtoFile.RepeatedGroupExtensionFieldNumber, 46);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedMessageExtensionFieldNumber, 48);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedEnumExtensionFieldNumber, 51);
Assert.AreEqual(Unittest.OptionalInt32ExtensionFieldNumber, 1);
Assert.AreEqual(Unittest.OptionalGroupExtensionFieldNumber, 16);
Assert.AreEqual(Unittest.OptionalNestedMessageExtensionFieldNumber, 18);
Assert.AreEqual(Unittest.OptionalNestedEnumExtensionFieldNumber, 21);
Assert.AreEqual(Unittest.RepeatedInt32ExtensionFieldNumber, 31);
Assert.AreEqual(Unittest.RepeatedGroupExtensionFieldNumber, 46);
Assert.AreEqual(Unittest.RepeatedNestedMessageExtensionFieldNumber, 48);
Assert.AreEqual(Unittest.RepeatedNestedEnumExtensionFieldNumber, 51);
}
[TestMethod]
......
......@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
// We don't really need CLSCompliance, but if the assembly builds with no warnings,
// that means the generator is okay.
[assembly: CLSCompliant(true)]
\ No newline at end of file
[assembly: CLSCompliant(false)]
\ No newline at end of file
......@@ -82,14 +82,23 @@
<Compile Include="Compatibility\TextCompatibilityTests.cs" />
<Compile Include="Compatibility\XmlCompatibilityTests.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="TestRpcForMimeTypes.cs" />
<Compile Include="TestReaderForUrlEncoded.cs" />
<Compile Include="CSharpOptionsTest.cs" />
<Compile Include="DeprecatedMemberTest.cs" />
<Compile Include="DescriptorsTest.cs" />
<Compile Include="Descriptors\MessageDescriptorTest.cs" />
<Compile Include="DynamicMessageTest.cs" />
<Compile Include="ExtendableMessageTest.cs" />
<Compile Include="GeneratedBuilderTest.cs" />
......@@ -104,26 +113,8 @@
<Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableTest.cs" />
<Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.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="TestWriterFormatJson.cs" />
<Compile Include="TestWriterFormatXml.cs" />
......@@ -162,6 +153,7 @@
<EmbeddedResource Include="Compatibility\google_message1.dat" />
<EmbeddedResource Include="Compatibility\google_message2.dat" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
......
......@@ -97,10 +97,8 @@ namespace Google.ProtocolBuffers
this.extensionRegistry = extensionRegistry;
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);
// TODO(jonskeet): Find dependency by name instead of number?
this.importFile = file.Dependencies[1];
Assert.AreEqual(1, file.Dependencies.Count);
this.importFile = file.Dependencies[0];
MessageDescriptor testAllTypes;
if (baseDescriptor.Name == "TestAllTypes")
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Hosting;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
......@@ -20,6 +21,7 @@ namespace Google.ProtocolBuffers
public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder();
[TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
......@@ -53,6 +55,7 @@ namespace Google.ProtocolBuffers
}
[TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestMessageWithExtensions()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
......@@ -74,16 +77,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE)
.SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
.Build();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry);
UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, message);
......@@ -98,6 +101,7 @@ namespace Google.ProtocolBuffers
}
[TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainBuilder()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
......@@ -131,6 +135,7 @@ namespace Google.ProtocolBuffers
}
[TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestBuilderWithExtensions()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
......@@ -152,16 +157,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE)
.SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
;
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry);
UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream();
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.
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using Google.ProtocolBuffers;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers
{
/// <summary>
/// This class verifies the correct code is generated from unittest_rpc_interop.proto and provides a small demonstration
/// of using the new IRpcDispatch to write a client/server
/// </summary>
[TestClass]
public class TestRpcGenerator
{
/// <summary>
/// A sample implementation of the ISearchService for testing
/// </summary>
private class ExampleSearchImpl : ISearchService
{
SearchResponse ISearchService.Search(SearchRequest searchRequest)
{
if (searchRequest.CriteriaCount == 0)
{
throw new ArgumentException("No criteria specified.", new InvalidOperationException());
}
SearchResponse.Builder resp = SearchResponse.CreateBuilder();
foreach (string criteria in searchRequest.CriteriaList)
{
resp.AddResults(
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://search.com").
Build());
}
return resp.Build();
}
SearchResponse ISearchService.RefineSearch(RefineSearchRequest refineSearchRequest)
{
SearchResponse.Builder resp = refineSearchRequest.PreviousResults.ToBuilder();
foreach (string criteria in refineSearchRequest.CriteriaList)
{
resp.AddResults(
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://refine.com").
Build());
}
return resp.Build();
}
}
/// <summary>
/// An example extraction of the wire protocol
/// </summary>
private interface IWireTransfer
{
byte[] Execute(string method, byte[] message);
}
/// <summary>
/// An example of a server responding to a wire request
/// </summary>
private class ExampleServerHost : IWireTransfer
{
private readonly IRpcServerStub _stub;
public ExampleServerHost(ISearchService implementation)
{
//on the server, we create a dispatch to call the appropriate method by name
IRpcDispatch dispatch = new SearchService.Dispatch(implementation);
//we then wrap that dispatch in a server stub which will deserialize the wire bytes to the message
//type appropriate for the method name being invoked.
_stub = new SearchService.ServerStub(dispatch);
}
byte[] IWireTransfer.Execute(string method, byte[] message)
{
//now when we recieve a wire transmission to invoke a method by name with a byte[] or stream payload
//we just simply call the sub:
IMessageLite response = _stub.CallMethod(method, CodedInputStream.CreateInstance(message),
ExtensionRegistry.Empty);
//now we return the expected response message:
return response.ToByteArray();
}
}
/// <summary>
/// An example of a client sending a wire request
/// </summary>
private class ExampleClient : IRpcDispatch
{
private readonly IWireTransfer _wire;
public ExampleClient(IWireTransfer wire)
{
_wire = wire;
}
TMessage IRpcDispatch.CallMethod<TMessage, TBuilder>(string method, IMessageLite request,
IBuilderLite<TMessage, TBuilder> response)
{
byte[] rawResponse = _wire.Execute(method, request.ToByteArray());
response.MergeFrom(rawResponse);
return response.Build();
}
}
/// <summary>
/// Put it all together to create one seamless client/server experience full of rich-type goodness ;)
/// All you need to do is send/recieve the method name and message bytes across the wire.
/// </summary>
[TestMethod]
public void TestClientServerDispatch()
{
ExampleServerHost server = new ExampleServerHost(new ExampleSearchImpl());
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting
IWireTransfer wire = server;
ISearchService client = new SearchService(new ExampleClient(wire));
//now the client has a real, typed, interface to work with:
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build());
Assert.AreEqual(1, result.ResultsCount);
Assert.AreEqual("Test", result.ResultsList[0].Name);
Assert.AreEqual("http://search.com", result.ResultsList[0].Url);
//The test part of this, call the only other method
result =
client.RefineSearch(
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build());
Assert.AreEqual(2, result.ResultsCount);
Assert.AreEqual("Test", result.ResultsList[0].Name);
Assert.AreEqual("http://search.com", result.ResultsList[0].Url);
Assert.AreEqual("Refine", result.ResultsList[1].Name);
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url);
}
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -334,9 +334,9 @@ namespace Google.ProtocolBuffers
TestAllExtensions message =
TestAllExtensions.ParseFrom(data, TestUtil.CreateExtensionRegistry());
Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
message.GetExtension(UnitTestProtoFile.OptionalNestedEnumExtension));
message.GetExtension(Unittest.OptionalNestedEnumExtension));
TestUtil.AssertEqual(new[] {TestAllTypes.Types.NestedEnum.FOO, TestAllTypes.Types.NestedEnum.BAZ},
message.GetExtension(UnitTestProtoFile.RepeatedNestedEnumExtension));
message.GetExtension(Unittest.RepeatedNestedEnumExtension));
TestUtil.AssertEqual(new[] {5UL}, message.UnknownFields[singularField.FieldNumber].VarintList);
TestUtil.AssertEqual(new[] {4UL, 6UL}, message.UnknownFields[repeatedField.FieldNumber].VarintList);
}
......
......@@ -193,8 +193,8 @@ namespace Google.ProtocolBuffers
.SetMyInt(1)
.SetMyString("foo")
.SetMyFloat(1.0F)
.SetExtension(UnitTestProtoFile.MyExtensionInt, 23)
.SetExtension(UnitTestProtoFile.MyExtensionString, "bar")
.SetExtension(Unittest.MyExtensionInt, 23)
.SetExtension(Unittest.MyExtensionString, "bar")
.Build().ToByteString();
AssertFieldsInOrder(data);
......@@ -204,8 +204,8 @@ namespace Google.ProtocolBuffers
.SetField(descriptor.FindDescriptor<FieldDescriptor>("my_int"), 1L)
.SetField(descriptor.FindDescriptor<FieldDescriptor>("my_string"), "foo")
.SetField(descriptor.FindDescriptor<FieldDescriptor>("my_float"), 1.0F)
.SetField(UnitTestProtoFile.MyExtensionInt.Descriptor, 23)
.SetField(UnitTestProtoFile.MyExtensionString.Descriptor, "bar")
.SetField(Unittest.MyExtensionInt.Descriptor, 23)
.SetField(Unittest.MyExtensionString.Descriptor, "bar")
.WeakBuild().ToByteString();
AssertFieldsInOrder(dynamic_data);
}
......
......@@ -158,25 +158,6 @@ namespace Google.ProtocolBuffers.Descriptors
return File.DescriptorPool.FindFieldByNumber(this, number);
}
/// <summary>
/// Finds a field by its property name, as it would be generated by protogen.
/// </summary>
/// <param name="propertyName">The property name within this message type.</param>
/// <returns>The field's descriptor, or null if not found.</returns>
public FieldDescriptor FindFieldByPropertyName(string propertyName)
{
// For reasonably short messages, this will be more efficient than a dictionary
// lookup. It also means we don't need to do things lazily with locks etc.
foreach (FieldDescriptor field in Fields)
{
if (field.CSharpOptions.PropertyName == propertyName)
{
return field;
}
}
return null;
}
/// <summary>
/// Finds a nested descriptor by name. The is valid for fields, nested
/// message types and enums.
......
......@@ -68,7 +68,6 @@
<Compile Include="Collections\Dictionaries.cs" />
<Compile Include="Collections\Lists.cs" />
<Compile Include="Collections\ReadOnlyDictionary.cs" />
<Compile Include="DescriptorProtos\CSharpOptions.cs" />
<Compile Include="DescriptorProtos\DescriptorProtoFile.cs" />
<Compile Include="DescriptorProtos\IDescriptorProto.cs" />
<Compile Include="DescriptorProtos\PartialClasses.cs" />
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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