Author: gert
Date: 2007-12-04 11:37:36 -0500 (Tue, 04 Dec 2007)
New Revision: 90693
Modified:
trunk/mcs/class/System/System.Diagnostics/ChangeLog
trunk/mcs/class/System/System.Diagnostics/Process.cs
trunk/mcs/class/System/Test/System.Diagnostics/ChangeLog
trunk/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
Log:
* Process.cs: Modified StartInfo to throw ArgumentNullException when
value is set to null, instead of ArgumentException. Remove check if
file name is rooted and exists when UseShellExecute is false, and let
runtime handle this. Fixes bug #345565. When a process cannot be started, do
not access ProcessStartInfo.EnvironmentVariables since that would not allow us
to re-use the instance when changing UseShellExecute. Added argument check in
Start (ProcessStartInfo). Code formatting.
* ProcessTest.cs: Added tests for Start overloads.
Modified: trunk/mcs/class/System/System.Diagnostics/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Diagnostics/ChangeLog 2007-12-04 16:34:19 UTC
(rev 90692)
+++ trunk/mcs/class/System/System.Diagnostics/ChangeLog 2007-12-04 16:37:36 UTC
(rev 90693)
@@ -1,3 +1,14 @@
+2007-12-04 Gert Driesen <[EMAIL PROTECTED]>
+
+ * Process.cs: Modified StartInfo to throw ArgumentNullException when
+ value is set to null, instead of ArgumentException. Remove check if
+ file name is rooted and exists when UseShellExecute is false, and let
+ runtime handle this. Fixes bug #3455655. When a process cannot be
+ started, do not access ProcessStartInfo.EnvironmentVariables since that
+ would not allow us to re-use the instance when changing
+ UseShellExecute. Added argument check in Start (ProcessStartInfo).
+ Code formatting.
+
2007-11-16 Jb Evain <[EMAIL PROTECTED]>
* Debug_2_1.cs: simply write debug messages to the
Modified: trunk/mcs/class/System/System.Diagnostics/Process.cs
===================================================================
--- trunk/mcs/class/System/System.Diagnostics/Process.cs 2007-12-04
16:34:19 UTC (rev 90692)
+++ trunk/mcs/class/System/System.Diagnostics/Process.cs 2007-12-04
16:37:36 UTC (rev 90693)
@@ -658,18 +658,14 @@
[MonitoringDescription ("Information for the start of this
process.")]
public ProcessStartInfo StartInfo {
get {
- if(start_info==null) {
- start_info=new ProcessStartInfo();
- }
-
- return(start_info);
+ if (start_info == null)
+ start_info = new ProcessStartInfo();
+ return start_info;
}
set {
- if(value==null) {
- throw new ArgumentException("value is
null");
- }
-
- start_info=value;
+ if (value == null)
+ throw new
ArgumentNullException("value");
+ start_info = value;
}
}
@@ -911,7 +907,7 @@
}
public void Refresh ()
- {
+ {
// FIXME: should refresh any cached data we might have
about
// the process (currently we have none).
}
@@ -967,8 +963,6 @@
private static bool Start_noshell (ProcessStartInfo startInfo,
Process process)
{
- if (Path.IsPathRooted (startInfo.FileName) &&
!File.Exists (startInfo.FileName))
- throw new FileNotFoundException ("Executable
not found: " + startInfo.FileName);
ProcInfo proc_info=new ProcInfo();
IntPtr stdin_rd, stdin_wr;
IntPtr stdout_wr;
@@ -1069,11 +1063,10 @@
MonoIO.Close (stderr_wr, out error);
}
- throw new Win32Exception (-proc_info.pid,
- "ApplicationName='"+startInfo.FileName+
- "', CommandLine='"+startInfo.Arguments+
- "',
CurrentDirectory='"+startInfo.WorkingDirectory+
- "',
PATH='"+startInfo.EnvironmentVariables["PATH"]+"'");
+ throw new Win32Exception (-proc_info.pid,
+ "ApplicationName='" +
startInfo.FileName +
+ "', CommandLine='" +
startInfo.Arguments +
+ "', CurrentDirectory='" +
startInfo.WorkingDirectory + "'");
}
process.process_handle = proc_info.process_handle;
@@ -1150,40 +1143,35 @@
}
}
- public bool Start() {
- bool ret;
-
+ public bool Start ()
+ {
if (process_handle != IntPtr.Zero) {
Process_free_internal (process_handle);
process_handle = IntPtr.Zero;
}
- ret=Start_common(start_info, this);
-
- return(ret);
+ return Start_common(start_info, this);
}
- public static Process Start(ProcessStartInfo startInfo) {
+ public static Process Start (ProcessStartInfo startInfo)
+ {
+ if (startInfo == null)
+ throw new ArgumentNullException ("startInfo");
Process process=new Process();
- bool ret;
-
process.StartInfo = startInfo;
- ret=Start_common(startInfo, process);
-
- if(ret==true) {
- return(process);
- } else {
- return(null);
- }
+ if (Start_common(startInfo, process))
+ return process;
+ return null;
}
- public static Process Start(string fileName) {
- return Start(new ProcessStartInfo(fileName));
+ public static Process Start (string fileName)
+ {
+ return Start (new ProcessStartInfo (fileName));
}
- public static Process Start(string fileName,
- string arguments) {
- return Start(new ProcessStartInfo(fileName, arguments));
+ public static Process Start(string fileName, string arguments)
+ {
+ return Start (new ProcessStartInfo (fileName,
arguments));
}
#if NET_2_0
@@ -1201,9 +1189,9 @@
}
#endif
- public override string ToString() {
- return(base.ToString() +
- " (" + this.ProcessName + ")");
+ public override string ToString()
+ {
+ return(base.ToString() + " (" + this.ProcessName + ")");
}
/* Waits up to ms milliseconds for process 'handle' to
Modified: trunk/mcs/class/System/Test/System.Diagnostics/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Diagnostics/ChangeLog 2007-12-04
16:34:19 UTC (rev 90692)
+++ trunk/mcs/class/System/Test/System.Diagnostics/ChangeLog 2007-12-04
16:37:36 UTC (rev 90693)
@@ -1,3 +1,7 @@
+2007-12-04 Gert Driesen <[EMAIL PROTECTED]>
+
+ * ProcessTest.cs: Added tests for Start overloads.
+
2007-11-02 Robert Jordan <[EMAIL PROTECTED]>
* ProcessTest.cs (TestRedirectedOutputIsAsync):
Modified: trunk/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
2007-12-04 16:34:19 UTC (rev 90692)
+++ trunk/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
2007-12-04 16:37:36 UTC (rev 90693)
@@ -9,6 +9,7 @@
//
using System;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
@@ -50,8 +51,549 @@
}
}
+ [Test] // Start ()
+ public void Start1_FileName_Empty ()
+ {
+ Process process = new Process ();
+ process.StartInfo = new ProcessStartInfo (string.Empty);
+
+ // no shell
+ process.StartInfo.UseShellExecute = false;
+ try {
+ process.Start ();
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ // shell
+ process.StartInfo.UseShellExecute = true;
+ try {
+ process.Start ();
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+
+ [Test] // Start ()
+ public void Start1_FileName_InvalidPathCharacters ()
+ {
+ if (RunningOnUnix)
+ // on unix, all characters are allowed
+ return;
+
+ string systemDir = Environment.GetFolderPath
(Environment.SpecialFolder.System);
+ string exe = "\"" + Path.Combine (systemDir,
"calc.exe") + "\"";
+
+ Process process = new Process ();
+ process.StartInfo = new ProcessStartInfo (exe);
+
+ // no shell
+ process.StartInfo.UseShellExecute = false;
+ Assert.IsTrue (process.Start ());
+ process.Kill ();
+
+ // shell
+ process.StartInfo.UseShellExecute = true;
+ Assert.IsTrue (process.Start ());
+ process.Kill ();
+ }
+
+ [Test] // Start ()
+ public void Start1_FileName_NotFound ()
+ {
+ Process process = new Process ();
+ string exe = RunningOnUnix ? exe =
"/usr/bin/shouldnoteverexist"
+ : @"c:\shouldnoteverexist.exe";
+
+ // absolute path, no shell
+ process.StartInfo = new ProcessStartInfo (exe);
+ process.StartInfo.UseShellExecute = false;
+ try {
+ process.Start ();
+ Assert.Fail ("#A1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#A2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#A3");
+ Assert.IsNull (ex.InnerException, "#A4");
+ Assert.IsNotNull (ex.Message, "#A5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
+ }
+
+ // relative path, no shell
+ process.StartInfo.FileName = "shouldnoteverexist.exe";
+ process.StartInfo.UseShellExecute = false;
+ try {
+ process.Start ();
+ Assert.Fail ("#B1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#B2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
+ }
+
+ if (RunningOnUnix)
+ Assert.Ignore ("On Unix and Mac OS X, we try " +
+ "to open any file (using xdg-open,
...)" +
+ " and we do not report an exception " +
+ "if this fails.");
+
+ // absolute path, shell
+ process.StartInfo.FileName = exe;
+ process.StartInfo.UseShellExecute = true;
+ try {
+ process.Start ();
+ Assert.Fail ("#C1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#C2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#C3");
+ Assert.IsNull (ex.InnerException, "#C4");
+ Assert.IsNotNull (ex.Message, "#C5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#C6");
+ }
+
+ // relative path, shell
+ process.StartInfo.FileName = "shouldnoteverexist.exe";
+ process.StartInfo.UseShellExecute = true;
+ try {
+ process.Start ();
+ Assert.Fail ("#D1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#D2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#D3");
+ Assert.IsNull (ex.InnerException, "#D4");
+ Assert.IsNotNull (ex.Message, "#D5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#D6");
+ }
+ }
+
+ [Test] // Start ()
+ public void Start1_FileName_Null ()
+ {
+ Process process = new Process ();
+ process.StartInfo = new ProcessStartInfo ((string)
null);
+
+ // no shell
+ process.StartInfo.UseShellExecute = false;
+ try {
+ process.Start ();
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ // shell
+ process.StartInfo.UseShellExecute = true;
+ try {
+ process.Start ();
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+
+ [Test] // Start ()
+ public void Start1_FileName_Whitespace ()
+ {
+ Process process = new Process ();
+ process.StartInfo = new ProcessStartInfo (" ");
+ process.StartInfo.UseShellExecute = false;
+ try {
+ process.Start ();
+ Assert.Fail ("#1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#6");
+ }
+ }
+
+ [Test] // Start (ProcessStartInfo)
+ public void Start2_FileName_Empty ()
+ {
+ ProcessStartInfo startInfo = new ProcessStartInfo
(string.Empty);
+
+ // no shell
+ startInfo.UseShellExecute = false;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ // shell
+ startInfo.UseShellExecute = true;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+
+ [Test] // Start (ProcessStartInfo)
+ public void Start2_FileName_NotFound ()
+ {
+ ProcessStartInfo startInfo = new ProcessStartInfo ();
+ string exe = RunningOnUnix ? exe =
"/usr/bin/shouldnoteverexist"
+ : @"c:\shouldnoteverexist.exe";
+
+ // absolute path, no shell
+ startInfo.FileName = exe;
+ startInfo.UseShellExecute = false;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#A1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#A2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#A3");
+ Assert.IsNull (ex.InnerException, "#A4");
+ Assert.IsNotNull (ex.Message, "#A5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
+ }
+
+ // relative path, no shell
+ startInfo.FileName = "shouldnoteverexist.exe";
+ startInfo.UseShellExecute = false;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#B1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#B2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
+ }
+
+ if (RunningOnUnix)
+ Assert.Ignore ("On Unix and Mac OS X, we try " +
+ "to open any file (using xdg-open,
...)" +
+ " and we do not report an exception " +
+ "if this fails.");
+
+ // absolute path, shell
+ startInfo.FileName = exe;
+ startInfo.UseShellExecute = true;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#C1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#C2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#C3");
+ Assert.IsNull (ex.InnerException, "#C4");
+ Assert.IsNotNull (ex.Message, "#C5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#C6");
+ }
+
+ // relative path, shell
+ startInfo.FileName = "shouldnoteverexist.exe";
+ startInfo.UseShellExecute = true;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#D1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#D2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#D3");
+ Assert.IsNull (ex.InnerException, "#D4");
+ Assert.IsNotNull (ex.Message, "#D5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#D6");
+ }
+ }
+
+ [Test] // Start (ProcessStartInfo)
+ public void Start2_FileName_Null ()
+ {
+ ProcessStartInfo startInfo = new ProcessStartInfo
((string) null);
+
+ // no shell
+ startInfo.UseShellExecute = false;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ // shell
+ startInfo.UseShellExecute = true;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+
+ [Test] // Start (ProcessStartInfo)
+ public void Start2_FileName_Whitespace ()
+ {
+ ProcessStartInfo startInfo = new ProcessStartInfo (" ");
+ startInfo.UseShellExecute = false;
+ try {
+ Process.Start (startInfo);
+ Assert.Fail ("#1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#6");
+ }
+ }
+
+ [Test] // Start (ProcessStartInfo)
+ public void Start2_StartInfo_Null ()
+ {
+ try {
+ Process.Start ((ProcessStartInfo) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof
(ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNotNull (ex.ParamName, "#5");
+ Assert.AreEqual ("startInfo", ex.ParamName,
"#6");
+ }
+ }
+
+ [Test] // Start (string)
+ public void Start3_FileName_Empty ()
+ {
+ try {
+ Process.Start (string.Empty);
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
+ [Test] // Start (string)
+ public void Start3_FileName_NotFound ()
+ {
+ if (RunningOnUnix)
+ Assert.Ignore ("On Unix and Mac OS X, we try " +
+ "to open any file (using xdg-open,
...)" +
+ " and we do not report an exception " +
+ "if this fails.");
+
+ string exe = @"c:\shouldnoteverexist.exe";
+
+ // absolute path, no shell
+ try {
+ Process.Start (exe);
+ Assert.Fail ("#A1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#A2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#A3");
+ Assert.IsNull (ex.InnerException, "#A4");
+ Assert.IsNotNull (ex.Message, "#A5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
+ }
+
+ // relative path, no shell
+ try {
+ Process.Start ("shouldnoteverexist.exe");
+ Assert.Fail ("#B1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#B2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
+ }
+ }
+
+ [Test] // Start (string)
+ public void Start3_FileName_Null ()
+ {
+ try {
+ Process.Start ((string) null);
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
+ [Test] // Start (string, string)
+ public void Start4_Arguments_Null ()
+ {
+ if (RunningOnUnix)
+ Assert.Ignore ("On Unix and Mac OS X, we try " +
+ "to open any file (using xdg-open,
...)" +
+ " and we do not report an exception " +
+ "if this fails.");
+
+ string exe = @"c:\shouldnoteverexist.exe";
+
+ try {
+ Process.Start ("whatever.exe", (string) null);
+ Assert.Fail ("#1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#B2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
+ }
+ }
+
+ [Test] // Start (string, string)
+ public void Start4_FileName_Empty ()
+ {
+ try {
+ Process.Start (string.Empty, string.Empty);
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
+ [Test] // Start (string, string)
+ public void Start4_FileName_NotFound ()
+ {
+ if (RunningOnUnix)
+ Assert.Ignore ("On Unix and Mac OS X, we try " +
+ "to open any file (using xdg-open,
...)" +
+ " and we do not report an exception " +
+ "if this fails.");
+
+ string exe = @"c:\shouldnoteverexist.exe";
+
+ // absolute path, no shell
+ try {
+ Process.Start (exe, string.Empty);
+ Assert.Fail ("#A1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#A2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#A3");
+ Assert.IsNull (ex.InnerException, "#A4");
+ Assert.IsNotNull (ex.Message, "#A5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
+ }
+
+ // relative path, no shell
+ try {
+ Process.Start ("shouldnoteverexist.exe",
string.Empty);
+ Assert.Fail ("#B1");
+ } catch (Win32Exception ex) {
+ // The system cannot find the file specified
+ Assert.AreEqual (typeof (Win32Exception),
ex.GetType (), "#B2");
+ Assert.AreEqual (-2147467259, ex.ErrorCode,
"#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
+ }
+ }
+
+ [Test] // Start (string, string)
+ public void Start4_FileName_Null ()
+ {
+ try {
+ Process.Start ((string) null, string.Empty);
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // Cannot start process because a file name has
+ // not been provided
+ Assert.AreEqual (typeof
(InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
[Test]
- [Category ("NotDotNet")]
+ public void StartInfo ()
+ {
+ ProcessStartInfo startInfo = new ProcessStartInfo ();
+
+ Process p = new Process ();
+ Assert.IsNotNull (p.StartInfo, "#A1");
+ p.StartInfo = startInfo;
+ Assert.AreSame (startInfo, p.StartInfo, "#A2");
+ }
+
+ [Test]
+ public void StartInfo_Null ()
+ {
+ Process p = new Process ();
+ try {
+ p.StartInfo = null;
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof
(ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNotNull (ex.ParamName, "#5");
+ Assert.AreEqual ("value", ex.ParamName, "#6");
+ }
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("NotDotNet")]
public void TestRedirectedOutputIsAsync ()
{
// Test requires cygwin, so we just bail out for now.
@@ -91,6 +633,17 @@
bytesRead = stm.EndRead (ar);
}
+ static bool RunningOnUnix {
+ get {
+ PlatformID platform =
Environment.OSVersion.Platform;
+#if NET_2_0
+ return platform == PlatformID.Unix;
+#else
+ return ((int) platform) == 128;
+#endif
+ }
+ }
+
int bytesRead = -1;
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches