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,64 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Text;
using Xunit;
namespace System.Text.EncodingTests
{
// Calculates the maximum number of characters produced by decoding the specified number of bytes.
// ASCIIEncoding.GetMaxCharCount(int)
public class ASCIIEncodingGetMaxCharCount
{
// PosTest1: The specified number of bytes is zero.
[Fact]
public void PosTest1()
{
DoPosTest(new ASCIIEncoding(), 0, 0);
}
// PosTest2: The specified number of bytes is a random non-negative Int32 value.
[Fact]
public void PosTest2()
{
ASCIIEncoding ascii;
int byteCount;
int expectedValue;
ascii = new ASCIIEncoding();
byteCount = TestLibrary.Generator.GetInt32(-55);
expectedValue = byteCount;
DoPosTest(ascii, byteCount, expectedValue);
}
private void DoPosTest(ASCIIEncoding ascii, int byteCount, int expectedValue)
{
int actualValue;
ascii = new ASCIIEncoding();
actualValue = ascii.GetMaxCharCount(byteCount);
Assert.Equal(expectedValue, actualValue);
}
// NegTest1: count of characters is less than zero.
[Fact]
public void NegTest1()
{
ASCIIEncoding ascii;
int byteCount;
ascii = new ASCIIEncoding();
byteCount = -1 * TestLibrary.Generator.GetInt32(-55) - 1;
DoNegAOORTest(ascii, byteCount);
}
private void DoNegAOORTest(ASCIIEncoding ascii, int byteCount)
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
ascii.GetMaxCharCount(byteCount);
});
}
}
}