[System] Remove Process.Start and related API from TvOS/WatchOS.
[mono.git] / mcs / class / System / Test / System.Diagnostics / ProcessTest.cs
index f7d6843d2b5dbecd5f4cfba9c6ea3b54f98fd88a..615b0aed3e694e59c12d6de98f0c83272b707672 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,26 @@ 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]
                public void ProcessName_NotStarted ()
@@ -863,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 ()
@@ -893,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 ()
@@ -909,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 ());
+                       }
+               }
        }
 }