mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
Commit migrated from https://github.com/dotnet/corefx/commit/1ad3dfd20e56dab48384063f07e13f72d1dbcf96
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using Xunit;
|
|
|
|
namespace System.Text.Tests
|
|
{
|
|
// Convert(System.Text.Encoding,System.Text.Encoding,System.Byte[])
|
|
public class EncodingConvert1
|
|
{
|
|
#region Positive Test Cases
|
|
// PosTest1: Verify method Convert
|
|
[Fact]
|
|
public void PosTest1()
|
|
{
|
|
string unicodeStr = "test string .";
|
|
Encoding ascii = Encoding.UTF8;
|
|
Encoding unicode = Encoding.Unicode;
|
|
|
|
byte[] unicodeBytes = unicode.GetBytes(unicodeStr);
|
|
|
|
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
|
|
|
|
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
|
|
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
|
|
string asciiStr = new string(asciiChars);
|
|
Assert.Equal(asciiStr, unicodeStr);
|
|
}
|
|
#endregion
|
|
|
|
#region Negative Test Cases
|
|
[Fact]
|
|
public void NegTest1()
|
|
{
|
|
string unicodeStr = "test string .";
|
|
|
|
Encoding ascii = null;
|
|
Encoding unicode = Encoding.Unicode;
|
|
|
|
byte[] unicodeBytes = unicode.GetBytes(unicodeStr);
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void NegTest2()
|
|
{
|
|
Encoding ascii = Encoding.UTF8;
|
|
Encoding unicode = null;
|
|
|
|
byte[] unicodeBytes = new byte[] { 1, 2, 3 };
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void NegTest3()
|
|
{
|
|
Encoding ascii = Encoding.UTF8;
|
|
Encoding unicode = Encoding.Unicode;
|
|
|
|
byte[] unicodeBytes = null;
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
|
|
});
|
|
}
|
|
#endregion
|
|
}
|
|
}
|