Merge pull request #3600 from henricm/fix-win-network-info-tests
[mono.git] / mcs / class / corlib / Test / System / StringTest.cs
index 293479eb851d41f9a6c6a9e89f083f3743b88257..be5e7984757b64a30bba3b7274a9f86edfab970f 100644 (file)
@@ -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,6 +96,38 @@ 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 ()
+       {
+               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)
        public void Constructor6 ()
        {
@@ -2993,12 +3029,14 @@ public class StringTest
        }
 
        [Test]
-       public void PadLeft_Overflow ()
+       [Category ("MobileNotWorking")]
+       public void PadLeft_LargeString ()
        {
-               try {
-                       "x".PadLeft (int.MaxValue, '-');
-               } catch (OutOfMemoryException) {
-               }
+               RequireHighMemoryTestEnvironment();
+
+               var x = "x".PadLeft (int.MaxValue, '-');
+               Assert.AreEqual ('-', x[0]);
+               Assert.AreEqual ('x', x[int.MaxValue - 1]);
        }
 
        [Test] // PadRight (Int32)
@@ -3043,12 +3081,14 @@ public class StringTest
        }
 
        [Test]
-       public void PadRight_Overflow ()
+       [Category ("MobileNotWorking")]
+       public void PadRight_LargeString ()
        {
-               try {
-                       "x".PadRight (int.MaxValue, '-');
-               } catch (OutOfMemoryException) {
-               }
+               RequireHighMemoryTestEnvironment();
+
+               var x = "x".PadRight (int.MaxValue, '-');
+               Assert.AreEqual ('x', x[0]);
+               Assert.AreEqual ('-', x[int.MaxValue - 1]);
        }
 
        [Test] // Remove (Int32, Int32)