Merge pull request #1624 from esdrubal/getprocesstimes
[mono.git] / mcs / class / System / Test / System.Diagnostics / ProcessTest.cs
index 2778832d555aec1ab79f018536ced1c02a4c749b..de12a43d3cfc5bc82742870ecb5fe81e345725ee 100644 (file)
@@ -52,6 +52,15 @@ namespace MonoTests.System.Diagnostics
                        }
                }
 
+               [Test] // Covers #26363
+               public void GetProcesses_StartTime ()
+               {
+                       foreach (var p in Process.GetProcesses ()) {
+                               if (!p.HasExited && p.StartTime.Year < 1800)
+                                       Assert.Fail ("Process should not be started since the 18th century.");
+                       }
+               }
+
                [Test]
                public void PriorityClass_NotStarted ()
                {
@@ -132,7 +141,7 @@ namespace MonoTests.System.Diagnostics
                {
                        if (RunningOnUnix)
                                // on unix, all characters are allowed
-                               return;
+                               Assert.Ignore ("Running on Unix.");
 
                        string systemDir = Environment.GetFolderPath (Environment.SpecialFolder.System);
                        string exe = "\"" + Path.Combine (systemDir, "calc.exe") + "\"";
@@ -593,7 +602,6 @@ namespace MonoTests.System.Diagnostics
                        }
                }
 
-#if NET_2_0            
                [Test]
                public void Start_UseShellExecuteWithEmptyUserName ()
                {
@@ -629,7 +637,6 @@ namespace MonoTests.System.Diagnostics
                        } catch (Win32Exception) {
                        }
                }
-#endif
                
                [Test] // Start (string, string)
                public void Start4_FileName_Null ()
@@ -680,7 +687,7 @@ namespace MonoTests.System.Diagnostics
                {
                        // Test requires cygwin, so we just bail out for now.
                        if (Path.DirectorySeparatorChar == '\\')
-                               return;
+                               Assert.Ignore ("Test requires cygwin.");
                        
                        Process p = new Process ();
                        p.StartInfo = new ProcessStartInfo ("/bin/sh", "-c \"sleep 2; echo hello\"");
@@ -722,9 +729,8 @@ namespace MonoTests.System.Diagnostics
                        }
                }
 
-               int bytesRead = -1;
+               public int bytesRead = -1;
 
-#if NET_2_0
 // Not technically a 2.0 only test, but I use lambdas, so I need gmcs
 
                [Test]
@@ -827,6 +833,21 @@ namespace MonoTests.System.Diagnostics
                        
                        Assert.IsNull (e.InnerException, "IOE inner exception should be null");
                }
-#endif
+
+               [Test]
+               public void Handle_ThrowsOnNotStarted ()
+               {
+                       Process p = new Process ();
+                       try {
+                               var x = p.Handle;
+                               Assert.Fail ("Handle should throw for unstated procs, but returned " + x);
+                       } catch (InvalidOperationException) {
+                       }
+               }
+
+               [Test]
+               public void HasExitedCurrent () {
+                       Assert.IsFalse (Process.GetCurrentProcess ().HasExited);
+               }
        }
 }