Test proto and unit test for issue #9605

This doesn't test *all* possibilities (e.g. the field being a
wrapper, or a message field, etc) - but I'm fairly confident that I
found all the places referring to the case.
pull/9710/head
Jon Skeet 3 years ago committed by Jon Skeet
parent 81c5e1a712
commit e2f845b2f1
  1. 14
      csharp/protos/unittest_issues.proto
  2. 16
      csharp/src/Google.Protobuf.Test/IssuesTest.cs

@ -156,3 +156,17 @@ message MixedRegularAndOptional {
string regular_field = 1;
optional string optional_field = 2;
}
message OneofWithNoneField {
oneof test {
string x = 1;
string none = 2;
}
}
message OneofWithNoneName {
oneof none {
string x = 1;
string y = 2;
}
}

@ -112,5 +112,21 @@ namespace Google.Protobuf
// See https://github.com/protocolbuffers/protobuf/pull/7289
cis.AssertNextTag(WireFormat.MakeTag(11, WireFormat.WireType.Varint));
}
[Test]
public void NoneFieldInOneof()
{
var message = new OneofWithNoneField();
var emptyHashCode = message.GetHashCode();
Assert.AreEqual(OneofWithNoneField.TestOneofCase.None, message.TestCase);
message.None = "test";
Assert.AreEqual(OneofWithNoneField.TestOneofCase.None_, message.TestCase);
Assert.AreNotEqual(emptyHashCode, message.GetHashCode());
var bytes = message.ToByteArray();
var parsed = OneofWithNoneField.Parser.ParseFrom(bytes);
Assert.AreEqual(message, parsed);
Assert.AreEqual("test", parsed.None);
}
}
}

Loading…
Cancel
Save