diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-09-30 12:20:52 -0700 |
---|---|---|
committer | Bryan Arant <bryanar@microsoft.com> | 2015-10-18 23:09:47 -0700 |
commit | 004514c07bcf5230b518befd75f794733b5f9067 (patch) | |
tree | f05d9d5692627acac1d043915eb5b20a74f403ec /tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs | |
parent | ddff89241f682995bdde165de89b579573a338aa (diff) | |
download | coreclr-004514c07bcf5230b518befd75f794733b5f9067.tar.gz coreclr-004514c07bcf5230b518befd75f794733b5f9067.tar.bz2 coreclr-004514c07bcf5230b518befd75f794733b5f9067.zip |
Managed Test Port
This is a collection of managed runtime tests from an internal legacy test tree.
Diffstat (limited to 'tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs')
-rw-r--r-- | tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs b/tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs new file mode 100644 index 0000000000..ed41141e5b --- /dev/null +++ b/tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs @@ -0,0 +1,82 @@ +using System; +using System.Globalization; + +/// <summary> +/// Char.System.IConvertible.ToUInt32(IFormatProvider) +/// Converts the value of the current Char object to an 32-bit unsigned integer. +/// </summary> +public class CharIConvertibleToUInt32 +{ + public static int Main() + { + CharIConvertibleToUInt32 testObj = new CharIConvertibleToUInt32(); + + TestLibrary.TestFramework.BeginTestCase("for method: Char.System.IConvertible.ToUInt32(IFormatProvider)"); + if(testObj.RunTests()) + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("PASS"); + return 100; + } + else + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("FAIL"); + return 0; + } + } + + public bool RunTests() + { + bool retVal = true; + + TestLibrary.TestFramework.LogInformation("[Positive]"); + retVal = PosTest1() && retVal; + + return retVal; + } + + #region Positive tests + public bool PosTest1() + { + bool retVal = true; + + const string c_TEST_ID = "P001"; + const string c_TEST_DESC = "PosTest1: Random character."; + string errorDesc; + + UInt32 expectedValue; + UInt32 actualValue; + char ch; + expectedValue = (UInt32)(TestLibrary.Generator.GetInt32(-55) % (UInt16.MaxValue + 1)); + ch = (char)expectedValue; + + TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); + try + { + NumberFormatInfo numberFormat = new NumberFormatInfo(); + IFormatProvider provider = numberFormat; + IConvertible converter = ch; + + actualValue = converter.ToUInt32(numberFormat); + + if (actualValue != expectedValue) + { + errorDesc = string.Format("UInt32 value of character \\u{0:x} is not ", (int)ch); + errorDesc += expectedValue + " as expected: Actual(" + actualValue + ")"; + TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); + retVal = false; + } + } + catch (Exception e) + { + errorDesc = "Unexpected exception: " + e; + TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); + retVal = false; + } + + return retVal; + } + #endregion +} + |