[System] Remove Process.Start and related API from TvOS/WatchOS.
[mono.git] / mcs / class / System / Test / System.Diagnostics / ProcessTest.cs
index b286100b932504342602c79ed75073df342023dc..615b0aed3e694e59c12d6de98f0c83272b707672 100644 (file)
@@ -53,6 +53,7 @@ namespace MonoTests.System.Diagnostics
                }
 
                [Test] // Covers #26363
+               [NUnit.Framework.Category ("MobileNotWorking")]
                public void GetProcesses_StartTime ()
                {
                        foreach (var p in Process.GetProcesses ()) {
@@ -103,6 +104,7 @@ namespace MonoTests.System.Diagnostics
                        }
                }
 
+#if MONO_FEATURE_PROCESS_START
                [Test] // Start ()
                public void Start1_FileName_Empty ()
                {
@@ -731,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
@@ -790,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;
@@ -802,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);
@@ -821,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 ();
@@ -831,34 +836,27 @@ namespace MonoTests.System.Diagnostics
                        p.BeginOutputReadLine ();
                        p.WaitForExit ();
 
+                       exited.Wait (10000);
                        Assert.AreEqual (1, exitedCalledCounter);
                        Thread.Sleep (50);
                        Assert.AreEqual (1, exitedCalledCounter);
                }
 
-               
-               private ProcessStartInfo GetCrossPlatformStartInfo ()
+               ProcessStartInfo GetCrossPlatformStartInfo ()
                {
-                       return RunningOnUnix ? new ProcessStartInfo ("/bin/ls", "/") : new ProcessStartInfo ("help", "");
+                       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] // Covers #26362
-               public void TestExitedEvent ()
-               {
-                       var falseExitedEvents = 0;
-                       var cp = Process.GetCurrentProcess ();
-                       foreach (var p in Process.GetProcesses ()) {
-                               if (p.Id != cp.Id && !p.HasExited) {
-                                       p.EnableRaisingEvents = true;
-                                       p.Exited += (s, e) => {
-                                               if (!p.HasExited)
-                                                       falseExitedEvents++;
-                                       };
-                               }
-                       }
-                       Assert.AreEqual (0, falseExitedEvents);
-               }
-               
                [Test]
                public void ProcessName_NotStarted ()
                {
@@ -879,6 +877,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 ()
@@ -909,6 +908,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 ()
@@ -925,5 +925,72 @@ namespace MonoTests.System.Diagnostics
                public void HasExitedCurrent () {
                        Assert.IsFalse (Process.GetCurrentProcess ().HasExited);
                }
+
+#if MONO_FEATURE_PROCESS_START
+               [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
+               public void DisposeWithDisposedStreams ()
+               {
+                       var psi = GetCrossPlatformStartInfo ();
+                       psi.RedirectStandardInput = true;
+                       psi.RedirectStandardOutput = true;
+                       psi.UseShellExecute = false;
+
+                       var p = Process.Start (psi);
+                       p.StandardInput.BaseStream.Dispose ();
+                       p.StandardOutput.BaseStream.Dispose ();
+                       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;
+                       foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
+                               var found = false;
+                               var name = a.GetName ();
+
+                               StringBuilder sb = new StringBuilder ();
+                               sb.AppendFormat ("Could not found: {0} {1}\n", name.Name, name.Version);
+                               sb.AppendLine ("Looked in assemblies:");
+
+                               foreach (var o in modules) {
+                                       var m = (ProcessModule) o;
+
+                                       sb.AppendFormat ("   {0} {1}.{2}.{3}\n", m.FileName.ToString (),
+                                                       m.FileVersionInfo.FileMajorPart,
+                                                       m.FileVersionInfo.FileMinorPart,
+                                                       m.FileVersionInfo.FileBuildPart);
+
+                                       if (!m.FileName.StartsWith ("[In Memory] " + name.Name))
+                                               continue;
+
+                                       var fv = m.FileVersionInfo;
+                                       if (fv.FileBuildPart != name.Version.Build ||
+                                               fv.FileMinorPart != name.Version.Minor ||
+                                               fv.FileMajorPart != name.Version.Major)
+                                               continue;
+
+                                       found = true;
+                               }
+
+                               Assert.IsTrue (found, sb.ToString ());
+                       }
+               }
        }
 }