Merge pull request #2274 from esdrubal/udpclientreceive
[mono.git] / mcs / class / System / Test / System.Diagnostics / ProcessTest.cs
index 14e5dcdca8e22c5dd813e0ce04260e854b2953ad..602a07d017a487e811174e4909f508256dcba424 100644 (file)
@@ -104,6 +104,7 @@ namespace MonoTests.System.Diagnostics
                        }
                }
 
+#if MONO_FEATURE_PROCESS_START
                [Test] // Start ()
                public void Start1_FileName_Empty ()
                {
@@ -732,8 +733,6 @@ namespace MonoTests.System.Diagnostics
 
                public int bytesRead = -1;
 
-// Not technically a 2.0 only test, but I use lambdas, so I need gmcs
-
                [Test]
                [NUnit.Framework.Category ("MobileNotWorking")]
                // This was for bug #459450
@@ -791,9 +790,11 @@ namespace MonoTests.System.Diagnostics
                        p.StartInfo.RedirectStandardError = true;
 
                        var exitedCalledCounter = 0;
+                       var exited = new ManualResetEventSlim ();
                        p.Exited += (object sender, EventArgs e) => {
                                exitedCalledCounter++;
                                Assert.IsTrue (p.HasExited);
+                               exited.Set ();
                        };
 
                        p.EnableRaisingEvents = true;
@@ -803,6 +804,7 @@ namespace MonoTests.System.Diagnostics
                        p.BeginOutputReadLine ();
                        p.WaitForExit ();
 
+                       exited.Wait (10000);
                        Assert.AreEqual (1, exitedCalledCounter);
                        Thread.Sleep (50);
                        Assert.AreEqual (1, exitedCalledCounter);
@@ -822,9 +824,11 @@ namespace MonoTests.System.Diagnostics
                        p.EnableRaisingEvents = true;
 
                        var exitedCalledCounter = 0;
+                       var exited = new ManualResetEventSlim ();
                        p.Exited += (object sender, EventArgs e) => {
                                exitedCalledCounter++;
                                Assert.IsTrue (p.HasExited);
+                               exited.Set ();
                        };
 
                        p.Start ();
@@ -832,16 +836,52 @@ namespace MonoTests.System.Diagnostics
                        p.BeginOutputReadLine ();
                        p.WaitForExit ();
 
+                       Assert.IsTrue (exited.Wait (10000));
                        Assert.AreEqual (1, exitedCalledCounter);
                        Thread.Sleep (50);
                        Assert.AreEqual (1, exitedCalledCounter);
                }
 
-               
-               private ProcessStartInfo GetCrossPlatformStartInfo ()
+               [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
+               public void TestDisableEventsBeforeExitedEvent ()
                {
-                       return RunningOnUnix ? new ProcessStartInfo ("/bin/ls", "/") : new ProcessStartInfo ("help", "");
+                       Process p = new Process ();
+                       
+                       p.StartInfo = GetCrossPlatformStartInfo ();
+                       p.StartInfo.UseShellExecute = false;
+                       p.StartInfo.RedirectStandardOutput = true;
+                       p.StartInfo.RedirectStandardError = true;
+
+                       p.EnableRaisingEvents = false;
+
+                       var exitedCalledCounter = 0;
+                       p.Exited += (object sender, EventArgs e) => {
+                               exitedCalledCounter++;
+                       };
+
+                       p.Start ();
+                       p.BeginErrorReadLine ();
+                       p.BeginOutputReadLine ();
+                       p.WaitForExit ();
+
+                       Assert.AreEqual (0, exitedCalledCounter);
+               }
+
+               ProcessStartInfo GetCrossPlatformStartInfo ()
+               {
+                       if (RunningOnUnix) {
+                               string path;
+#if MONODROID
+                               path = "/system/bin/ls";
+#else
+                               path = "/bin/ls";
+#endif
+                               return new ProcessStartInfo (path, "/");
+                       } else
+                               return new ProcessStartInfo ("help", "");
                }
+#endif // MONO_FEATURE_PROCESS_START
 
                [Test]
                public void ProcessName_NotStarted ()
@@ -863,6 +903,7 @@ namespace MonoTests.System.Diagnostics
                        Assert.IsNull (e.InnerException, "IOE inner exception should be null");
                }
                
+#if MONO_FEATURE_PROCESS_START
                [Test]
                [NUnit.Framework.Category ("MobileNotWorking")]
                public void ProcessName_AfterExit ()
@@ -893,6 +934,7 @@ namespace MonoTests.System.Diagnostics
                        
                        Assert.IsNull (e.InnerException, "IOE inner exception should be null");
                }
+#endif // MONO_FEATURE_PROCESS_START
 
                [Test]
                public void Handle_ThrowsOnNotStarted ()
@@ -910,7 +952,9 @@ namespace MonoTests.System.Diagnostics
                        Assert.IsFalse (Process.GetCurrentProcess ().HasExited);
                }
 
+#if MONO_FEATURE_PROCESS_START
                [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
                public void DisposeWithDisposedStreams ()
                {
                        var psi = GetCrossPlatformStartInfo ();
@@ -924,6 +968,22 @@ namespace MonoTests.System.Diagnostics
                        p.Dispose ();
                }
 
+               [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
+               public void StandardInputWrite ()
+               {
+                       var psi = GetCrossPlatformStartInfo ();
+                       psi.RedirectStandardInput = true;
+                       psi.RedirectStandardOutput = true;
+                       psi.UseShellExecute = false;
+
+                       using (var p = Process.Start (psi)) {
+                               for (int i = 0; i < 1024 * 9; ++i)
+                                       p.StandardInput.Write ('x');
+                       }
+               }
+#endif // MONO_FEATURE_PROCESS_START
+
                [Test]
                public void Modules () {
                        var modules = Process.GetCurrentProcess ().Modules;