From 004514c07bcf5230b518befd75f794733b5f9067 Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Wed, 30 Sep 2015 12:20:52 -0700 Subject: Managed Test Port This is a collection of managed runtime tests from an internal legacy test tree. --- .../cti/system/char/chariconvertibletouint32.cs | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs (limited to 'tests/src/CoreMangLib/cti/system/char/chariconvertibletouint32.cs') 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; + +/// +/// Char.System.IConvertible.ToUInt32(IFormatProvider) +/// Converts the value of the current Char object to an 32-bit unsigned integer. +/// +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 +} + -- cgit v1.2.3