From 8cf53f8dfca43b0347efcc1052033c96aa3f626c Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 10 Nov 2017 09:50:47 +0000 Subject: [PATCH] MMinor fix-ups to C# tests from changes in earlier commits --- .../Google.Protobuf.Test/JsonFormatterTest.cs | 6 ++-- .../Google.Protobuf.Test/JsonParserTest.cs | 4 +-- .../Reflection/DescriptorsTest.cs | 34 ++++++++++++------- .../WellKnownTypes/AnyTest.cs | 6 ++-- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 53ac3dc9be..1c7a8cdf24 100644 --- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -514,7 +514,7 @@ namespace Google.Protobuf var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor))); var message = new TestAllTypes { SingleInt32 = 10, SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 } }; var any = Any.Pack(message); - AssertJson("{ '@type': 'type.googleapis.com/protobuf_unittest.TestAllTypes', 'singleInt32': 10, 'singleNestedMessage': { 'bb': 20 } }", formatter.Format(any)); + AssertJson("{ '@type': 'type.googleapis.com/protobuf_unittest3.TestAllTypes', 'singleInt32': 10, 'singleNestedMessage': { 'bb': 20 } }", formatter.Format(any)); } [Test] @@ -523,7 +523,7 @@ namespace Google.Protobuf var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor))); var message = new TestAllTypes { SingleInt32 = 10 }; var any = Any.Pack(message, "foo.bar/baz"); - AssertJson("{ '@type': 'foo.bar/baz/protobuf_unittest.TestAllTypes', 'singleInt32': 10 }", formatter.Format(any)); + AssertJson("{ '@type': 'foo.bar/baz/protobuf_unittest3.TestAllTypes', 'singleInt32': 10 }", formatter.Format(any)); } [Test] @@ -536,7 +536,7 @@ namespace Google.Protobuf var doubleNestedMessage = new TestAllTypes { SingleInt32 = 20 }; var nestedMessage = Any.Pack(doubleNestedMessage); var message = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) }; - AssertJson("{ 'anyField': { '@type': 'type.googleapis.com/google.protobuf.Any', 'value': { '@type': 'type.googleapis.com/protobuf_unittest.TestAllTypes', 'singleInt32': 20 } } }", + AssertJson("{ 'anyField': { '@type': 'type.googleapis.com/google.protobuf.Any', 'value': { '@type': 'type.googleapis.com/protobuf_unittest3.TestAllTypes', 'singleInt32': 20 } } }", formatter.Format(message)); } diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 2c515433c2..329ae9be49 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -809,7 +809,7 @@ namespace Google.Protobuf var json = formatter.Format(original); // This is tested in JsonFormatterTest var parser = new JsonParser(new JsonParser.Settings(10, registry)); Assert.AreEqual(original, parser.Parse(json)); - string valueFirstJson = "{ \"singleInt32\": 10, \"singleNestedMessage\": { \"bb\": 20 }, \"@type\": \"type.googleapis.com/protobuf_unittest.TestAllTypes\" }"; + string valueFirstJson = "{ \"singleInt32\": 10, \"singleNestedMessage\": { \"bb\": 20 }, \"@type\": \"type.googleapis.com/protobuf_unittest3.TestAllTypes\" }"; Assert.AreEqual(original, parser.Parse(valueFirstJson)); } @@ -820,7 +820,7 @@ namespace Google.Protobuf var message = new TestAllTypes { SingleInt32 = 10 }; var original = Any.Pack(message, "custom.prefix/middle-part"); var parser = new JsonParser(new JsonParser.Settings(10, registry)); - string json = "{ \"@type\": \"custom.prefix/middle-part/protobuf_unittest.TestAllTypes\", \"singleInt32\": 10 }"; + string json = "{ \"@type\": \"custom.prefix/middle-part/protobuf_unittest3.TestAllTypes\", \"singleInt32\": 10 }"; Assert.AreEqual(original, parser.Parse(json)); } diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs index 52d5a67697..29a376e049 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -48,13 +48,13 @@ namespace Google.Protobuf.Reflection { FileDescriptor file = UnittestProto3Reflection.Descriptor; - Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Name); - Assert.AreEqual("protobuf_unittest", file.Package); + Assert.AreEqual("unittest_proto3.proto", file.Name); + Assert.AreEqual("protobuf_unittest3", file.Package); Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname); - Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Proto.Name); + Assert.AreEqual("unittest_proto3.proto", file.Proto.Name); - // unittest.proto doesn't have any public imports, but unittest_import.proto does. + // unittest_proto3.proto doesn't have any public imports, but unittest_import_proto3.proto does. Assert.AreEqual(0, file.PublicDependencies.Count); Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.PublicDependencies.Count); Assert.AreEqual(UnittestImportPublicProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor.PublicDependencies[0]); @@ -68,7 +68,7 @@ namespace Google.Protobuf.Reflection Assert.AreEqual(messageType, file.MessageTypes[0]); Assert.AreEqual(messageType, file.FindTypeByName("TestAllTypes")); Assert.Null(file.FindTypeByName("NoSuchType")); - Assert.Null(file.FindTypeByName("protobuf_unittest.TestAllTypes")); + Assert.Null(file.FindTypeByName("protobuf_unittest3.TestAllTypes")); for (int i = 0; i < file.MessageTypes.Count; i++) { Assert.AreEqual(i, file.MessageTypes[i].Index); @@ -76,7 +76,7 @@ namespace Google.Protobuf.Reflection Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName("ForeignEnum")); Assert.Null(file.FindTypeByName("NoSuchType")); - Assert.Null(file.FindTypeByName("protobuf_unittest.ForeignEnum")); + Assert.Null(file.FindTypeByName("protobuf_unittest3.ForeignEnum")); Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.EnumTypes.Count); Assert.AreEqual("ImportEnum", UnittestImportProto3Reflection.Descriptor.EnumTypes[0].Name); for (int i = 0; i < file.EnumTypes.Count; i++) @@ -87,6 +87,16 @@ namespace Google.Protobuf.Reflection Assert.AreEqual(10, file.SerializedData[0]); } + [Test] + public void FileDescriptor_NonRootPath() + { + // unittest_proto3.proto used to be in google/protobuf. Now it's in the C#-specific location, + // let's test something that's still in a directory. + FileDescriptor file = UnittestWellKnownTypesReflection.Descriptor; + Assert.AreEqual("google/protobuf/unittest_well_known_types.proto", file.Name); + Assert.AreEqual("protobuf_unittest", file.Package); + } + [Test] public void MessageDescriptor() { @@ -94,7 +104,7 @@ namespace Google.Protobuf.Reflection MessageDescriptor nestedType = TestAllTypes.Types.NestedMessage.Descriptor; Assert.AreEqual("TestAllTypes", messageType.Name); - Assert.AreEqual("protobuf_unittest.TestAllTypes", messageType.FullName); + Assert.AreEqual("protobuf_unittest3.TestAllTypes", messageType.FullName); Assert.AreEqual(UnittestProto3Reflection.Descriptor, messageType.File); Assert.IsNull(messageType.ContainingType); Assert.IsNull(messageType.Proto.Options); @@ -102,7 +112,7 @@ namespace Google.Protobuf.Reflection Assert.AreEqual("TestAllTypes", messageType.Name); Assert.AreEqual("NestedMessage", nestedType.Name); - Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName); + Assert.AreEqual("protobuf_unittest3.TestAllTypes.NestedMessage", nestedType.FullName); Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File); Assert.AreEqual(messageType, nestedType.ContainingType); @@ -143,7 +153,7 @@ namespace Google.Protobuf.Reflection FieldDescriptor messageField = messageType.FindDescriptor("single_foreign_message"); Assert.AreEqual("single_int32", primitiveField.Name); - Assert.AreEqual("protobuf_unittest.TestAllTypes.single_int32", + Assert.AreEqual("protobuf_unittest3.TestAllTypes.single_int32", primitiveField.FullName); Assert.AreEqual(1, primitiveField.FieldNumber); Assert.AreEqual(messageType, primitiveField.ContainingType); @@ -180,13 +190,13 @@ namespace Google.Protobuf.Reflection EnumDescriptor nestedType = TestAllTypes.Descriptor.FindDescriptor("NestedEnum"); Assert.AreEqual("ForeignEnum", enumType.Name); - Assert.AreEqual("protobuf_unittest.ForeignEnum", enumType.FullName); + Assert.AreEqual("protobuf_unittest3.ForeignEnum", enumType.FullName); Assert.AreEqual(UnittestProto3Reflection.Descriptor, enumType.File); Assert.Null(enumType.ContainingType); Assert.Null(enumType.Proto.Options); Assert.AreEqual("NestedEnum", nestedType.Name); - Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedEnum", + Assert.AreEqual("protobuf_unittest3.TestAllTypes.NestedEnum", nestedType.FullName); Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File); Assert.AreEqual(TestAllTypes.Descriptor, nestedType.ContainingType); @@ -209,7 +219,7 @@ namespace Google.Protobuf.Reflection { OneofDescriptor descriptor = TestAllTypes.Descriptor.FindDescriptor("oneof_field"); Assert.AreEqual("oneof_field", descriptor.Name); - Assert.AreEqual("protobuf_unittest.TestAllTypes.oneof_field", descriptor.FullName); + Assert.AreEqual("protobuf_unittest3.TestAllTypes.oneof_field", descriptor.FullName); var expectedFields = new[] { TestAllTypes.OneofBytesFieldNumber, diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index a3edd5950c..6ca1e1f04b 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -42,7 +42,7 @@ namespace Google.Protobuf.WellKnownTypes { var message = SampleMessages.CreateFullTestAllTypes(); var any = Any.Pack(message); - Assert.AreEqual("type.googleapis.com/protobuf_unittest.TestAllTypes", any.TypeUrl); + Assert.AreEqual("type.googleapis.com/protobuf_unittest3.TestAllTypes", any.TypeUrl); Assert.AreEqual(message.CalculateSize(), any.Value.Length); } @@ -51,7 +51,7 @@ namespace Google.Protobuf.WellKnownTypes { var message = SampleMessages.CreateFullTestAllTypes(); var any = Any.Pack(message, "foo.bar/baz"); - Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl); + Assert.AreEqual("foo.bar/baz/protobuf_unittest3.TestAllTypes", any.TypeUrl); Assert.AreEqual(message.CalculateSize(), any.Value.Length); } @@ -60,7 +60,7 @@ namespace Google.Protobuf.WellKnownTypes { var message = SampleMessages.CreateFullTestAllTypes(); var any = Any.Pack(message, "foo.bar/baz/"); - Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl); + Assert.AreEqual("foo.bar/baz/protobuf_unittest3.TestAllTypes", any.TypeUrl); Assert.AreEqual(message.CalculateSize(), any.Value.Length); }