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");
}
}
p.EnableRaisingEvents = false;
- var exitedCalledCounter = 0;
+ ManualResetEvent mre = new ManualResetEvent (false);
p.Exited += (object sender, EventArgs e) => {
- exitedCalledCounter++;
+ mre.Set ();
};
p.Start ();
p.BeginOutputReadLine ();
p.WaitForExit ();
- Assert.AreEqual (0, exitedCalledCounter);
+ Assert.IsFalse (mre.WaitOne (1000));
}
ProcessStartInfo GetCrossPlatformStartInfo ()
} else
return new ProcessStartInfo ("help", "");
}
+
+ ProcessStartInfo GetEchoCrossPlatformStartInfo ()
+ {
+ if (RunningOnUnix) {
+ string path;
+#if MONODROID
+ path = "/system/bin/cat";
+#else
+ path = "/bin/cat";
+#endif
+ return new ProcessStartInfo (path);
+ } else {
+ var psi = new ProcessStartInfo ("findstr");
+ psi.Arguments = "\"^\"";
+ return psi;
+ }
+ }
#endif // MONO_FEATURE_PROCESS_START
[Test]
[NUnit.Framework.Category ("MobileNotWorking")]
public void StandardInputWrite ()
{
- var psi = GetCrossPlatformStartInfo ();
+ var psi = GetEchoCrossPlatformStartInfo ();
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
using (var p = Process.Start (psi)) {
- for (int i = 0; i < 1024 * 9; ++i)
+ // drain stdout
+ p.OutputDataReceived += (s, e) => {};
+ p.BeginOutputReadLine ();
+
+ for (int i = 0; i < 1024 * 9; ++i) {
p.StandardInput.Write ('x');
+ if (i > 0 && i % 128 == 0)
+ p.StandardInput.WriteLine ();
+ }
+
+ p.StandardInput.Close ();
+
+ p.WaitForExit ();
}
}
#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;
Assert.IsTrue (found, sb.ToString ());
}
}
+
+#if MONO_FEATURE_PROCESS_START
+ [Test]
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void TestDoubleBeginOutputReadLine ()
+ {
+ using (Process p = new Process ()) {
+ p.StartInfo = GetCrossPlatformStartInfo ();
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.RedirectStandardOutput = true;
+ p.StartInfo.RedirectStandardError = true;
+
+ p.Start ();
+
+ p.BeginOutputReadLine ();
+ p.BeginOutputReadLine ();
+
+ Assert.Fail ();
+ }
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void TestDoubleBeginErrorReadLine ()
+ {
+ using (Process p = new Process ()) {
+ p.StartInfo = GetCrossPlatformStartInfo ();
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.RedirectStandardOutput = true;
+ p.StartInfo.RedirectStandardError = true;
+
+ p.Start ();
+
+ p.BeginErrorReadLine ();
+ p.BeginErrorReadLine ();
+
+ Assert.Fail ();
+ }
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("MobileNotWorking")]
+ public void TestExitedRaisedTooSoon ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("using sleep command, only available on unix");
+
+ int sleeptime = 5;
+
+ using (Process p = Process.Start("sleep", sleeptime.ToString ())) {
+ ManualResetEvent mre = new ManualResetEvent (false);
+
+ p.EnableRaisingEvents = true;
+ p.Exited += (sender, e) => {
+ mre.Set ();
+ };
+
+ Assert.IsFalse (mre.WaitOne ((sleeptime - 2) * 1000), "Exited triggered before the process returned");
+ }
+ }
+#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;
+ }
}
}