}
}
+ [Test] // Covers #26363
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ 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 ()
{
}
}
-#if NET_2_0
[Test]
public void Start_UseShellExecuteWithEmptyUserName ()
{
} catch (Win32Exception) {
}
}
-#endif
[Test] // Start (string, string)
public void Start4_FileName_Null ()
public int bytesRead = -1;
-#if NET_2_0
-// 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
Assert.AreEqual (true, r, "Null Argument Events Raised");
}
-
- private ProcessStartInfo GetCrossPlatformStartInfo ()
+
+ [Test]
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ public void TestEnableEventsAfterExitedEvent ()
+ {
+ Process p = new Process ();
+
+ p.StartInfo = GetCrossPlatformStartInfo ();
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.RedirectStandardOutput = true;
+ 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;
+
+ p.Start ();
+ p.BeginErrorReadLine ();
+ p.BeginOutputReadLine ();
+ p.WaitForExit ();
+
+ exited.Wait (10000);
+ Assert.AreEqual (1, exitedCalledCounter);
+ Thread.Sleep (50);
+ Assert.AreEqual (1, exitedCalledCounter);
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ public void TestEnableEventsBeforeExitedEvent ()
{
- 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 = true;
+
+ var exitedCalledCounter = 0;
+ var exited = new ManualResetEventSlim ();
+ p.Exited += (object sender, EventArgs e) => {
+ exitedCalledCounter++;
+ Assert.IsTrue (p.HasExited);
+ exited.Set ();
+ };
+
+ p.Start ();
+ p.BeginErrorReadLine ();
+ p.BeginOutputReadLine ();
+ p.WaitForExit ();
+
+ exited.Wait (10000);
+ Assert.AreEqual (1, exitedCalledCounter);
+ Thread.Sleep (50);
+ Assert.AreEqual (1, 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", "");
+ }
+
[Test]
public void ProcessName_NotStarted ()
{
Assert.IsNull (e.InnerException, "IOE inner exception should be null");
}
-#endif
[Test]
public void Handle_ThrowsOnNotStarted ()
} catch (InvalidOperationException) {
}
}
+
+ [Test]
+ public void HasExitedCurrent () {
+ Assert.IsFalse (Process.GetCurrentProcess ().HasExited);
+ }
+
+ [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');
+ }
+ }
+
+ [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 ());
+ }
+ }
}
}