using System.IO;
using System.Text;
using System.Threading;
+using System.Runtime.InteropServices;
using NUnit.Framework;
Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
Assert.IsNull (ex.InnerException, "#4");
Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (2, ex.NativeErrorCode, "#6");
+ // TODO: On windows we get ACCESS_DENIED (5) instead of FILE_NOT_FOUND (2) and .NET
+ // gives ERROR_INVALID_PARAMETER (87). See https://bugzilla.xamarin.com/show_bug.cgi?id=44514
+ Assert.IsTrue (ex.NativeErrorCode == 2 || ex.NativeErrorCode == 5 || ex.NativeErrorCode == 87, "#6");
}
}
Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
Assert.IsNull (ex.InnerException, "#4");
Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (2, ex.NativeErrorCode, "#6");
+ // TODO: On windows we get ACCESS_DENIED (5) instead of FILE_NOT_FOUND (2) and .NET
+ // gives ERROR_INVALID_PARAMETER (87). See https://bugzilla.xamarin.com/show_bug.cgi?id=44514
+ Assert.IsTrue (ex.NativeErrorCode == 2 || ex.NativeErrorCode == 5 || ex.NativeErrorCode == 87, "#6");
}
}
path = "/bin/cat";
#endif
return new ProcessStartInfo (path);
- } else
- return new ProcessStartInfo ("type");
+ } else {
+ var psi = new ProcessStartInfo ("findstr");
+ psi.Arguments = "\"^\"";
+ return psi;
+ }
}
#endif // MONO_FEATURE_PROCESS_START
StringBuilder sb = new StringBuilder ();
sb.AppendFormat ("Could not found: {0} {1}\n", name.Name, name.Version);
- sb.AppendLine ("Looked in assemblies:");
+ sb.AppendLine ("Looked in modules:");
foreach (var o in modules) {
var m = (ProcessModule) o;
}
}
#endif // MONO_FEATURE_PROCESS_START
+
+ [Test]
+ public void GetProcessesByName()
+ {
+ // This should return Process[0] or a Process[] with all the "foo" programs running
+ Process.GetProcessesByName ("foo");
+ }
+
+ [Test]
+ [ExpectedException(typeof(InvalidOperationException))]
+ public void HigherPrivilegeProcessName ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("accessing pid 1, only available on unix");
+
+ string v = Process.GetProcessById (1).ProcessName;
+ }
+
+ [Test]
+ public void NonChildProcessWaitForExit ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("accessing parent pid, only available on unix");
+
+ using (Process process = Process.GetProcessById (getppid ()))
+ {
+ Assert.IsFalse (process.WaitForExit (10), "#1");
+ Assert.IsFalse (process.HasExited, "#2");
+ Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#3");
+
+ process.Exited += (s, e) => Assert.Fail ("#4");
+ process.EnableRaisingEvents = true;
+
+ Assert.IsFalse (process.WaitForExit (10), "#5");
+ Assert.IsFalse (process.HasExited, "#6");
+ Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#7");
+ }
+ }
+
+ [Test]
+ public void NonChildProcessName ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("accessing parent pid, only available on unix");
+
+ using (Process process = Process.GetProcessById (getppid ()))
+ {
+ string pname = process.ProcessName;
+ Assert.IsNotNull (pname, "#1");
+ AssertHelper.IsNotEmpty (pname, "#2");
+ }
+ }
+
+ [Test]
+ public void NonChildProcessId ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("accessing parent pid, only available on unix");
+
+ int ppid;
+ using (Process process = Process.GetProcessById (ppid = getppid ()))
+ {
+ int pid = process.Id;
+ Assert.AreEqual (ppid, pid, "#1");
+ AssertHelper.Greater (pid, 0, "#2");
+ }
+ }
+
+ [DllImport ("libc")]
+ static extern int getppid();
}
}