Skip to content

Commit

Permalink
Updated set of unit tests and unit test protos.
Browse files Browse the repository at this point in the history
This commit includes changes to the C#-specific protos, and rebuilt versions of the "stock" protos.
The stock protos have been locally updated to have a specific C# namespace, but this is expected to change soon, so hasn't been committed.
Four areas are currently not tested:
1) Serialization - we may restore this at some point, possibly optionally.
2) Services - currently nothing is generated for this; will need to see how it interacts with GRPC
3) Fields beginning with _{digit} - see protocolbuffers/protobuf#308
4) Fields with names which conflict with the declaring type in nasty ways - see protocolbuffers/protobuf#309
  • Loading branch information
jskeet committed Apr 28, 2015
1 parent 5ca126f commit efb713a
Show file tree
Hide file tree
Showing 67 changed files with 164,903 additions and 93,042 deletions.
37 changes: 0 additions & 37 deletions protos/extest/unittest_extras.proto

This file was deleted.

13 changes: 6 additions & 7 deletions protos/extest/unittest_extras_full.proto
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasFullProtoFile";
syntax = "proto2";

package protobuf_unittest_extra;

option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = CODE_SIZE;

option java_package = "com.google.protobuf";

message TestInteropPerson {
Expand Down Expand Up @@ -45,7 +41,10 @@ message TestInteropEmployeeId {
}

extend TestInteropPerson {
required TestInteropEmployeeId employee_id = 126;
// Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeId employee_id = 126;
}

message TestMissingFieldsA {
Expand Down
14 changes: 6 additions & 8 deletions protos/extest/unittest_extras_lite.proto
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasLiteProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
syntax = "proto2";

package protobuf_unittest_extra;

option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = LITE_RUNTIME;

option java_package = "com.google.protobuf";

message TestRequiredLite {
Expand Down Expand Up @@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite {
}

extend TestInteropPersonLite {
required TestInteropEmployeeIdLite employee_id_lite = 126;
// Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeIdLite employee_id_lite = 126;
}

/* Removed from unittest_lite.proto and added back here */
Expand Down
7 changes: 3 additions & 4 deletions protos/extest/unittest_extras_xmltest.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
syntax = "proto2";

option csharp_namespace = "Google.ProtocolBuffers.TestProtos";

package protobuf_unittest_extra;

Expand Down
35 changes: 18 additions & 17 deletions protos/extest/unittest_generic_services.proto
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
syntax = "proto2";

// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
import "google/protobuf/unittest.proto";
import "google/protobuf/unittest_custom_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestGenericServices";

option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";

// option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;

// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;

// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;

option optimize_for = SPEED;

service TestGenericService {
rpc Foo(FooRequest) returns (FooResponse);
rpc Bar(BarRequest) returns (BarResponse);
}

service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210;

rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2;
}
}


service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210;

rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2;
}
}

36 changes: 20 additions & 16 deletions protos/extest/unittest_issues.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
syntax = "proto2";

// These proto descriptors have at one time been reported as an issue or defect.
// They are kept here to replicate the issue, and continue to verify the fix.
import "google/protobuf/csharp_options.proto";

// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
option (google.protobuf.csharp_file_options).namespace = "UnitTest.Issues.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasIssuesProtoFile";
option csharp_namespace = "UnitTest.Issues.TestProtos";

package unittest_issues;
option optimize_for = SPEED;
Expand Down Expand Up @@ -67,24 +67,28 @@ service TestGenericService {
rpc Bar(TestBasicNoFields) returns (TestBasicMessage);
}
*/
// Issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13

// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// New issue 309: https://github.com/google/protobuf/issues/309

message A {
optional int32 _A = 1;
}
// message A {
// optional int32 _A = 1;
// }

message B {
optional int32 B_ = 1;
}
// message B {
// optional int32 B_ = 1;
// }

message AB {
optional int32 a_b = 1;
}
//message AB {
// optional int32 a_b = 1;
//}

// Similar issue with numeric names
message NumberField {
optional int32 _01 = 1;
}
// Java code failed too, so probably best for this to be a restriction.
// See https://github.com/google/protobuf/issues/308
// message NumberField {
// optional int32 _01 = 1;
// }

// Issue 28: Circular message dependencies result in null defaults for DefaultInstance

Expand Down
8 changes: 4 additions & 4 deletions src/ProtocolBuffers.Test/AbstractMessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void UnpackedParsingOfPackedInputExtensions()
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry);
UnitTestExtrasProtoFile.RegisterAllExtensions(registry);
Unittest.RegisterAllExtensions(registry);
UnittestImport.RegisterAllExtensions(registry);
TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertUnpackedExtensionsSet(message);
}
Expand All @@ -143,7 +143,7 @@ public void PackedParsingOfUnpackedInputExtensions()
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry);
Unittest.RegisterAllExtensions(registry);
TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertPackedExtensionsSet(message);
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public void EqualsAndHashCode()
TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build();
TestAllExtensions e = TestUtil.GetAllExtensionsSet();
TestAllExtensions f = TestAllExtensions.CreateBuilder(e)
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 999).Build();
.AddExtension(Unittest.RepeatedInt32Extension, 999).Build();

CheckEqualsIsConsistent(a);
CheckEqualsIsConsistent(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Compatibility
{
/// <summary>
/// This abstract base implements several tests to ensure that well-known messages can be written
/// and read to/from various formats without loosing data. Implementations overload the two serailization
/// and read to/from various formats without losing data. Implementations overload the two serailization
/// methods to provide the tests with the means to read and write for a given format.
/// </summary>
public abstract class CompatibilityTests
Expand Down

0 comments on commit efb713a

Please sign in to comment.