本文整理汇总了C#中UTF8Encoding.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetChars方法的具体用法?C# UTF8Encoding.GetChars怎么用?C# UTF8Encoding.GetChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetChars方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest2
public bool PosTest2()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method GetChars with null chars");
try
{
Byte[] bytes;
Char[] chars = new Char[] { };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 0, 0);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 0, 0, chars, 0);
if (charsEncodedCount != 0)
{
TestLibrary.TestFramework.LogError("002.1", "Method GetChars Err.");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.1", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例2: PosTest2
public void PosTest2()
{
Byte[] bytes;
Char[] chars = new Char[] { };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 0, 0);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 0, 0, chars, 0);
Assert.Equal(0, charsEncodedCount);
}
示例3: PosTest1
public void PosTest1()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
}
示例4: NegTest1
public void NegTest1()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
});
}
示例5: NegTest7
public bool NegTest7()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest7: ArgumentException is not thrown when chars does not have enough capacity from charIndex to the end of the array to accommodate the resulting characters");
try
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, chars.Length);
TestLibrary.TestFramework.LogError("107.1", "ArgumentException is not thrown when byteIndex is not a valid index in bytes.");
retVal = false;
}
catch (ArgumentException) { }
catch (Exception e)
{
TestLibrary.TestFramework.LogError("107.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例6: NegTest6
public bool NegTest6()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest6: ArgumentOutOfRangeException is not thrown when byteIndex and byteCount do not denote a valid range in chars. ");
try
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 2, 2, chars, 1);
TestLibrary.TestFramework.LogError("106.1", "ArgumentOutOfRangeException is not thrown when byteIndex and byteCount do not denote a valid range in chars.");
retVal = false;
}
catch (ArgumentOutOfRangeException) { }
catch (Exception e)
{
TestLibrary.TestFramework.LogError("106.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: NegTest2
public bool NegTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest2: ArgumentNullException is not thrown when chars is a null reference ");
try
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
chars = null;
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
TestLibrary.TestFramework.LogError("102.1", "ArgumentNullException is not thrown when chars is a null reference ");
retVal = false;
}
catch (ArgumentNullException) { }
catch (Exception e)
{
TestLibrary.TestFramework.LogError("102.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}