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:
Venkatraman Mahalingam authored and Venkatraman Mahalingam committed 2015-05-21 15:22:44 -07:00
1 parent 40a96f0d15
commit e157c69bbc
104 files changed
+12887

No files matched your search

@@ -0,0 +1,72 @@
using System;
using System.Text;
using Xunit;
namespace System.Text.EncodingTests
{
//System.Test.UnicodeEncoding.GetDecoder()
public class UnicodeEncodingGetDecoder
{
#region Positive Tests
// PosTest1:Invoke the method
[Fact]
public void PosTest1()
{
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
int buffer;
int outChars;
bool completed;
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
bool expectedValue = true;
bool actualValue = true;
Decoder dC = uEncoding.GetDecoder();
dC.Convert(bytes, 0, 20, desChars, 0, 10, true, out buffer, out outChars, out completed);
if (completed)
{
for (int i = 0; i < 10; i++)
{
actualValue = actualValue & (desChars[i] == srcChars[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
}
}