Change the effective proto root for C#-specific test protos.

PiperOrigin-RevId: 505928634
pull/10978/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent b8536814cd
commit 943bd5a7d8
  1. 2
      csharp/generate_protos.sh
  2. 6
      csharp/protos/map_unittest_proto3.proto
  3. 5
      csharp/protos/old_extensions1.proto
  4. 65
      csharp/protos/unittest.proto
  5. 4
      csharp/protos/unittest_import.proto
  6. 3
      csharp/protos/unittest_import_proto3.proto
  7. 7
      csharp/protos/unittest_issue6936_b.proto
  8. 7
      csharp/protos/unittest_issue6936_c.proto
  9. 13
      csharp/protos/unittest_proto3.proto
  10. 13
      csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs
  11. 16
      csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs

@ -50,7 +50,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
# Note that this deliberately does *not* include old_extensions1.proto # Note that this deliberately does *not* include old_extensions1.proto
# and old_extensions2.proto, which are generated with an older version # and old_extensions2.proto, which are generated with an older version
# of protoc. # of protoc.
$PROTOC -Isrc -Icsharp/protos \ $PROTOC -Isrc -I. \
--experimental_allow_proto3_optional \ --experimental_allow_proto3_optional \
--csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \ --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \
--csharp_opt=file_extension=.pb.cs \ --csharp_opt=file_extension=.pb.cs \

