From 59eeebee870332ea2b9085688ba524c69311f662 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 17 Jul 2015 08:26:04 +0100 Subject: First pass at the big rename from ProtocolBuffers to Google.Protobuf. We'll see what I've missed when CI fails... --- .../Google.Protobuf.Test.csproj | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj new file mode 100644 index 00000000..6d8b4de2 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -0,0 +1,120 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {DD01ED24-3750-4567-9A23-1DB676A15610} + Library + Properties + Google.Protobuf + Google.Protobuf.Test + v4.5 + 512 + true + ..\..\keys\Google.Protobuf.snk + 3.5 + + + + + + + true + full + false + bin\Debug + obj\Debug\ + DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) + prompt + 4 + true + Off + false + + + pdbonly + true + bin\Release + obj\Release\ + TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) + prompt + 4 + true + Off + false + + + + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll + True + + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll + True + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll + True + + + ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {6908BDCE-D925-43F3-94AC-A531E6DF2591} + Google.Protobuf + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 20bf6a563a94e5772fdb7b1bd6530404b2ea2c0b Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 22 Jul 2015 15:14:38 +0100 Subject: First pass at making field access simpler. This is definitely not ready to ship - I'm "troubled" by the disconnect between a list of fields in declaration order, and a mapping of field accessors by field number/name. Discussion required, but I find that easier when we've got code to look at :) --- .../Google.Protobuf.Test/GeneratedMessageTest.cs | 160 --------------- .../Google.Protobuf.Test.csproj | 3 +- .../Reflection/DescriptorsTest.cs | 15 ++ .../Reflection/FieldAccessTest.cs | 218 +++++++++++++++++++++ .../WellKnownTypes/WrappersTest.cs | 6 +- .../Google.Protobuf/Reflection/FileDescriptor.cs | 2 +- .../Reflection/MessageDescriptor.cs | 80 +++++++- 7 files changed, 309 insertions(+), 175 deletions(-) create mode 100644 csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 180976d1..528a4023 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -597,165 +597,5 @@ namespace Google.Protobuf Assert.AreEqual(message, message2); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase); } - - // TODO: Consider moving these tests to a separate reflection test - although they do require generated messages. - - [Test] - public void Reflection_GetValue() - { - var message = SampleMessages.CreateFullTestAllTypes(); - var fields = TestAllTypes.Descriptor.FieldAccessorsByFieldNumber; - Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].GetValue(message)); - Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].GetValue(message)); - Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].GetValue(message)); - Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].GetValue(message)); - Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].GetValue(message)); - Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].GetValue(message)); - Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].GetValue(message)); - - // Just one example for repeated fields - they're all just returning the list - var list = (IList)fields[TestAllTypes.RepeatedInt32FieldNumber].GetValue(message); - Assert.AreEqual(message.RepeatedInt32, list); - Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt... - - // Just a single map field, for the same reason - var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } }; - fields = TestMap.Descriptor.FieldAccessorsByFieldNumber; - var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].GetValue(mapMessage); - Assert.AreEqual(mapMessage.MapStringString, dictionary); - Assert.AreEqual("value1", dictionary["key1"]); - } - - [Test] - public void Reflection_Clear() - { - var message = SampleMessages.CreateFullTestAllTypes(); - var fields = TestAllTypes.Descriptor.FieldAccessorsByFieldNumber; - fields[TestAllTypes.SingleBoolFieldNumber].Clear(message); - fields[TestAllTypes.SingleInt32FieldNumber].Clear(message); - fields[TestAllTypes.SingleStringFieldNumber].Clear(message); - fields[TestAllTypes.SingleBytesFieldNumber].Clear(message); - fields[TestAllTypes.SingleForeignEnumFieldNumber].Clear(message); - fields[TestAllTypes.SingleForeignMessageFieldNumber].Clear(message); - fields[TestAllTypes.RepeatedDoubleFieldNumber].Clear(message); - - var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes()) - { - SingleBool = false, - SingleInt32 = 0, - SingleString = "", - SingleBytes = ByteString.Empty, - SingleForeignEnum = 0, - SingleForeignMessage = null, - }; - expected.RepeatedDouble.Clear(); - - Assert.AreEqual(expected, message); - - // Separately, maps. - var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } }; - fields = TestMap.Descriptor.FieldAccessorsByFieldNumber; - fields[TestMap.MapStringStringFieldNumber].Clear(mapMessage); - Assert.AreEqual(0, mapMessage.MapStringString.Count); - } - - [Test] - public void Reflection_SetValue_SingleFields() - { - // Just a sample (primitives, messages, enums, strings, byte strings) - var message = SampleMessages.CreateFullTestAllTypes(); - var fields = TestAllTypes.Descriptor.FieldAccessorsByFieldNumber; - fields[TestAllTypes.SingleBoolFieldNumber].SetValue(message, false); - fields[TestAllTypes.SingleInt32FieldNumber].SetValue(message, 500); - fields[TestAllTypes.SingleStringFieldNumber].SetValue(message, "It's a string"); - fields[TestAllTypes.SingleBytesFieldNumber].SetValue(message, ByteString.CopyFrom(99, 98, 97)); - fields[TestAllTypes.SingleForeignEnumFieldNumber].SetValue(message, ForeignEnum.FOREIGN_FOO); - fields[TestAllTypes.SingleForeignMessageFieldNumber].SetValue(message, new ForeignMessage { C = 12345 }); - fields[TestAllTypes.SingleDoubleFieldNumber].SetValue(message, 20150701.5); - - var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes()) - { - SingleBool = false, - SingleInt32 = 500, - SingleString = "It's a string", - SingleBytes = ByteString.CopyFrom(99, 98, 97), - SingleForeignEnum = ForeignEnum.FOREIGN_FOO, - SingleForeignMessage = new ForeignMessage { C = 12345 }, - SingleDouble = 20150701.5 - }; - - Assert.AreEqual(expected, message); - } - - [Test] - public void Reflection_SetValue_SingleFields_WrongType() - { - IMessage message = SampleMessages.CreateFullTestAllTypes(); - var fields = message.Descriptor.FieldAccessorsByFieldNumber; - Assert.Throws(() => fields[TestAllTypes.SingleBoolFieldNumber].SetValue(message, "This isn't a bool")); - } - - [Test] - public void Reflection_SetValue_MapFields() - { - IMessage message = new TestMap(); - var fields = message.Descriptor.FieldAccessorsByFieldNumber; - Assert.Throws(() => fields[TestMap.MapStringStringFieldNumber].SetValue(message, new Dictionary())); - } - - [Test] - public void Reflection_SetValue_RepeatedFields() - { - IMessage message = SampleMessages.CreateFullTestAllTypes(); - var fields = message.Descriptor.FieldAccessorsByFieldNumber; - Assert.Throws(() => fields[TestAllTypes.RepeatedDoubleFieldNumber].SetValue(message, new double[10])); - } - - [Test] - public void Reflection_GetValue_IncorrectType() - { - IMessage message = SampleMessages.CreateFullTestAllTypes(); - var fields = message.Descriptor.FieldAccessorsByFieldNumber; - Assert.Throws(() => fields[TestAllTypes.SingleBoolFieldNumber].GetValue(new TestMap())); - } - - [Test] - public void Reflection_Oneof() - { - var message = new TestAllTypes(); - var descriptor = TestAllTypes.Descriptor; - Assert.AreEqual(1, descriptor.Oneofs.Count); - var oneof = descriptor.Oneofs[0]; - Assert.AreEqual("oneof_field", oneof.Name); - Assert.IsNull(oneof.Accessor.GetCaseFieldDescriptor(message)); - - message.OneofString = "foo"; - Assert.AreSame(descriptor.FieldAccessorsByFieldNumber[TestAllTypes.OneofStringFieldNumber].Descriptor, oneof.Accessor.GetCaseFieldDescriptor(message)); - - message.OneofUint32 = 10; - Assert.AreSame(descriptor.FieldAccessorsByFieldNumber[TestAllTypes.OneofUint32FieldNumber].Descriptor, oneof.Accessor.GetCaseFieldDescriptor(message)); - - oneof.Accessor.Clear(message); - Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); - } } } diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 6d8b4de2..2522901e 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -1,4 +1,4 @@ - + Debug @@ -82,6 +82,7 @@ + diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs index 0aff0a6c..ed4291a4 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -33,6 +33,7 @@ using System.Linq; using Google.Protobuf.TestProtos; using NUnit.Framework; +using UnitTest.Issues.TestProtos; namespace Google.Protobuf.Reflection { @@ -220,5 +221,19 @@ namespace Google.Protobuf.Reflection CollectionAssert.AreEquivalent(expectedFields, descriptor.Fields); } + + [Test] + public void ConstructionWithoutGeneratedCodeInfo() + { + var data = UnittestIssues.Descriptor.Proto.ToByteArray(); + var newDescriptor = Google.Protobuf.Reflection.FileDescriptor.InternalBuildGeneratedFileFrom(data, new Reflection.FileDescriptor[] { }, null); + + // We should still be able to get at a field... + var messageDescriptor = newDescriptor.FindTypeByName("ItemField"); + var fieldDescriptor = messageDescriptor.FindFieldByName("item"); + // But there shouldn't be an accessor (or a generated type for the message) + Assert.IsNull(fieldDescriptor.Accessor); + Assert.IsNull(messageDescriptor.GeneratedType); + } } } \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs new file mode 100644 index 00000000..5d6e777f --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs @@ -0,0 +1,218 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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.Protobuf.TestProtos; +using NUnit.Framework; +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Google.Protobuf.Reflection +{ + public class FieldAccessTest + { + [Test] + public void GetValue() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var fields = TestAllTypes.Descriptor.FieldAccessors; + Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].GetValue(message)); + Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].GetValue(message)); + Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].GetValue(message)); + Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].GetValue(message)); + Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].GetValue(message)); + Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].GetValue(message)); + Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].GetValue(message)); + + // Just one example for repeated fields - they're all just returning the list + var list = (IList) fields[TestAllTypes.RepeatedInt32FieldNumber].GetValue(message); + Assert.AreEqual(message.RepeatedInt32, list); + Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt... + + // Just a single map field, for the same reason + var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } }; + fields = TestMap.Descriptor.FieldAccessors; + var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].GetValue(mapMessage); + Assert.AreEqual(mapMessage.MapStringString, dictionary); + Assert.AreEqual("value1", dictionary["key1"]); + } + + [Test] + public void Clear() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var fields = TestAllTypes.Descriptor.FieldAccessors; + fields[TestAllTypes.SingleBoolFieldNumber].Clear(message); + fields[TestAllTypes.SingleInt32FieldNumber].Clear(message); + fields[TestAllTypes.SingleStringFieldNumber].Clear(message); + fields[TestAllTypes.SingleBytesFieldNumber].Clear(message); + fields[TestAllTypes.SingleForeignEnumFieldNumber].Clear(message); + fields[TestAllTypes.SingleForeignMessageFieldNumber].Clear(message); + fields[TestAllTypes.RepeatedDoubleFieldNumber].Clear(message); + + var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes()) + { + SingleBool = false, + SingleInt32 = 0, + SingleString = "", + SingleBytes = ByteString.Empty, + SingleForeignEnum = 0, + SingleForeignMessage = null, + }; + expected.RepeatedDouble.Clear(); + + Assert.AreEqual(expected, message); + + // Separately, maps. + var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } }; + fields = TestMap.Descriptor.FieldAccessors; + fields[TestMap.MapStringStringFieldNumber].Clear(mapMessage); + Assert.AreEqual(0, mapMessage.MapStringString.Count); + } + + [Test] + public void SetValue_SingleFields() + { + // Just a sample (primitives, messages, enums, strings, byte strings) + var message = SampleMessages.CreateFullTestAllTypes(); + var fields = TestAllTypes.Descriptor.FieldAccessors; + fields[TestAllTypes.SingleBoolFieldNumber].SetValue(message, false); + fields[TestAllTypes.SingleInt32FieldNumber].SetValue(message, 500); + fields[TestAllTypes.SingleStringFieldNumber].SetValue(message, "It's a string"); + fields[TestAllTypes.SingleBytesFieldNumber].SetValue(message, ByteString.CopyFrom(99, 98, 97)); + fields[TestAllTypes.SingleForeignEnumFieldNumber].SetValue(message, ForeignEnum.FOREIGN_FOO); + fields[TestAllTypes.SingleForeignMessageFieldNumber].SetValue(message, new ForeignMessage { C = 12345 }); + fields[TestAllTypes.SingleDoubleFieldNumber].SetValue(message, 20150701.5); + + var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes()) + { + SingleBool = false, + SingleInt32 = 500, + SingleString = "It's a string", + SingleBytes = ByteString.CopyFrom(99, 98, 97), + SingleForeignEnum = ForeignEnum.FOREIGN_FOO, + SingleForeignMessage = new ForeignMessage { C = 12345 }, + SingleDouble = 20150701.5 + }; + + Assert.AreEqual(expected, message); + } + + [Test] + public void SetValue_SingleFields_WrongType() + { + IMessage message = SampleMessages.CreateFullTestAllTypes(); + var fields = message.Descriptor.FieldAccessors; + Assert.Throws(() => fields[TestAllTypes.SingleBoolFieldNumber].SetValue(message, "This isn't a bool")); + } + + [Test] + public void SetValue_MapFields() + { + IMessage message = new TestMap(); + var fields = message.Descriptor.FieldAccessors; + Assert.Throws(() => fields[TestMap.MapStringStringFieldNumber].SetValue(message, new Dictionary())); + } + + [Test] + public void SetValue_RepeatedFields() + { + IMessage message = SampleMessages.CreateFullTestAllTypes(); + var fields = message.Descriptor.FieldAccessors; + Assert.Throws(() => fields[TestAllTypes.RepeatedDoubleFieldNumber].SetValue(message, new double[10])); + } + + [Test] + public void GetValue_IncorrectType() + { + IMessage message = SampleMessages.CreateFullTestAllTypes(); + var fields = message.Descriptor.FieldAccessors; + Assert.Throws(() => fields[TestAllTypes.SingleBoolFieldNumber].GetValue(new TestMap())); + } + + [Test] + public void Oneof() + { + var message = new TestAllTypes(); + var descriptor = TestAllTypes.Descriptor; + Assert.AreEqual(1, descriptor.Oneofs.Count); + var oneof = descriptor.Oneofs[0]; + Assert.AreEqual("oneof_field", oneof.Name); + Assert.IsNull(oneof.Accessor.GetCaseFieldDescriptor(message)); + + message.OneofString = "foo"; + Assert.AreSame(descriptor.FieldAccessors[TestAllTypes.OneofStringFieldNumber].Descriptor, oneof.Accessor.GetCaseFieldDescriptor(message)); + + message.OneofUint32 = 10; + Assert.AreSame(descriptor.FieldAccessors[TestAllTypes.OneofUint32FieldNumber].Descriptor, oneof.Accessor.GetCaseFieldDescriptor(message)); + + oneof.Accessor.Clear(message); + Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); + } + + [Test] + public void FieldAccessor_ByName() + { + var descriptor = TestAllTypes.Descriptor; + Assert.AreSame( + descriptor.FieldAccessors[TestAllTypes.SingleBoolFieldNumber], + descriptor.FieldAccessors["single_bool"]); + } + + [Test] + public void FieldAccessor_NotFound() + { + var descriptor = TestAllTypes.Descriptor; + Assert.Throws(() => descriptor.FieldAccessors[999999].ToString()); + Assert.Throws(() => descriptor.FieldAccessors["not found"].ToString()); + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs index c617db36..a8288483 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs @@ -192,7 +192,7 @@ namespace Google.Protobuf.WellKnownTypes Uint32Field = 3, Uint64Field = 4 }; - var fields = TestWellKnownTypes.Descriptor.FieldAccessorsByFieldNumber; + var fields = TestWellKnownTypes.Descriptor.FieldAccessors; Assert.AreEqual("x", fields[TestWellKnownTypes.StringFieldFieldNumber].GetValue(message)); Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), fields[TestWellKnownTypes.BytesFieldFieldNumber].GetValue(message)); @@ -216,7 +216,7 @@ namespace Google.Protobuf.WellKnownTypes { // Just a single example... note that we can't have a null value here var message = new RepeatedWellKnownTypes { Int32Field = { 1, 2 } }; - var fields = RepeatedWellKnownTypes.Descriptor.FieldAccessorsByFieldNumber; + var fields = RepeatedWellKnownTypes.Descriptor.FieldAccessors; var list = (IList) fields[RepeatedWellKnownTypes.Int32FieldFieldNumber].GetValue(message); CollectionAssert.AreEqual(new[] { 1, 2 }, list); } @@ -226,7 +226,7 @@ namespace Google.Protobuf.WellKnownTypes { // Just a single example... note that we can't have a null value here var message = new MapWellKnownTypes { Int32Field = { { 1, 2 }, { 3, null } } }; - var fields = MapWellKnownTypes.Descriptor.FieldAccessorsByFieldNumber; + var fields = MapWellKnownTypes.Descriptor.FieldAccessors; var dictionary = (IDictionary) fields[MapWellKnownTypes.Int32FieldFieldNumber].GetValue(message); Assert.AreEqual(2, dictionary[1]); Assert.IsNull(dictionary[3]); diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 041d4711..718c4797 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -231,7 +231,7 @@ namespace Google.Protobuf.Reflection /// Finds a type (message, enum, service or extension) in the file by name. Does not find nested types. /// /// The unqualified type name to look for. - /// The type of descriptor to look for (or ITypeDescriptor for any) + /// The type of descriptor to look for /// The type's descriptor, or null if not found. public T FindTypeByName(String name) where T : class, IDescriptor diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index b29b4b20..909a31ff 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -61,10 +61,10 @@ namespace Google.Protobuf.Reflection private readonly IList nestedTypes; private readonly IList enumTypes; private readonly IList fields; + private readonly FieldAccessorCollection fieldAccessors; private readonly IList oneofs; // CLR representation of the type described by this descriptor, if any. private readonly Type generatedType; - private IDictionary fieldAccessorsByFieldNumber; internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo) : base(file, file.ComputeFullName(parent, proto.Name), typeIndex) @@ -94,6 +94,7 @@ namespace Google.Protobuf.Reflection (field, index) => new FieldDescriptor(field, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.PropertyNames[index])); file.DescriptorPool.AddSymbol(this); + fieldAccessors = new FieldAccessorCollection(this); } /// @@ -135,14 +136,27 @@ namespace Google.Protobuf.Reflection get { return containingType; } } + // TODO: It's confusing that FieldAccessors[x] doesn't retrieve the accessor + // for Fields[x]. We should think about this further... how often does a user really + // want the fields in declaration order? + /// - /// An unmodifiable list of this message type's fields. + /// An unmodifiable list of this message type's fields, in the declaration order + /// within the .proto file. /// public IList Fields { get { return fields; } } + /// + /// A collection of accessors, which can be retrieved by name or field number. + /// + public FieldAccessorCollection FieldAccessors + { + get { return fieldAccessors; } + } + /// /// An unmodifiable list of this message type's nested types. /// @@ -164,13 +178,6 @@ namespace Google.Protobuf.Reflection get { return oneofs; } } - /// - /// Returns a map from field number to accessor. - /// TODO: Revisit this. It's mostly in place to make the transition from FieldAccessorTable - /// to descriptor-based reflection simple in terms of tests. Work out what we really want. - /// - public IDictionary FieldAccessorsByFieldNumber { get { return fieldAccessorsByFieldNumber; } } - /// /// Finds a field by field name. /// @@ -222,8 +229,61 @@ namespace Google.Protobuf.Reflection { oneof.CrossLink(); } + } + + /// + /// A collection to simplify retrieving the field accessor for a particular field. + /// + public sealed class FieldAccessorCollection + { + private readonly MessageDescriptor messageDescriptor; + + internal FieldAccessorCollection(MessageDescriptor messageDescriptor) + { + this.messageDescriptor = messageDescriptor; + } - fieldAccessorsByFieldNumber = new ReadOnlyDictionary(fields.ToDictionary(field => field.FieldNumber, field => field.Accessor)); + /// + /// Retrieves the accessor for the field with the given number. + /// + /// Number of the field to retrieve the accessor for + /// The accessor for the given field, or null if reflective field access is + /// not supported for the field. + /// The message descriptor does not contain a field + /// with the given number + public IFieldAccessor this[int number] + { + get + { + var fieldDescriptor = messageDescriptor.FindFieldByNumber(number); + if (fieldDescriptor == null) + { + throw new KeyNotFoundException("No such field number"); + } + return fieldDescriptor.Accessor; + } + } + + /// + /// Retrieves the accessor for the field with the given name. + /// + /// Number of the field to retrieve the accessor for + /// The accessor for the given field, or null if reflective field access is + /// not supported for the field. + /// The message descriptor does not contain a field + /// with the given name + public IFieldAccessor this[string name] + { + get + { + var fieldDescriptor = messageDescriptor.FindFieldByName(name); + if (fieldDescriptor == null) + { + throw new KeyNotFoundException("No such field name"); + } + return fieldDescriptor.Accessor; + } + } } } } \ No newline at end of file -- cgit v1.2.3 From 9ccc83990dd38765354172c879612fc3b8796553 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 28 Jul 2015 09:01:13 +0100 Subject: Humbug - previous commit didn't include project file changes :( --- csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj | 2 ++ 1 file changed, 2 insertions(+) (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 2522901e..fdae447e 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -75,6 +75,8 @@ + + -- cgit v1.2.3 From 9629797331e6859ce68c5489fc690d3526a3915a Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 30 Jul 2015 09:29:52 +0100 Subject: Well-known type operations for Timestamp and Duration (but not JSON formatting). While I've provided operators, I haven't yet provided the method equivalents. It's not clear to me that they're actually a good idea, while we're really targeting C# developers who definitely *can* use the user-defined operators. --- .../Google.Protobuf.Test.csproj | 2 + .../WellKnownTypes/DurationTest.cs | 104 +++++++++++++ .../WellKnownTypes/TimestampTest.cs | 84 +++++++++++ csharp/src/Google.Protobuf/Google.Protobuf.csproj | 3 + .../WellKnownTypes/DurationPartial.cs | 145 ++++++++++++++++++ .../WellKnownTypes/TimeExtensions.cs | 61 ++++++++ .../WellKnownTypes/TimestampPartial.cs | 164 +++++++++++++++++++++ 7 files changed, 563 insertions(+) create mode 100644 csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs create mode 100644 csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs create mode 100644 csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs create mode 100644 csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs create mode 100644 csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index fdae447e..eb6d3960 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -97,6 +97,8 @@ + + diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs new file mode 100644 index 00000000..36012e63 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs @@ -0,0 +1,104 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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 NUnit.Framework; +using System; + +namespace Google.Protobuf.WellKnownTypes +{ + public class DurationTest + { + [Test] + public void ToTimeSpan() + { + Assert.AreEqual(TimeSpan.FromSeconds(1), new Duration { Seconds = 1 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromSeconds(-1), new Duration { Seconds = -1 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromMilliseconds(1), new Duration { Nanos = 1000000 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromMilliseconds(-1), new Duration { Nanos = -1000000 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromTicks(1), new Duration { Nanos = 100 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromTicks(-1), new Duration { Nanos = -100 }.ToTimeSpan()); + + // Rounding is towards 0 + Assert.AreEqual(TimeSpan.FromTicks(2), new Duration { Nanos = 250 }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromTicks(-2), new Duration { Nanos = -250 }.ToTimeSpan()); + + // Non-normalized durations + Assert.AreEqual(TimeSpan.FromSeconds(3), new Duration { Seconds = 1, Nanos = 2 * Duration.NanosecondsPerSecond }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromSeconds(1), new Duration { Seconds = 3, Nanos = -2 * Duration.NanosecondsPerSecond }.ToTimeSpan()); + Assert.AreEqual(TimeSpan.FromSeconds(-1), new Duration { Seconds = 1, Nanos = -2 * Duration.NanosecondsPerSecond }.ToTimeSpan()); + } + + [Test] + public void Addition() + { + Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 }, + new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = 500000000 }); + Assert.AreEqual(new Duration { Seconds = -2, Nanos = -100000000 }, + new Duration { Seconds = -1, Nanos = -600000000 } + new Duration { Nanos = -500000000 }); + Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 }, + new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = -500000000 }); + + // Non-normalized durations, or non-normalized intermediate results + Assert.AreEqual(new Duration { Seconds = 1 }, + new Duration { Seconds = 1, Nanos = -500000000 } + new Duration { Nanos = 500000000 }); + + Assert.AreEqual(new Duration { Nanos = -900000000 }, + new Duration { Seconds = -1, Nanos = -100000000 } + new Duration { Nanos = 200000000 }); + Assert.AreEqual(new Duration { Nanos = 900000000 }, + new Duration { Seconds = 1, Nanos = 100000000 } + new Duration { Nanos = -200000000 }); + } + + [Test] + public void Subtraction() + { + Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 }, + new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = 500000000 }); + Assert.AreEqual(new Duration { Seconds = -1, Nanos = -100000000 }, + new Duration { Seconds = -1, Nanos = -600000000 } - new Duration { Nanos = -500000000 }); + Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 }, + new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = -500000000 }); + + // Non-normalized durations + Assert.AreEqual(new Duration(), + new Duration { Seconds = 1, Nanos = -500000000 } - new Duration { Nanos = 500000000 }); + Assert.AreEqual(new Duration { Seconds = 1 }, + new Duration { Nanos = 2000000000 } - new Duration { Nanos = 1000000000 }); + } + + [Test] + public void FromTimeSpan() + { + Assert.AreEqual(new Duration { Seconds = 1 }, Duration.FromTimeSpan(TimeSpan.FromSeconds(1))); + Assert.AreEqual(new Duration { Nanos = Duration.NanosecondsPerTick }, Duration.FromTimeSpan(TimeSpan.FromTicks(1))); + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs new file mode 100644 index 00000000..597539eb --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs @@ -0,0 +1,84 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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 NUnit.Framework; +using System; + +namespace Google.Protobuf.WellKnownTypes +{ + public class TimestampTest + { + [Test] + public void FromAndToDateTime() + { + DateTime utcMin = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); + DateTime utcMax = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc); + AssertRoundtrip(new Timestamp { Seconds = -62135596800 }, utcMin); + AssertRoundtrip(new Timestamp { Seconds = 253402300799, Nanos = 999999900 }, utcMax); + AssertRoundtrip(new Timestamp(), new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)); + AssertRoundtrip(new Timestamp { Nanos = 1000000}, new DateTime(1970, 1, 1, 0, 0, 0, 1, DateTimeKind.Utc)); + AssertRoundtrip(new Timestamp { Seconds = -1, Nanos = 999000000 }, new DateTime(1969, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc)); + AssertRoundtrip(new Timestamp { Seconds = 3600 }, new DateTime(1970, 1, 1, 1, 0, 0, DateTimeKind.Utc)); + AssertRoundtrip(new Timestamp { Seconds = -3600 }, new DateTime(1969, 12, 31, 23, 0, 0, DateTimeKind.Utc)); + } + + [Test] + public void ToDateTimeTruncation() + { + var t1 = new Timestamp { Seconds = 1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 }; + Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc).AddMilliseconds(1), t1.ToDateTime()); + + var t2 = new Timestamp { Seconds = -1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 }; + Assert.AreEqual(new DateTime(1969, 12, 31, 23, 59, 59).AddMilliseconds(1), t2.ToDateTime()); + } + + private static void AssertRoundtrip(Timestamp timestamp, DateTime dateTime) + { + Assert.AreEqual(timestamp, Timestamp.FromDateTime(dateTime)); + Assert.AreEqual(dateTime, timestamp.ToDateTime()); + Assert.AreEqual(DateTimeKind.Utc, timestamp.ToDateTime().Kind); + } + + [Test] + public void Arithmetic() + { + Timestamp t1 = new Timestamp { Seconds = 10000, Nanos = 5000 }; + Timestamp t2 = new Timestamp { Seconds = 8000, Nanos = 10000 }; + Duration difference = new Duration { Seconds = 1999, Nanos = Duration.NanosecondsPerSecond - 5000 }; + Assert.AreEqual(difference, t1 - t2); + Assert.AreEqual(-difference, t2 - t1); + + Assert.AreEqual(t1, t2 + difference); + Assert.AreEqual(t2, t1 - difference); + } + } +} diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 7de4f51b..c7038eb4 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -100,11 +100,14 @@ + + + diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs new file mode 100644 index 00000000..c69d1b23 --- /dev/null +++ b/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs @@ -0,0 +1,145 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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; + +namespace Google.Protobuf.WellKnownTypes +{ + // Manually-written partial class for the Duration well-known type, + // providing a conversion to TimeSpan and convenience operators. + public partial class Duration + { + public const int NanosecondsPerSecond = 1000000000; + public const int NanosecondsPerTick = 100; + + /// + /// Converts this to a . + /// + /// If the duration is not a precise number of ticks, it is truncated towards 0. + /// The value of this duration, as a TimeSpan. + public TimeSpan ToTimeSpan() + { + checked + { + long ticks = Seconds * TimeSpan.TicksPerSecond + Nanos / NanosecondsPerTick; + return TimeSpan.FromTicks(ticks); + } + } + + /// + /// Converts the given to a . + /// + /// The TimeSpan to convert. + /// The value of the given TimeSpan, as a Duration. + public static Duration FromTimeSpan(TimeSpan timeSpan) + { + checked + { + long ticks = timeSpan.Ticks; + long seconds = ticks / TimeSpan.TicksPerSecond; + int nanos = (int) (ticks % TimeSpan.TicksPerSecond) * NanosecondsPerTick; + return new Duration { Seconds = seconds, Nanos = nanos }; + } + } + + /// + /// Returns the result of negating the duration. For example, the negation of 5 minutes is -5 minutes. + /// + /// The duration to negate. Must not be null. + /// The negated value of this duration. + public static Duration operator -(Duration value) + { + Preconditions.CheckNotNull(value, "value"); + checked + { + return Normalize(-value.Seconds, -value.Nanos); + } + } + + /// + /// Adds the two specified values together. + /// + /// The first value to add. Must not be null. + /// The second value to add. Must not be null. + /// + public static Duration operator +(Duration lhs, Duration rhs) + { + Preconditions.CheckNotNull(lhs, "lhs"); + Preconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos); + } + } + + /// + /// Subtracts one from another. + /// + /// The duration to subtract from. Must not be null. + /// The duration to subtract. Must not be null. + /// The difference between the two specified durations. + public static Duration operator -(Duration lhs, Duration rhs) + { + Preconditions.CheckNotNull(lhs, "lhs"); + Preconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Creates a duration with the normalized values from the given number of seconds and + /// nanoseconds, conforming with the description in the proto file. + /// + internal static Duration Normalize(long seconds, int nanoseconds) + { + // Ensure that nanoseconds is in the range (-1,000,000,000, +1,000,000,000) + int extraSeconds = nanoseconds / NanosecondsPerSecond; + seconds += extraSeconds; + nanoseconds -= extraSeconds * NanosecondsPerSecond; + + // Now make sure that Sign(seconds) == Sign(nanoseconds) if Sign(seconds) != 0. + if (seconds < 0 && nanoseconds > 0) + { + seconds += 1; + nanoseconds -= NanosecondsPerSecond; + } + else if (seconds > 0 && nanoseconds < 0) + { + seconds -= 1; + nanoseconds += NanosecondsPerSecond; + } + return new Duration { Seconds = seconds, Nanos = nanoseconds }; + } + } +} diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs b/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs new file mode 100644 index 00000000..a3806b5c --- /dev/null +++ b/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs @@ -0,0 +1,61 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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 System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Protobuf.WellKnownTypes +{ + /// + /// Extension methods on BCL time-related types, converting to protobuf types. + /// + public static class TimeExtensions + { + public static Timestamp ToTimestamp(this DateTime dateTime) + { + return Timestamp.FromDateTime(dateTime); + } + + public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset) + { + return Timestamp.FromDateTimeOffset(dateTimeOffset); + } + + public static Duration ToDuration(this TimeSpan timeSpan) + { + return Duration.FromTimeSpan(timeSpan); + } + } +} diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs new file mode 100644 index 00000000..f682d093 --- /dev/null +++ b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs @@ -0,0 +1,164 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// 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; + +namespace Google.Protobuf.WellKnownTypes +{ + public partial class Timestamp + { + private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private static readonly long BclSecondsAtUnixEpoch = UnixEpoch.Ticks / TimeSpan.TicksPerSecond; + + /// + /// Returns the difference between one and another, as a . + /// + /// The timestamp to subtract from. Must not be null. + /// The timestamp to subtract. Must not be null. + /// The difference between the two specified timestamps. + public static Duration operator -(Timestamp lhs, Timestamp rhs) + { + Preconditions.CheckNotNull(lhs, "lhs"); + Preconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Adds a to a , to obtain another Timestamp. + /// + /// The timestamp to add the duration to. Must not be null. + /// The duration to add. Must not be null. + /// The result of adding the duration to the timestamp. + public static Timestamp operator +(Timestamp lhs, Duration rhs) + { + Preconditions.CheckNotNull(lhs, "lhs"); + Preconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos); + } + } + + /// + /// Subtracts a from a , to obtain another Timestamp. + /// + /// The timestamp to subtract the duration from. Must not be null. + /// The duration to subtract. + /// The result of subtracting the duration from the timestamp. + public static Timestamp operator -(Timestamp lhs, Duration rhs) + { + Preconditions.CheckNotNull(lhs, "lhs"); + Preconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Converts this timestamp into a . + /// + /// + /// The resulting DateTime will always have a Kind of Utc. + /// If the timestamp is not a precise number of ticks, it will be truncated towards the start + /// of time. For example, a timestamp with a value of 99 will result in a + /// value precisely on a second. + /// + /// This timestamp as a DateTime. + public DateTime ToDateTime() + { + return UnixEpoch.AddSeconds(Seconds).AddTicks(Nanos / Duration.NanosecondsPerTick); + } + + /// + /// Converts this timestamp into a . + /// + /// + /// The resulting DateTimeOffset will always have an Offset of zero. + /// If the timestamp is not a precise number of ticks, it will be truncated towards the start + /// of time. For example, a timestamp with a value of 99 will result in a + /// value precisely on a second. + /// + /// This timestamp as a DateTimeOffset. + public DateTimeOffset ToDateTimeOffset() + { + return new DateTimeOffset(ToDateTime(), TimeSpan.Zero); + } + + /// + /// Converts the specified to a . + /// + /// + /// The Kind of is not DateTimeKind.Utc. + /// The converted timestamp. + public static Timestamp FromDateTime(DateTime dateTime) + { + if (dateTime.Kind != DateTimeKind.Utc) + { + throw new ArgumentException("Conversion from DateTime to Timestamp requires the DateTime kind to be Utc", "dateTime"); + } + // Do the arithmetic using DateTime.Ticks, which is always non-negative, making things simpler. + long secondsSinceBclEpoch = dateTime.Ticks / TimeSpan.TicksPerSecond; + int nanoseconds = (int) (dateTime.Ticks % TimeSpan.TicksPerSecond) * Duration.NanosecondsPerTick; + return new Timestamp { Seconds = secondsSinceBclEpoch - BclSecondsAtUnixEpoch, Nanos = nanoseconds }; + } + + /// + /// Converts the specified to a . + /// + /// + /// The converted timestamp. + public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset) + { + // We don't need to worry about this having negative ticks: DateTimeOffset is constrained to handle + // values whose *UTC* value is in the range of DateTime. + return FromDateTime(dateTimeOffset.UtcDateTime); + } + + private static Timestamp Normalize(long seconds, int nanoseconds) + { + int extraSeconds = nanoseconds / Duration.NanosecondsPerSecond; + seconds += extraSeconds; + nanoseconds -= extraSeconds * Duration.NanosecondsPerSecond; + + if (nanoseconds < 0) + { + nanoseconds += Duration.NanosecondsPerSecond; + seconds--; + } + return new Timestamp { Seconds = seconds, Nanos = nanoseconds }; + } + } +} -- cgit v1.2.3 From 538ef54f1e9ff218d9134927a17cb3a8703358b1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 29 Jul 2015 20:35:07 -0700 Subject: build signed assemblies --- csharp/buildall.sh | 1 - csharp/keys/Google.Protobuf.public.snk | Bin 0 -> 160 bytes csharp/keys/Google.Protobuf.snk | Bin 596 -> 0 bytes csharp/keys/README.md | 5 +++++ csharp/keys/generate_new_key.bat | 13 ------------- csharp/src/AddressBook/AddressBook.csproj | 14 ++++++++++++++ csharp/src/AddressBook/Properties/AssemblyInfo.cs | 6 +++--- .../Google.Protobuf.JsonDump.csproj | 14 ++++++++++++++ .../Properties/AssemblyInfo.cs | 6 +++--- .../Google.Protobuf.Test/Google.Protobuf.Test.csproj | 14 ++++++++++++++ .../Google.Protobuf.Test/Properties/AssemblyInfo.cs | 4 ++-- csharp/src/Google.Protobuf.sln | 13 +++++++++++-- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 15 +++++++++++++++ csharp/src/Google.Protobuf/Google.Protobuf.nuspec | 10 +++++----- csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs | 18 +++++++++++------- 15 files changed, 97 insertions(+), 36 deletions(-) create mode 100644 csharp/keys/Google.Protobuf.public.snk delete mode 100644 csharp/keys/Google.Protobuf.snk create mode 100644 csharp/keys/README.md delete mode 100644 csharp/keys/generate_new_key.bat (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/buildall.sh b/csharp/buildall.sh index d903c1ca..45af705f 100755 --- a/csharp/buildall.sh +++ b/csharp/buildall.sh @@ -6,7 +6,6 @@ NUNIT_CONSOLE=nunit-console # The rest you can leave intact CONFIG=Release -KEYFILE=../keys/Google.Protobuf.snk # TODO(jtattermusch): signing! SRC=$(dirname $0)/src set -ex diff --git a/csharp/keys/Google.Protobuf.public.snk b/csharp/keys/Google.Protobuf.public.snk new file mode 100644 index 00000000..59cd3698 Binary files /dev/null and b/csharp/keys/Google.Protobuf.public.snk differ diff --git a/csharp/keys/Google.Protobuf.snk b/csharp/keys/Google.Protobuf.snk deleted file mode 100644 index 6bbfc90f..00000000 Binary files a/csharp/keys/Google.Protobuf.snk and /dev/null differ diff --git a/csharp/keys/README.md b/csharp/keys/README.md new file mode 100644 index 00000000..1a014198 --- /dev/null +++ b/csharp/keys/README.md @@ -0,0 +1,5 @@ +Contents +-------- + +- Google.Protobuf.public.snk: + Public key to verify strong name of Google.Protobuf assemblies. \ No newline at end of file diff --git a/csharp/keys/generate_new_key.bat b/csharp/keys/generate_new_key.bat deleted file mode 100644 index 6af599a1..00000000 --- a/csharp/keys/generate_new_key.bat +++ /dev/null @@ -1,13 +0,0 @@ -@ECHO OFF -IF EXIST "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\sn.exe" GOTO FOUND -goto USEPATH - -:FOUND -"C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\sn.exe" -k %~dp0\Google.Protobuf.snk -GOTO EXIT - -:USEPATH -sn.exe -k %~dp0\Google.Protobuf.snk -GOTO EXIT - -:EXIT \ No newline at end of file diff --git a/csharp/src/AddressBook/AddressBook.csproj b/csharp/src/AddressBook/AddressBook.csproj index 8f8ca7e2..39df2bd3 100644 --- a/csharp/src/AddressBook/AddressBook.csproj +++ b/csharp/src/AddressBook/AddressBook.csproj @@ -41,6 +41,20 @@ Off false + + pdbonly + true + bin\ReleaseSigned + obj\ReleaseSigned\ + TRACE + prompt + 4 + true + Off + false + True + C:\keys\Google.Protobuf.snk + diff --git a/csharp/src/AddressBook/Properties/AssemblyInfo.cs b/csharp/src/AddressBook/Properties/AssemblyInfo.cs index e9c40dce..65e2f9cc 100644 --- a/csharp/src/AddressBook/Properties/AssemblyInfo.cs +++ b/csharp/src/AddressBook/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("AddressBook")] -[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -25,5 +25,5 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("2.4.1.555")] -[assembly: AssemblyVersion("2.4.1.555")] -[assembly: AssemblyFileVersion("2.4.1.555")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.0.1")] +[assembly: AssemblyFileVersion("3.0.0.1")] \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj index ede1f778..233bd0af 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj +++ b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj @@ -40,6 +40,20 @@ Off false + + pdbonly + true + bin\ReleaseSigned + obj\ReleaseSigned\ + TRACE + prompt + 4 + true + Off + false + True + C:\keys\Google.Protobuf.snk + diff --git a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs index a8ce8eae..126db6ba 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ProtoDump")] -[assembly: AssemblyCopyright("Copyright © 2009")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -26,5 +26,5 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("2.4.1.555")] -[assembly: AssemblyVersion("2.4.1.555")] -[assembly: AssemblyFileVersion("2.4.1.555")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.0.1")] +[assembly: AssemblyFileVersion("3.0.0.1")] \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index eb6d3960..5805f494 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -45,6 +45,20 @@ Off false + + pdbonly + true + bin\ReleaseSigned + obj\ReleaseSigned\ + TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) + prompt + 4 + true + Off + false + True + C:\keys\Google.Protobuf.snk + diff --git a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs index b551388c..197ea809 100644 --- a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Google.Protobuf.Test")] -[assembly: AssemblyCopyright("Copyright � 2008")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -27,4 +27,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("2.4.1.555")] -[assembly: AssemblyVersion("2.4.1.555")] +[assembly: AssemblyVersion("3.0.0.1")] diff --git a/csharp/src/Google.Protobuf.sln b/csharp/src/Google.Protobuf.sln index a290ae82..85f2bd4b 100644 --- a/csharp/src/Google.Protobuf.sln +++ b/csharp/src/Google.Protobuf.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.22823.1 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{6908BDCE-D925-43F3-94AC-A531E6DF2591}" EndProject @@ -14,24 +14,33 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + ReleaseSigned|Any CPU = ReleaseSigned|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.Build.0 = Debug|Any CPU {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU + {6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU + {6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU {DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU {DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU + {DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU + {DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.Build.0 = Debug|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.ActiveCfg = Release|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.Build.0 = Release|Any CPU + {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU + {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU + {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU + {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index c7038eb4..2784d9b2 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -46,6 +46,21 @@ true Off + + pdbonly + true + bin\ReleaseSigned + obj\ReleaseSigned\ + $(OutputPath)\$(AssemblyName).xml + 1591, 1570, 1571, 1572, 1573, 1574 + TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);SIGNED + prompt + 4 + true + Off + True + C:\keys\Google.Protobuf.snk + diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec index 09ec5cf0..fcfe4103 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec +++ b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec @@ -5,20 +5,20 @@ Google Protocol Buffers C# C# runtime library for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.0.0-beta* + 3.0.0-alpha4 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE https://github.com/google/protobuf false - Experimental version of C# Protocol Buffers + C# Protocol Buffers Copyright 2015, Google Inc. Protocol Buffers Binary Serialization Format Google proto proto3 - - - + + + diff --git a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs index a957e8b3..c1bca8d8 100644 --- a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs @@ -42,7 +42,7 @@ using System.Runtime.CompilerServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Google.Protobuf")] -[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -59,14 +59,18 @@ using System.Runtime.CompilerServices; [assembly: AssemblyVersion("2.4.1.555")] +#if SIGNED [assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" + - "00240000048000009400000006020000002400005253413100040000110000003b4611704c5379" + - "39c3e0fbe9447dd6fa5462507f9dd4fd9fbf0712457e415b037da6d2c4eb5d2c7d29c86380af68" + - "7cf400401bb183f2a70bd3b631c1fcb7db8aa66c766694a9fb53fa765df6303104da8c978f3b6d" + - "53909cd30685b8bc9922c726cd82b5995e9e2cfca6df7a2d189d851492e49f4b76f269ce6dfd08" + - "c34a7d98")] + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + + "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" + + "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + + "c5ae9cb6")] +#else +[assembly: InternalsVisibleTo("Google.Protobuf.Test")] +#endif #if !NOFILEVERSION -[assembly: AssemblyFileVersion("2.4.1.555")] +[assembly: AssemblyFileVersion("3.0.0.1")] #endif -- cgit v1.2.3 From d331d2f60fdce61ee81c3ab4ad66ba6d7e72cdd9 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sun, 2 Aug 2015 01:05:00 -0700 Subject: make changes and fixes in signing --- csharp/src/AddressBook/AddressBook.csproj | 14 -------------- csharp/src/AddressBook/Properties/AssemblyInfo.cs | 15 ++------------- .../Google.Protobuf.JsonDump.csproj | 14 -------------- .../Properties/AssemblyInfo.cs | 15 ++------------- .../Google.Protobuf.Test/Google.Protobuf.Test.csproj | 2 -- .../Google.Protobuf.Test/Properties/AssemblyInfo.cs | 14 ++------------ csharp/src/Google.Protobuf.sln | 8 ++++---- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 8 +++----- csharp/src/Google.Protobuf/Google.Protobuf.nuspec | 2 -- .../src/Google.Protobuf/Properties/AssemblyInfo.cs | 20 +++----------------- 10 files changed, 16 insertions(+), 96 deletions(-) (limited to 'csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj') diff --git a/csharp/src/AddressBook/AddressBook.csproj b/csharp/src/AddressBook/AddressBook.csproj index 39df2bd3..8f8ca7e2 100644 --- a/csharp/src/AddressBook/AddressBook.csproj +++ b/csharp/src/AddressBook/AddressBook.csproj @@ -41,20 +41,6 @@ Off false - - pdbonly - true - bin\ReleaseSigned - obj\ReleaseSigned\ - TRACE - prompt - 4 - true - Off - false - True - C:\keys\Google.Protobuf.snk - diff --git a/csharp/src/AddressBook/Properties/AssemblyInfo.cs b/csharp/src/AddressBook/Properties/AssemblyInfo.cs index 65e2f9cc..9cb014c0 100644 --- a/csharp/src/AddressBook/Properties/AssemblyInfo.cs +++ b/csharp/src/AddressBook/Properties/AssemblyInfo.cs @@ -14,16 +14,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("2.4.1.555")] - -[assembly: AssemblyVersion("3.0.0.1")] -[assembly: AssemblyFileVersion("3.0.0.1")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj index 233bd0af..ede1f778 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj +++ b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj @@ -40,20 +40,6 @@ Off false - - pdbonly - true - bin\ReleaseSigned - obj\ReleaseSigned\ - TRACE - prompt - 4 - true - Off - false - True - C:\keys\Google.Protobuf.snk - diff --git a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs index 126db6ba..d980b013 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs @@ -15,16 +15,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("2.4.1.555")] - -[assembly: AssemblyVersion("3.0.0.1")] -[assembly: AssemblyFileVersion("3.0.0.1")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 5805f494..d9593828 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -12,8 +12,6 @@ Google.Protobuf.Test v4.5 512 - true - ..\..\keys\Google.Protobuf.snk 3.5 diff --git a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs index 197ea809..d00acf85 100644 --- a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs @@ -16,15 +16,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("2.4.1.555")] - -[assembly: AssemblyVersion("3.0.0.1")] +[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.sln b/csharp/src/Google.Protobuf.sln index 85f2bd4b..fef7a7f1 100644 --- a/csharp/src/Google.Protobuf.sln +++ b/csharp/src/Google.Protobuf.sln @@ -33,14 +33,14 @@ Global {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.Build.0 = Debug|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.ActiveCfg = Release|Any CPU {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.Build.0 = Release|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU + {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU + {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU + {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU + {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 2784d9b2..8a19067a 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -14,8 +14,6 @@ Profile259 v4.5 512 - true - ..\..\keys\Google.Protobuf.snk 3.5 10.0 @@ -27,7 +25,7 @@ obj\Debug\ bin\Debug\Google.Protobuf.xml 1591, 1570, 1571, 1572, 1573, 1574 - DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) + DEBUG;TRACE prompt 4 true @@ -40,7 +38,7 @@ obj\Release\ $(OutputPath)\$(AssemblyName).xml 1591, 1570, 1571, 1572, 1573, 1574 - TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) + TRACE prompt 4 true @@ -53,7 +51,7 @@ obj\ReleaseSigned\ $(OutputPath)\$(AssemblyName).xml 1591, 1570, 1571, 1572, 1573, 1574 - TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);SIGNED + TRACE;SIGNED prompt 4 true diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec index 1f502626..228457a3 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec +++ b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec @@ -23,7 +23,6 @@ - @@ -33,6 +32,5 @@ - diff --git a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs index c1bca8d8..73a78b01 100644 --- a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs @@ -46,19 +46,6 @@ using System.Runtime.CompilerServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("2.4.1.555")] - -[assembly: AssemblyVersion("2.4.1.555")] - #if SIGNED [assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + @@ -70,7 +57,6 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Google.Protobuf.Test")] #endif -#if !NOFILEVERSION -[assembly: AssemblyFileVersion("3.0.0.1")] -#endif - +[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyFileVersion("3.0.0.0")] +[assembly: AssemblyInformationalVersion("3.0.0-alpha4")] -- cgit v1.2.3