//[InlineData(TextEncoderTestHelper.SupportedEncoding.FromUtf32)] // Open issue: https://github.com/dotnet/corefxlab/issues/1513 public void InputBufferEndsTooEarlyAndRestart(TextEncoderTestHelper.SupportedEncoding from) { string inputString1 = TextEncoderTestHelper.GenerateValidStringEndsWithHighStartsWithLow(TextEncoderConstants.DataLength, false); string inputString2 = inputString1 + TextEncoderTestHelper.GenerateValidStringEndsWithHighStartsWithLow(TextEncoderConstants.DataLength, true); byte[] inputUtf8Bytes1 = TextEncoderTestHelper.GenerateValidUtf8BytesEndsWithHighStartsWithLow(TextEncoderConstants.DataLength, false); byte[] tempForUtf8Bytes2 = TextEncoderTestHelper.GenerateValidUtf8BytesEndsWithHighStartsWithLow(TextEncoderConstants.DataLength, true); byte[] inputUtf8Bytes2 = new byte[inputUtf8Bytes1.Length + tempForUtf8Bytes2.Length]; Array.Copy(inputUtf8Bytes1, inputUtf8Bytes2, inputUtf8Bytes1.Length); Array.Copy(tempForUtf8Bytes2, 0, inputUtf8Bytes2, inputUtf8Bytes1.Length, tempForUtf8Bytes2.Length); uint[] inputUtf32Bytes1 = TextEncoderTestHelper.GenerateValidUtf32EndsWithHighStartsWithLow(TextEncoderConstants.DataLength, false); uint[] tempForUtf32Bytes2 = TextEncoderTestHelper.GenerateValidUtf32EndsWithHighStartsWithLow(TextEncoderConstants.DataLength, true); uint[] inputUtf32Bytes2 = new uint[inputUtf32Bytes1.Length + tempForUtf32Bytes2.Length]; Array.Copy(inputUtf32Bytes1, inputUtf32Bytes2, inputUtf32Bytes1.Length); Array.Copy(tempForUtf32Bytes2, 0, inputUtf32Bytes2, inputUtf32Bytes1.Length, tempForUtf32Bytes2.Length); byte[] uint32Bytes1 = TextEncoderTestHelper.GenerateValidBytesUtf32EndsWithHighStartsWithLow(TextEncoderConstants.DataLength, false); byte[] tempUint32Bytes = TextEncoderTestHelper.GenerateValidBytesUtf32EndsWithHighStartsWithLow(TextEncoderConstants.DataLength, true); byte[] uint32Bytes2 = new byte[uint32Bytes1.Length + tempUint32Bytes.Length]; Array.Copy(uint32Bytes1, uint32Bytes2, uint32Bytes1.Length); Array.Copy(tempUint32Bytes, 0, uint32Bytes2, uint32Bytes1.Length, tempUint32Bytes.Length); byte[] expectedBytes; Span <byte> encodedBytes; int charactersConsumed1; int charactersConsumed2; int bytesWritten1; int bytesWritten2; switch (from) { case TextEncoderTestHelper.SupportedEncoding.FromUtf8: expectedBytes = Text.Encoding.Convert(testEncoder, testEncoder, inputUtf8Bytes2); ReadOnlySpan <byte> firstUtf8 = inputUtf8Bytes1; ReadOnlySpan <byte> secondUtf8 = inputUtf8Bytes2; encodedBytes = new Span <byte>(new byte[expectedBytes.Length]); Assert.False(utf8.TryEncode(firstUtf8, encodedBytes, out charactersConsumed1, out bytesWritten1)); Assert.True(utf8.TryEncode(secondUtf8.Slice(charactersConsumed1), encodedBytes.Slice(bytesWritten1), out charactersConsumed2, out bytesWritten2)); break; case TextEncoderTestHelper.SupportedEncoding.FromUtf16: byte[] inputStringUtf16 = testEncoderUnicode.GetBytes(inputString2); expectedBytes = Text.Encoding.Convert(testEncoderUnicode, testEncoder, inputStringUtf16); ReadOnlySpan <char> firstUtf16 = inputString1.AsSpan(); ReadOnlySpan <char> secondUtf16 = inputString2.AsSpan(); encodedBytes = new Span <byte>(new byte[expectedBytes.Length]); Assert.False(utf8.TryEncode(firstUtf16, encodedBytes, out charactersConsumed1, out bytesWritten1)); Assert.True(utf8.TryEncode(secondUtf16.Slice(charactersConsumed1), encodedBytes.Slice(bytesWritten1), out charactersConsumed2, out bytesWritten2)); break; case TextEncoderTestHelper.SupportedEncoding.FromString: // Open issue: https://github.com/dotnet/corefxlab/issues/1515 /*inputStringUtf16 = testEncoderUnicode.GetBytes(inputString2); * expectedBytes = Text.Encoding.Convert(testEncoderUnicode, testEncoder, inputStringUtf16); * string firstInputStr = inputString1; * string secondInputStr = inputString2; * encodedBytes = new Span<byte>(new byte[expectedBytes.Length]); * Assert.False(utf8.TryEncode(firstInputStr, encodedBytes, out bytesWritten1)); * Assert.True(utf8.TryEncode(secondInputStr.Substring(charactersConsumed1), encodedBytes.Slice(bytesWritten1), out bytesWritten1));*/ return; case TextEncoderTestHelper.SupportedEncoding.FromUtf32: default: expectedBytes = Text.Encoding.Convert(testEncoderUtf32, testEncoder, uint32Bytes2); ReadOnlySpan <uint> firstInput = inputUtf32Bytes1.AsSpan(); ReadOnlySpan <uint> secondInput = inputUtf32Bytes2.AsSpan(); encodedBytes = new Span <byte>(new byte[TextEncoderTestHelper.GetUtf8ByteCount(inputUtf32Bytes2)]); Assert.False(utf8.TryEncode(firstInput, encodedBytes, out charactersConsumed1, out bytesWritten1)); Assert.True(utf8.TryEncode(secondInput.Slice(charactersConsumed1), encodedBytes.Slice(bytesWritten1), out charactersConsumed2, out bytesWritten2)); break; } Assert.Equal(TextEncoderConstants.DataLength * 2, charactersConsumed1 + charactersConsumed2); Assert.Equal(expectedBytes.Length, bytesWritten1 + bytesWritten2); Assert.True(expectedBytes.AsSpan().SequenceEqual(encodedBytes)); }