Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@ -14,6 +14,7 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using NUnit.Framework;
@ -22,6 +23,13 @@ namespace MonoTests.System.Diagnostics
[TestFixture]
public class ProcessTest
{
static bool RunningOnUnix {
get {
int p = (int)Environment.OSVersion.Platform;
return ((p == 128) || (p == 4) || (p == 6));
}
}
[Test]
public void GetProcessById_MachineName_Null ()
{
@ -284,7 +292,9 @@ namespace MonoTests.System.Diagnostics
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");
}
}
@ -440,7 +450,9 @@ namespace MonoTests.System.Diagnostics
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");
}
}
@ -724,13 +736,6 @@ namespace MonoTests.System.Diagnostics
bytesRead = stm.EndRead (ar);
}
static bool RunningOnUnix {
get {
int p = (int)Environment.OSVersion.Platform;
return ((p == 128) || (p == 4) || (p == 6));
}
}
public int bytesRead = -1;
[Test]
@ -892,8 +897,11 @@ namespace MonoTests.System.Diagnostics
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
@ -1018,7 +1026,7 @@ namespace MonoTests.System.Diagnostics
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;
@ -1106,5 +1114,71 @@ namespace MonoTests.System.Diagnostics
}
}
#endif // MONO_FEATURE_PROCESS_START
[Test]
[NUnit.Framework.Category ("MobileNotWorking")]
public void GetProcessesByName()
{
// This should return Process[0] or a Process[] with all the "foo" programs running
Process.GetProcessesByName ("foo");
}
[Test]
[NUnit.Framework.Category ("MobileNotWorking")]
public void NonChildProcessWaitForExit ()
{
if (!RunningOnUnix)
Assert.Ignore ("accessing parent pid, only available on unix");
using (Process process = Process.GetProcessById (getppid ()))
using (ManualResetEvent mre = new ManualResetEvent (false))
{
Assert.IsFalse (process.WaitForExit (10), "#1");
Assert.IsFalse (process.HasExited, "#2");
Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#3");
process.Exited += (s, e) => mre.Set ();
process.EnableRaisingEvents = true;
Assert.IsFalse (mre.WaitOne (100), "#4");
Assert.IsFalse (process.WaitForExit (10), "#5");
Assert.IsFalse (process.HasExited, "#6");
Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#7");
}
}
[Test]
[NUnit.Framework.Category ("MobileNotWorking")]
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]
[NUnit.Framework.Category ("MobileNotWorking")]
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();
}
}