@ -36,11 +36,11 @@
// required fields in proto3. // required fields in proto3.
syntax = "proto3"; syntax = "proto3";
option csharp_namespace = "Google.Protobuf.TestProtos"; package protobuf_unittest3;
import "unittest_proto3.proto"; import "csharp/protos/unittest_proto3.proto";
package protobuf_unittest3; option csharp_namespace = "Google.Protobuf.TestProtos";
// Tests maps. // Tests maps.
message TestMap { message TestMap {

@ -43,10 +43,9 @@ syntax = "proto3";
// Import the proto file containing the extension. We don't use it, // Import the proto file containing the extension. We don't use it,
// but the import is what caused the issue. // but the import is what caused the issue.
import "old_extensions2.proto"; import "csharp/protos/old_extensions2.proto";
option csharp_namespace = "Google.Protobuf.TestProtos.OldGenerator"; option csharp_namespace = "Google.Protobuf.TestProtos.OldGenerator";
// We don't use this message other than to get its descriptor. // We don't use this message other than to get its descriptor.
message TestMessage { message TestMessage {}
}

@ -45,7 +45,7 @@ option java_generic_services = true; // auto-added
option py_generic_services = true; // auto-added option py_generic_services = true; // auto-added
option cc_enable_arenas = true; option cc_enable_arenas = true;
import "unittest_import.proto"; import "csharp/protos/unittest_import.proto";
// We don't put this in a package within proto2 because we need to make sure // 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. // that the generated code doesn't depend on being in the proto2 namespace.
@ -99,7 +99,8 @@ message TestAllTypes {
optional NestedMessage optional_nested_message = 18; optional NestedMessage optional_nested_message = 18;
optional ForeignMessage optional_foreign_message = 19; optional ForeignMessage optional_foreign_message = 19;
optional protobuf_unittest_import_proto2.ImportMessage optional_import_message = 20; optional protobuf_unittest_import_proto2.ImportMessage
optional_import_message = 20;
optional NestedEnum optional_nested_enum = 21; optional NestedEnum optional_nested_enum = 21;
optional ForeignEnum optional_foreign_enum = 22; optional ForeignEnum optional_foreign_enum = 22;
@ -137,7 +138,8 @@ message TestAllTypes {
repeated NestedMessage repeated_nested_message = 48; repeated NestedMessage repeated_nested_message = 48;
repeated ForeignMessage repeated_foreign_message = 49; repeated ForeignMessage repeated_foreign_message = 49;
repeated protobuf_unittest_import_proto2.ImportMessage repeated_import_message = 50; repeated protobuf_unittest_import_proto2.ImportMessage
repeated_import_message = 50;
repeated NestedEnum repeated_nested_enum = 51; repeated NestedEnum repeated_nested_enum = 51;
repeated ForeignEnum repeated_foreign_enum = 52; repeated ForeignEnum repeated_foreign_enum = 52;
@ -167,10 +169,11 @@ message TestAllTypes {
optional NestedEnum default_nested_enum = 81 [default = BAR]; optional NestedEnum default_nested_enum = 81 [default = BAR];
optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
optional protobuf_unittest_import_proto2.ImportEnum optional protobuf_unittest_import_proto2.ImportEnum default_import_enum = 83
default_import_enum = 83 [default = IMPORT_BAR]; [default = IMPORT_BAR];
optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; optional string default_string_piece = 84
[ctype = STRING_PIECE, default = "abc"];
optional string default_cord = 85 [ctype = CORD, default = "123"]; optional string default_cord = 85 [ctype = CORD, default = "123"];
// For oneof test // For oneof test
@ -260,8 +263,8 @@ extend TestAllExtensions {
optional protobuf_unittest_import_proto2.PublicImportMessage optional protobuf_unittest_import_proto2.PublicImportMessage
optional_public_import_message_extension = 26; optional_public_import_message_extension = 26;
optional TestAllTypes.NestedMessage optional TestAllTypes.NestedMessage optional_lazy_message_extension = 27
optional_lazy_message_extension = 27 [lazy=true]; [lazy = true];
// Repeated // Repeated
repeated int32 repeated_int32_extension = 31; repeated int32 repeated_int32_extension = 31;
@ -297,8 +300,8 @@ extend TestAllExtensions {
repeated string repeated_string_piece_extension = 54 [ctype = STRING_PIECE]; repeated string repeated_string_piece_extension = 54 [ctype = STRING_PIECE];
repeated string repeated_cord_extension = 55 [ctype = CORD]; repeated string repeated_cord_extension = 55 [ctype = CORD];
repeated TestAllTypes.NestedMessage repeated TestAllTypes.NestedMessage repeated_lazy_message_extension = 57
repeated_lazy_message_extension = 57 [lazy=true]; [lazy = true];
// Singular with defaults // Singular with defaults
optional int32 default_int32_extension = 61 [default = 41]; optional int32 default_int32_extension = 61 [default = 41];
@ -317,15 +320,15 @@ extend TestAllExtensions {
optional string default_string_extension = 74 [default = "hello"]; optional string default_string_extension = 74 [default = "hello"];
optional bytes default_bytes_extension = 75 [default = "world"]; optional bytes default_bytes_extension = 75 [default = "world"];
optional TestAllTypes.NestedEnum optional TestAllTypes.NestedEnum default_nested_enum_extension = 81
default_nested_enum_extension = 81 [default = BAR]; [default = BAR];
optional ForeignEnum optional ForeignEnum default_foreign_enum_extension = 82
default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; [default = FOREIGN_BAR];
optional protobuf_unittest_import_proto2.ImportEnum optional protobuf_unittest_import_proto2.ImportEnum
default_import_enum_extension = 83 [default = IMPORT_BAR]; default_import_enum_extension = 83 [default = IMPORT_BAR];
optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, optional string default_string_piece_extension = 84
default="abc"]; [ctype = STRING_PIECE, default = "abc"];
optional string default_cord_extension = 85 [ctype = CORD, default = "123"]; optional string default_cord_extension = 85 [ctype = CORD, default = "123"];
// For oneof test // For oneof test
@ -432,8 +435,7 @@ message TestForeignNested {
} }
// TestEmptyMessage is used to test unknown field support. // TestEmptyMessage is used to test unknown field support.
message TestEmptyMessage { message TestEmptyMessage {}
}
// Like above, but declare all field numbers as potential extensions. No // Like above, but declare all field numbers as potential extensions. No
// actual extensions should ever be defined for this type. // actual extensions should ever be defined for this type.
@ -487,13 +489,17 @@ message TestIsInitialized {
} }
// Test that groups have disjoint field numbers from their siblings and // Test that groups have disjoint field numbers from their siblings and
// parents. This is NOT possible in proto1; only google.protobuf. When attempting // parents. This is NOT possible in proto1; only google.protobuf. When
// to compile with proto1, this will emit an error; so we only include it // attempting to compile with proto1, this will emit an error; so we only
// in protobuf_unittest_proto. // include it in protobuf_unittest_proto.
message TestDupFieldNumber { // NO_PROTO1 message TestDupFieldNumber { // NO_PROTO1
optional int32 a = 1; // NO_PROTO1 optional int32 a = 1; // NO_PROTO1
optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 optional group Foo = 2 {
optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 optional int32 a = 1;
} // NO_PROTO1
optional group Bar = 3 {
optional int32 a = 1;
} // NO_PROTO1
} // NO_PROTO1 } // NO_PROTO1
// Additional messages for testing lazy fields. // Additional messages for testing lazy fields.
@ -513,7 +519,6 @@ message TestNestedMessageHasBits {
optional NestedMessage optional_nested_message = 1; optional NestedMessage optional_nested_message = 1;
} }
// Test an enum that has multiple values with the same number. // Test an enum that has multiple values with the same number.
enum TestEnumWithDupValue { enum TestEnumWithDupValue {
option allow_alias = true; option allow_alias = true;
@ -554,7 +559,6 @@ message TestCamelCaseFieldNames {
repeated string RepeatedCordField = 12 [ctype = CORD]; repeated string RepeatedCordField = 12 [ctype = CORD];
} }
// We list fields out of order, to ensure that we're using field number and not // We list fields out of order, to ensure that we're using field number and not
// field index to determine serialization order. // field index to determine serialization order.
message TestFieldOrderings { message TestFieldOrderings {
@ -641,10 +645,9 @@ message TestExtremeDefaultValues {
// String defaults containing the character '\000' // String defaults containing the character '\000'
optional string string_with_zero = 23 [default = "hel\000lo"]; optional string string_with_zero = 23 [default = "hel\000lo"];
optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, optional string string_piece_with_zero = 25
default="ab\000c"]; [ctype = STRING_PIECE, default = "ab\000c"];
optional string cord_with_zero = 26 [ctype=CORD, optional string cord_with_zero = 26 [ctype = CORD, default = "12\0003"];
default="12\0003"];
optional string replacement_string = 27 [default = "${unknown}"]; optional string replacement_string = 27 [default = "${unknown}"];
} }
@ -934,7 +937,6 @@ message TestCommentInjectionMessage {
optional string a = 1 [default = "*/ <- Neither should this."]; optional string a = 1 [default = "*/ <- Neither should this."];
} }
// Test that RPC services work. // Test that RPC services work.
message FooRequest {} message FooRequest {}
message FooResponse {} message FooResponse {}
@ -947,7 +949,6 @@ service TestService {
rpc Bar(BarRequest) returns (BarResponse); rpc Bar(BarRequest) returns (BarResponse);
} }
message BarRequest {} message BarRequest {}
message BarResponse {} message BarResponse {}
@ -1110,4 +1111,4 @@ enum VeryLargeEnum {
ENUM_LABEL_98 = 98; ENUM_LABEL_98 = 98;
ENUM_LABEL_99 = 99; ENUM_LABEL_99 = 99;
ENUM_LABEL_100 = 100; ENUM_LABEL_100 = 100;
}; }

@ -44,11 +44,10 @@ package protobuf_unittest_import_proto2;
option optimize_for = SPEED; option optimize_for = SPEED;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option csharp_namespace = "Google.Protobuf.TestProtos.Proto2"; option csharp_namespace = "Google.Protobuf.TestProtos.Proto2";
// Test public import // Test public import
import public "unittest_import_public.proto"; import public "csharp/protos/unittest_import_public.proto";
message ImportMessage { message ImportMessage {
optional int32 d = 1; optional int32 d = 1;
@ -60,7 +59,6 @@ enum ImportEnum {
IMPORT_BAZ = 9; IMPORT_BAZ = 9;
} }
// To use an enum in a map, it must has the first value as 0. // To use an enum in a map, it must has the first value as 0.
enum ImportEnumForMap { enum ImportEnumForMap {
UNKNOWN = 0; UNKNOWN = 0;

@ -41,7 +41,7 @@ package protobuf_unittest_import;
option csharp_namespace = "Google.Protobuf.TestProtos"; option csharp_namespace = "Google.Protobuf.TestProtos";
// Test public import // Test public import
import public "unittest_import_public_proto3.proto"; import public "csharp/protos/unittest_import_public_proto3.proto";
message ImportMessage { message ImportMessage {
int32 d = 1; int32 d = 1;
@ -53,4 +53,3 @@ enum ImportEnum {
IMPORT_BAR = 8; IMPORT_BAR = 8;
IMPORT_BAZ = 9; IMPORT_BAZ = 9;
} }

@ -30,14 +30,15 @@
syntax = "proto3"; syntax = "proto3";
import "unittest_issue6936_a.proto";
package unittest_issues; package unittest_issues;
import "csharp/protos/unittest_issue6936_a.proto";
option csharp_namespace = "UnitTest.Issues.TestProtos"; option csharp_namespace = "UnitTest.Issues.TestProtos";
// This file is used as part of a unit test for issue 6936 // This file is used as part of a unit test for issue 6936
// We don't need to use it, we just have to import it in "unittest_issue6936_c.proto" // We don't need to use it, we just have to import it in
// "unittest_issue6936_c.proto"
message Foo { message Foo {
option (opt) = "foo"; option (opt) = "foo";

@ -30,11 +30,11 @@
syntax = "proto3"; syntax = "proto3";
import "unittest_issue6936_a.proto";
import "unittest_issue6936_b.proto";
package unittest_issues; package unittest_issues;
import "csharp/protos/unittest_issue6936_a.proto";
import "csharp/protos/unittest_issue6936_b.proto";
option csharp_namespace = "UnitTest.Issues.TestProtos"; option csharp_namespace = "UnitTest.Issues.TestProtos";
// This file is used as part of a unit test for issue 6936 // This file is used as part of a unit test for issue 6936
@ -42,5 +42,6 @@ option csharp_namespace = "UnitTest.Issues.TestProtos";
message Bar { message Bar {
option (opt) = "bar"; option (opt) = "bar";
Foo foo = 1; Foo foo = 1;
} }

@ -42,7 +42,7 @@ option csharp_namespace = "Google.Protobuf.TestProtos";
// of a non-C# option) // of a non-C# option)
option java_outer_classname = "UnittestProto"; option java_outer_classname = "UnittestProto";
import "unittest_import_proto3.proto"; import "csharp/protos/unittest_import_proto3.proto";
package protobuf_unittest3; package protobuf_unittest3;
@ -90,8 +90,8 @@ message TestAllTypes {
protobuf_unittest_import.ImportEnum single_import_enum = 23; protobuf_unittest_import.ImportEnum single_import_enum = 23;
// Defined in unittest_import_public.proto // Defined in unittest_import_public.proto
protobuf_unittest_import.PublicImportMessage protobuf_unittest_import.PublicImportMessage single_public_import_message =
single_public_import_message = 26; 26;
// Repeated // Repeated
repeated int32 repeated_int32 = 31; repeated int32 repeated_int32 = 31;
@ -159,7 +159,6 @@ message TestReservedFields {
reserved "bar", "baz"; reserved "bar", "baz";
} }
// Test that we can use NestedMessage from outside TestAllTypes. // Test that we can use NestedMessage from outside TestAllTypes.
message TestForeignNested { message TestForeignNested {
TestAllTypes.NestedMessage foreign_nested = 1; TestAllTypes.NestedMessage foreign_nested = 1;
@ -194,9 +193,10 @@ message TestEnumAllowAlias {
// Test an enum that has multiple values with the same number. // Test an enum that has multiple values with the same number.
enum TestEnumWithDupValue { enum TestEnumWithDupValue {
TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0;
option allow_alias = true; option allow_alias = true;
TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0;
FOO1 = 1; FOO1 = 1;
BAR1 = 2; BAR1 = 2;
BAZ = 3; BAZ = 3;
@ -231,7 +231,6 @@ message TestCamelCaseFieldNames {
repeated ForeignMessage RepeatedMessageField = 10; repeated ForeignMessage RepeatedMessageField = 10;
} }
// We list fields out of order, to ensure that we're using field number and not // We list fields out of order, to ensure that we're using field number and not
// field index to determine serialization order. // field index to determine serialization order.
message TestFieldOrderings { message TestFieldOrderings {
@ -360,7 +359,6 @@ message TestCommentInjectionMessage {
string a = 1; string a = 1;
} }
// Test that RPC services work. // Test that RPC services work.
message FooRequest {} message FooRequest {}
message FooResponse {} message FooResponse {}
@ -375,7 +373,6 @@ service TestService {
rpc Bar(BarRequest) returns (BarResponse); rpc Bar(BarRequest) returns (BarResponse);
} }
message BarRequest {} message BarRequest {}
message BarResponse {} message BarResponse {}

@ -1,4 +1,4 @@
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2018 Google Inc. All rights reserved. // Copyright 2018 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
@ -86,10 +86,12 @@ namespace Google.Protobuf.Test.Reflection
{ {
var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage"); var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
Assert.NotNull(message.Declaration); Assert.NotNull(message.Declaration);
Assert.AreEqual(389, message.Declaration.StartLine); // TODO(jonskeet): Reinstate after regeneration
// Assert.AreEqual(386, message.Declaration.StartLine);
Assert.AreEqual(1, message.Declaration.StartColumn); Assert.AreEqual(1, message.Declaration.StartColumn);
Assert.AreEqual(404, message.Declaration.EndLine); // TODO(jonskeet): Reinstate after regeneration
// Assert.AreEqual(401, message.Declaration.EndLine);
Assert.AreEqual(2, message.Declaration.EndColumn); Assert.AreEqual(2, message.Declaration.EndColumn);
} }
@ -169,7 +171,10 @@ namespace Google.Protobuf.Test.Reflection
} }
var byteStrings = descriptorSet.File.Select(f => f.ToByteString()).ToList(); var byteStrings = descriptorSet.File.Select(f => f.ToByteString()).ToList();
var descriptors = FileDescriptor.BuildFromByteStrings(byteStrings); var descriptors = FileDescriptor.BuildFromByteStrings(byteStrings);
return descriptors.Single(d => d.Name == "unittest_proto3.proto"); // TODO(jonskeet): Remove the second condition here after regeneration
// (The Windows build doesn't perform regeneration yet.)
return descriptors.Single(d => d.Name == "csharp/protos/unittest_proto3.proto" ||
d.Name == "unittest_proto3.proto");
} }
} }
} }

@ -91,11 +91,13 @@ namespace Google.Protobuf.Reflection
private void TestFileDescriptor(FileDescriptor file, FileDescriptor importedFile, FileDescriptor importedPublicFile) private void TestFileDescriptor(FileDescriptor file, FileDescriptor importedFile, FileDescriptor importedPublicFile)
{ {
Assert.AreEqual("unittest_proto3.proto", file.Name); // TODO(jonskeet): Reinstate after regeneration
// Assert.AreEqual("csharp/protos/unittest_proto3.proto", file.Name);
Assert.AreEqual("protobuf_unittest3", file.Package); Assert.AreEqual("protobuf_unittest3", file.Package);
Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname); Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname);
Assert.AreEqual("unittest_proto3.proto", file.Proto.Name); // TODO(jonskeet): Reinstate after regeneration
// Assert.AreEqual("csharp/protos/unittest_proto3.proto", file.Proto.Name);
// unittest_proto3.proto doesn't have any public imports, but unittest_import_proto3.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(0, file.PublicDependencies.Count);
@ -126,16 +128,6 @@ namespace Google.Protobuf.Reflection
TestDescriptorToProto(file.ToProto, file.Proto); TestDescriptorToProto(file.ToProto, file.Proto);
} }
[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] [Test]
public void FileDescriptor_BuildFromByteStrings_MissingDependency() public void FileDescriptor_BuildFromByteStrings_MissingDependency()
{ {

Loading…
Cancel
Save