mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
Porting System.Text.Encoding from ToF and unified 4.0 and 4.10 tests into same folder
[tfs-changeset: 1474146] Commit migrated from https://github.com/dotnet/corefx/commit/1394fa1c2539f289916b9c0641f81436b73e8794
This commit is contained in:
1 parent
40a96f0d15
commit
e157c69bbc
104 files changed
+12887
No files matched your search
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Text.EncodingTests
|
||||
{
|
||||
//System.Text.UnicodeEncoding.GetEncoder() [v-zuolan]
|
||||
public class UnicodeEncodingGetEncoder
|
||||
{
|
||||
#region Positive Tests
|
||||
// PosTest1:Invoke the method
|
||||
[Fact]
|
||||
public void PosTest1()
|
||||
{
|
||||
Char[] Chars = GetCharArray(10);
|
||||
Byte[] bytes = new Byte[20];
|
||||
Byte[] desBytes = new Byte[20];
|
||||
int buffer;
|
||||
int outChars;
|
||||
bool completed;
|
||||
UnicodeEncoding uEncoding = new UnicodeEncoding();
|
||||
int byteCount = uEncoding.GetBytes(Chars, 0, 10, bytes, 0);
|
||||
bool expectedValue = true;
|
||||
bool actualValue = true;
|
||||
|
||||
Encoder eC = uEncoding.GetEncoder();
|
||||
eC.Convert(Chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
|
||||
if (completed)
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
actualValue = actualValue & (bytes[i] == desBytes[i]);
|
||||
}
|
||||
}
|
||||
Assert.Equal(expectedValue, actualValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper Methods
|
||||
//Create a None-Surrogate-Char Array.
|
||||
public Char[] GetCharArray(int length)
|
||||
{
|
||||
if (length <= 0) return new Char[] { };
|
||||
|
||||
Char[] charArray = new Char[length];
|
||||
int i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
Char temp = TestLibrary.Generator.GetChar(-55);
|
||||
if (!Char.IsSurrogate(temp))
|
||||
{
|
||||
charArray[i] = temp;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return charArray;
|
||||
}
|
||||
|
||||
//Convert Char Array to String
|
||||
public String ToString(Char[] chars)
|
||||
{
|
||||
String str = "{";
|
||||
for (int i = 0; i < chars.Length; i++)
|
||||
{
|
||||
str = str + @"\u" + String.Format("{0:X04}", (int)chars[i]);
|
||||
if (i != chars.Length - 1) str = str + ",";
|
||||
}
|
||||
str = str + "}";
|
||||
return str;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user