X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem%2FStringTest.cs;h=be5e7984757b64a30bba3b7274a9f86edfab970f;hb=889b71116d77b38125e67918397b39018f6e14b6;hp=7119236c8aab2bb638ec9916a2191e761088ed7c;hpb=9900f812e2fc72b1e9389c4e7a0602007f256718;p=mono.git diff --git a/mcs/class/corlib/Test/System/StringTest.cs b/mcs/class/corlib/Test/System/StringTest.cs index 7119236c8aa..be5e7984757 100644 --- a/mcs/class/corlib/Test/System/StringTest.cs +++ b/mcs/class/corlib/Test/System/StringTest.cs @@ -16,6 +16,10 @@ using System.Globalization; using System.Reflection; using System.Threading; +#if !MOBILE +using System.Diagnostics; +#endif + using NUnit.Framework; namespace MonoTests.System @@ -92,19 +96,36 @@ public class StringTest } } + // Several tests in this file, to run properly, allocate 4GB objects. + // Obviously this creates problems on several kinds of systems, so we + // conservatively skip these tests unless we find a high-RAM environment. + // Checking RAM requires PerformanceCounter which is absent on mobile, + // so any test that calls this must be category MobileNotWorking. + static void RequireHighMemoryTestEnvironment () + { +#if MOBILE + Assert.Ignore("PerformanceCounter not available."); +#else + if (!Environment.Is64BitProcess) + Assert.Ignore("This test cannot run on a 32-bit system."); + + // Require 6 GB available RAM, for the 4GB string plus 2GB headroom + var pc = new PerformanceCounter ("Mono Memory", "Available Physical Memory"); + + if (pc.RawValue < 6L*1024L*1024L*1024L) + Assert.Ignore("This machine may not have enough RAM to run this test."); +#endif + } + [Test] // ctor (Char, Int32) + [Category ("MobileNotWorking")] public void Constructor4_LargeString () { - try { - var x = new String ('A', int.MaxValue); - if (Environment.Is64BitProcess) { - Assert.AreEqual ('A', x[0]); - Assert.AreEqual ('A', x[int.MaxValue - 1]); - } - else - Assert.Fail ("Expected OutOfMemoryException."); - } catch (OutOfMemoryException) { - } + RequireHighMemoryTestEnvironment(); + + var x = new String ('A', int.MaxValue); + Assert.AreEqual ('A', x[0]); + Assert.AreEqual ('A', x[int.MaxValue - 1]); } [Test] // ctor (Char [], Int32, Int32) @@ -3008,18 +3029,14 @@ public class StringTest } [Test] + [Category ("MobileNotWorking")] public void PadLeft_LargeString () { - try { - var x = "x".PadLeft (int.MaxValue, '-'); - if (Environment.Is64BitProcess) { - Assert.AreEqual ('-', x[0]); - Assert.AreEqual ('x', x[int.MaxValue - 1]); - } - else - Assert.Fail ("Expected OutOfMemoryException."); - } catch (OutOfMemoryException) { - } + RequireHighMemoryTestEnvironment(); + + var x = "x".PadLeft (int.MaxValue, '-'); + Assert.AreEqual ('-', x[0]); + Assert.AreEqual ('x', x[int.MaxValue - 1]); } [Test] // PadRight (Int32) @@ -3064,18 +3081,14 @@ public class StringTest } [Test] + [Category ("MobileNotWorking")] public void PadRight_LargeString () { - try { - var x = "x".PadRight (int.MaxValue, '-'); - if (Environment.Is64BitProcess) { - Assert.AreEqual ('x', x[0]); - Assert.AreEqual ('-', x[int.MaxValue - 1]); - } - else - Assert.Fail ("Expected OutOfMemoryException."); - } catch (OutOfMemoryException) { - } + RequireHighMemoryTestEnvironment(); + + var x = "x".PadRight (int.MaxValue, '-'); + Assert.AreEqual ('x', x[0]); + Assert.AreEqual ('-', x[int.MaxValue - 1]); } [Test] // Remove (Int32, Int32)