Added C# unit tests verifying current UTF-8 behavior.

PiperOrigin-RevId: 634029739
pull/16835/head
Joshua Haberman 9 months ago committed by Copybara-Service
parent a8cb5833aa
commit 6a2e4be010
  1. 25
      csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs

@ -99,6 +99,29 @@ namespace Google.Protobuf
Assert.Throws<ArgumentNullException>(() => message.OneofBytes = null);
}
[Test]
public void Roundtrip_UnpairedSurrogate()
{
var message = new TestAllTypes { SingleString = "\ud83d" };
Assert.AreEqual("\ud83d", message.SingleString);
// The serialized bytes contain the replacement character.
var bytes = message.ToByteArray();
CollectionAssert.AreEqual(bytes, new byte[] { 0x72, 3, 0xEF, 0xBF, 0xBD });
}
[Test]
public void InvalidUtf8ParsesAsReplacementChars()
{
var payload = new byte[] { 0x72, 1, 0x80 };
// We would prefer to have this parse operation fail, but at the moment it substitutes
// the replacement character.
var message = TestAllTypes.Parser.ParseFrom(payload);
Assert.AreEqual("\ufffd", message.SingleString);
}
[Test]
public void RoundTrip_Empty()
{
@ -886,4 +909,4 @@ namespace Google.Protobuf
Assert.AreEqual(expected, message1.MapStringString);
}
}
}
}

Loading…
Cancel
Save