3cbb80e2fd55e35310f998ea0728d60b66f1c860
[mono.git] / mcs / class / System / Test / System.Diagnostics / ProcessTest.cs
1 //
2 // ProcessTest.cs - NUnit Test Cases for System.Diagnostics.Process
3 //
4 // Authors:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //   Robert Jordan <robertj@gmx.net>
7 //
8 // (C) 2007 Gert Driesen
9 // 
10
11 using System;
12 using System.ComponentModel;
13 using System.Diagnostics;
14 using System.IO;
15 using System.Text;
16
17 using NUnit.Framework;
18
19 namespace MonoTests.System.Diagnostics
20 {
21         [TestFixture]
22         public class ProcessTest
23         {
24                 [Test]
25                 public void GetProcessById_MachineName_Null ()
26                 {
27                         try {
28                                 Process.GetProcessById (1, (string) null);
29                                 Assert.Fail ("#1");
30                         } catch (ArgumentNullException ex) {
31                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
32                                 Assert.IsNotNull (ex.Message, "#3");
33                                 Assert.IsNotNull (ex.ParamName, "#4");
34                                 Assert.AreEqual ("machineName", ex.ParamName, "#5");
35                                 Assert.IsNull (ex.InnerException, "#6");
36                         }
37                 }
38
39                 [Test]
40                 public void GetProcesses_MachineName_Null ()
41                 {
42                         try {
43                                 Process.GetProcesses ((string) null);
44                                 Assert.Fail ("#1");
45                         } catch (ArgumentNullException ex) {
46                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
47                                 Assert.IsNotNull (ex.Message, "#3");
48                                 Assert.IsNotNull (ex.ParamName, "#4");
49                                 Assert.AreEqual ("machineName", ex.ParamName, "#5");
50                                 Assert.IsNull (ex.InnerException, "#6");
51                         }
52                 }
53
54                 [Test]
55                 public void PriorityClass_NotStarted ()
56                 {
57                         Process process = new Process ();
58                         try {
59                                 process.PriorityClass = ProcessPriorityClass.Normal;
60                                 Assert.Fail ("#A1");
61                         } catch (InvalidOperationException ex) {
62                                 // No process is associated with this object
63                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
64                                 Assert.IsNull (ex.InnerException, "#A3");
65                                 Assert.IsNotNull (ex.Message, "#A4");
66                         }
67
68                         try {
69                                 Assert.Fail ("#B1:" + process.PriorityClass);
70                         } catch (InvalidOperationException ex) {
71                                 // No process is associated with this object
72                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
73                                 Assert.IsNull (ex.InnerException, "#B3");
74                                 Assert.IsNotNull (ex.Message, "#B4");
75                         }
76                 }
77
78                 [Test]
79                 public void PriorityClass_Invalid ()
80                 {
81                         Process process = new Process ();
82                         try {
83                                 process.PriorityClass = (ProcessPriorityClass) 666;
84                                 Assert.Fail ("#1");
85                         } catch (InvalidEnumArgumentException ex) {
86                                 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
87                                 Assert.IsNull (ex.InnerException, "#3");
88                                 Assert.IsNotNull (ex.Message, "#4");
89                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#5");
90                                 Assert.IsTrue (ex.Message.IndexOf (typeof (ProcessPriorityClass).Name) != -1, "#6");
91                                 Assert.IsNotNull (ex.ParamName, "#7");
92                                 Assert.AreEqual ("value", ex.ParamName, "#8");
93                         }
94                 }
95
96                 [Test] // Start ()
97                 public void Start1_FileName_Empty ()
98                 {
99                         Process process = new Process ();
100                         process.StartInfo = new ProcessStartInfo (string.Empty);
101
102                         // no shell
103                         process.StartInfo.UseShellExecute = false;
104                         try {
105                                 process.Start ();
106                                 Assert.Fail ("#A1");
107                         } catch (InvalidOperationException ex) {
108                                 // Cannot start process because a file name has
109                                 // not been provided
110                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
111                                 Assert.IsNull (ex.InnerException, "#A3");
112                                 Assert.IsNotNull (ex.Message, "#A4");
113                         }
114
115                         // shell
116                         process.StartInfo.UseShellExecute = true;
117                         try {
118                                 process.Start ();
119                                 Assert.Fail ("#B1");
120                         } catch (InvalidOperationException ex) {
121                                 // Cannot start process because a file name has
122                                 // not been provided
123                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
124                                 Assert.IsNull (ex.InnerException, "#B3");
125                                 Assert.IsNotNull (ex.Message, "#B4");
126                         }
127                 }
128
129                 [Test] // Start ()
130                 public void Start1_FileName_InvalidPathCharacters ()
131                 {
132                         if (RunningOnUnix)
133                                 // on unix, all characters are allowed
134                                 return;
135
136                         string systemDir = Environment.GetFolderPath (Environment.SpecialFolder.System);
137                         string exe = "\"" + Path.Combine (systemDir, "calc.exe") + "\"";
138
139                         Process process = new Process ();
140                         process.StartInfo = new ProcessStartInfo (exe);
141
142                         // no shell
143                         process.StartInfo.UseShellExecute = false;
144                         Assert.IsTrue (process.Start ());
145                         process.Kill ();
146
147                         // shell
148                         process.StartInfo.UseShellExecute = true;
149                         Assert.IsTrue (process.Start ());
150                         process.Kill ();
151                 }
152
153                 [Test] // Start ()
154                 public void Start1_FileName_NotFound ()
155                 {
156                         Process process = new Process ();
157                         string exe = RunningOnUnix ? exe = "/usr/bin/shouldnoteverexist"
158                                 : @"c:\shouldnoteverexist.exe";
159
160                         // absolute path, no shell
161                         process.StartInfo = new ProcessStartInfo (exe);
162                         process.StartInfo.UseShellExecute = false;
163                         try {
164                                 process.Start ();
165                                 Assert.Fail ("#A1");
166                         } catch (Win32Exception ex) {
167                                 // The system cannot find the file specified
168                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#A2");
169                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#A3");
170                                 Assert.IsNull (ex.InnerException, "#A4");
171                                 Assert.IsNotNull (ex.Message, "#A5");
172                                 Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
173                         }
174
175                         // relative path, no shell
176                         process.StartInfo.FileName = "shouldnoteverexist.exe";
177                         process.StartInfo.UseShellExecute = false;
178                         try {
179                                 process.Start ();
180                                 Assert.Fail ("#B1");
181                         } catch (Win32Exception ex) {
182                                 // The system cannot find the file specified
183                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#B2");
184                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#B3");
185                                 Assert.IsNull (ex.InnerException, "#B4");
186                                 Assert.IsNotNull (ex.Message, "#B5");
187                                 Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
188                         }
189
190                         if (RunningOnUnix)
191                                 Assert.Ignore ("On Unix and Mac OS X, we try " +
192                                         "to open any file (using xdg-open, ...)" +
193                                         " and we do not report an exception " +
194                                         "if this fails.");
195
196                         // absolute path, shell
197                         process.StartInfo.FileName = exe;
198                         process.StartInfo.UseShellExecute = true;
199                         try {
200                                 process.Start ();
201                                 Assert.Fail ("#C1");
202                         } catch (Win32Exception ex) {
203                                 // The system cannot find the file specified
204                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#C2");
205                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#C3");
206                                 Assert.IsNull (ex.InnerException, "#C4");
207                                 Assert.IsNotNull (ex.Message, "#C5");
208                                 Assert.AreEqual (2, ex.NativeErrorCode, "#C6");
209                         }
210
211                         // relative path, shell
212                         process.StartInfo.FileName = "shouldnoteverexist.exe";
213                         process.StartInfo.UseShellExecute = true;
214                         try {
215                                 process.Start ();
216                                 Assert.Fail ("#D1");
217                         } catch (Win32Exception ex) {
218                                 // The system cannot find the file specified
219                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#D2");
220                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#D3");
221                                 Assert.IsNull (ex.InnerException, "#D4");
222                                 Assert.IsNotNull (ex.Message, "#D5");
223                                 Assert.AreEqual (2, ex.NativeErrorCode, "#D6");
224                         }
225                 }
226
227                 [Test] // Start ()
228                 public void Start1_FileName_Null ()
229                 {
230                         Process process = new Process ();
231                         process.StartInfo = new ProcessStartInfo ((string) null);
232
233                         // no shell
234                         process.StartInfo.UseShellExecute = false;
235                         try {
236                                 process.Start ();
237                                 Assert.Fail ("#A1");
238                         } catch (InvalidOperationException ex) {
239                                 // Cannot start process because a file name has
240                                 // not been provided
241                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
242                                 Assert.IsNull (ex.InnerException, "#A3");
243                                 Assert.IsNotNull (ex.Message, "#A4");
244                         }
245
246                         // shell
247                         process.StartInfo.UseShellExecute = true;
248                         try {
249                                 process.Start ();
250                                 Assert.Fail ("#B1");
251                         } catch (InvalidOperationException ex) {
252                                 // Cannot start process because a file name has
253                                 // not been provided
254                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
255                                 Assert.IsNull (ex.InnerException, "#B3");
256                                 Assert.IsNotNull (ex.Message, "#B4");
257                         }
258                 }
259
260                 [Test] // Start ()
261                 public void Start1_FileName_Whitespace ()
262                 {
263                         Process process = new Process ();
264                         process.StartInfo = new ProcessStartInfo (" ");
265                         process.StartInfo.UseShellExecute = false;
266                         try {
267                                 process.Start ();
268                                 Assert.Fail ("#1");
269                         } catch (Win32Exception ex) {
270                                 // The system cannot find the file specified
271                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#2");
272                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
273                                 Assert.IsNull (ex.InnerException, "#4");
274                                 Assert.IsNotNull (ex.Message, "#5");
275                                 Assert.AreEqual (2, ex.NativeErrorCode, "#6");
276                         }
277                 }
278
279                 [Test] // Start (ProcessStartInfo)
280                 public void Start2_FileName_Empty ()
281                 {
282                         ProcessStartInfo startInfo = new ProcessStartInfo (string.Empty);
283
284                         // no shell
285                         startInfo.UseShellExecute = false;
286                         try {
287                                 Process.Start (startInfo);
288                                 Assert.Fail ("#A1");
289                         } catch (InvalidOperationException ex) {
290                                 // Cannot start process because a file name has
291                                 // not been provided
292                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
293                                 Assert.IsNull (ex.InnerException, "#A3");
294                                 Assert.IsNotNull (ex.Message, "#A4");
295                         }
296
297                         // shell
298                         startInfo.UseShellExecute = true;
299                         try {
300                                 Process.Start (startInfo);
301                                 Assert.Fail ("#B1");
302                         } catch (InvalidOperationException ex) {
303                                 // Cannot start process because a file name has
304                                 // not been provided
305                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
306                                 Assert.IsNull (ex.InnerException, "#B3");
307                                 Assert.IsNotNull (ex.Message, "#B4");
308                         }
309                 }
310
311                 [Test] // Start (ProcessStartInfo)
312                 public void Start2_FileName_NotFound ()
313                 {
314                         ProcessStartInfo startInfo = new ProcessStartInfo ();
315                         string exe = RunningOnUnix ? exe = "/usr/bin/shouldnoteverexist"
316                                 : @"c:\shouldnoteverexist.exe";
317
318                         // absolute path, no shell
319                         startInfo.FileName = exe;
320                         startInfo.UseShellExecute = false;
321                         try {
322                                 Process.Start (startInfo);
323                                 Assert.Fail ("#A1");
324                         } catch (Win32Exception ex) {
325                                 // The system cannot find the file specified
326                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#A2");
327                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#A3");
328                                 Assert.IsNull (ex.InnerException, "#A4");
329                                 Assert.IsNotNull (ex.Message, "#A5");
330                                 Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
331                         }
332
333                         // relative path, no shell
334                         startInfo.FileName = "shouldnoteverexist.exe";
335                         startInfo.UseShellExecute = false;
336                         try {
337                                 Process.Start (startInfo);
338                                 Assert.Fail ("#B1");
339                         } catch (Win32Exception ex) {
340                                 // The system cannot find the file specified
341                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#B2");
342                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#B3");
343                                 Assert.IsNull (ex.InnerException, "#B4");
344                                 Assert.IsNotNull (ex.Message, "#B5");
345                                 Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
346                         }
347
348                         if (RunningOnUnix)
349                                 Assert.Ignore ("On Unix and Mac OS X, we try " +
350                                         "to open any file (using xdg-open, ...)" +
351                                         " and we do not report an exception " +
352                                         "if this fails.");
353
354                         // absolute path, shell
355                         startInfo.FileName = exe;
356                         startInfo.UseShellExecute = true;
357                         try {
358                                 Process.Start (startInfo);
359                                 Assert.Fail ("#C1");
360                         } catch (Win32Exception ex) {
361                                 // The system cannot find the file specified
362                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#C2");
363                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#C3");
364                                 Assert.IsNull (ex.InnerException, "#C4");
365                                 Assert.IsNotNull (ex.Message, "#C5");
366                                 Assert.AreEqual (2, ex.NativeErrorCode, "#C6");
367                         }
368
369                         // relative path, shell
370                         startInfo.FileName = "shouldnoteverexist.exe";
371                         startInfo.UseShellExecute = true;
372                         try {
373                                 Process.Start (startInfo);
374                                 Assert.Fail ("#D1");
375                         } catch (Win32Exception ex) {
376                                 // The system cannot find the file specified
377                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#D2");
378                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#D3");
379                                 Assert.IsNull (ex.InnerException, "#D4");
380                                 Assert.IsNotNull (ex.Message, "#D5");
381                                 Assert.AreEqual (2, ex.NativeErrorCode, "#D6");
382                         }
383                 }
384
385                 [Test] // Start (ProcessStartInfo)
386                 public void Start2_FileName_Null ()
387                 {
388                         ProcessStartInfo startInfo = new ProcessStartInfo ((string) null);
389
390                         // no shell
391                         startInfo.UseShellExecute = false;
392                         try {
393                                 Process.Start (startInfo);
394                                 Assert.Fail ("#A1");
395                         } catch (InvalidOperationException ex) {
396                                 // Cannot start process because a file name has
397                                 // not been provided
398                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
399                                 Assert.IsNull (ex.InnerException, "#A3");
400                                 Assert.IsNotNull (ex.Message, "#A4");
401                         }
402
403                         // shell
404                         startInfo.UseShellExecute = true;
405                         try {
406                                 Process.Start (startInfo);
407                                 Assert.Fail ("#B1");
408                         } catch (InvalidOperationException ex) {
409                                 // Cannot start process because a file name has
410                                 // not been provided
411                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
412                                 Assert.IsNull (ex.InnerException, "#B3");
413                                 Assert.IsNotNull (ex.Message, "#B4");
414                         }
415                 }
416
417                 [Test] // Start (ProcessStartInfo)
418                 public void Start2_FileName_Whitespace ()
419                 {
420                         ProcessStartInfo startInfo = new ProcessStartInfo (" ");
421                         startInfo.UseShellExecute = false;
422                         try {
423                                 Process.Start (startInfo);
424                                 Assert.Fail ("#1");
425                         } catch (Win32Exception ex) {
426                                 // The system cannot find the file specified
427                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#2");
428                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
429                                 Assert.IsNull (ex.InnerException, "#4");
430                                 Assert.IsNotNull (ex.Message, "#5");
431                                 Assert.AreEqual (2, ex.NativeErrorCode, "#6");
432                         }
433                 }
434
435                 [Test] // Start (ProcessStartInfo)
436                 public void Start2_StartInfo_Null ()
437                 {
438                         try {
439                                 Process.Start ((ProcessStartInfo) null);
440                                 Assert.Fail ("#1");
441                         } catch (ArgumentNullException ex) {
442                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
443                                 Assert.IsNull (ex.InnerException, "#3");
444                                 Assert.IsNotNull (ex.Message, "#4");
445                                 Assert.IsNotNull (ex.ParamName, "#5");
446                                 Assert.AreEqual ("startInfo", ex.ParamName, "#6");
447                         }
448                 }
449
450                 [Test] // Start (string)
451                 public void Start3_FileName_Empty ()
452                 {
453                         try {
454                                 Process.Start (string.Empty);
455                                 Assert.Fail ("#1");
456                         } catch (InvalidOperationException ex) {
457                                 // Cannot start process because a file name has
458                                 // not been provided
459                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
460                                 Assert.IsNull (ex.InnerException, "#3");
461                                 Assert.IsNotNull (ex.Message, "#4");
462                         }
463                 }
464
465                 [Test] // Start (string)
466                 public void Start3_FileName_NotFound ()
467                 {
468                         if (RunningOnUnix)
469                                 Assert.Ignore ("On Unix and Mac OS X, we try " +
470                                         "to open any file (using xdg-open, ...)" +
471                                         " and we do not report an exception " +
472                                         "if this fails.");
473
474                         string exe = @"c:\shouldnoteverexist.exe";
475
476                         // absolute path, no shell
477                         try {
478                                 Process.Start (exe);
479                                 Assert.Fail ("#A1");
480                         } catch (Win32Exception ex) {
481                                 // The system cannot find the file specified
482                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#A2");
483                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#A3");
484                                 Assert.IsNull (ex.InnerException, "#A4");
485                                 Assert.IsNotNull (ex.Message, "#A5");
486                                 Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
487                         }
488
489                         // relative path, no shell
490                         try {
491                                 Process.Start ("shouldnoteverexist.exe");
492                                 Assert.Fail ("#B1");
493                         } catch (Win32Exception ex) {
494                                 // The system cannot find the file specified
495                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#B2");
496                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#B3");
497                                 Assert.IsNull (ex.InnerException, "#B4");
498                                 Assert.IsNotNull (ex.Message, "#B5");
499                                 Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
500                         }
501                 }
502
503                 [Test] // Start (string)
504                 public void Start3_FileName_Null ()
505                 {
506                         try {
507                                 Process.Start ((string) null);
508                                 Assert.Fail ("#1");
509                         } catch (InvalidOperationException ex) {
510                                 // Cannot start process because a file name has
511                                 // not been provided
512                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
513                                 Assert.IsNull (ex.InnerException, "#3");
514                                 Assert.IsNotNull (ex.Message, "#4");
515                         }
516                 }
517
518                 [Test] // Start (string, string)
519                 public void Start4_Arguments_Null ()
520                 {
521                         if (RunningOnUnix)
522                                 Assert.Ignore ("On Unix and Mac OS X, we try " +
523                                         "to open any file (using xdg-open, ...)" +
524                                         " and we do not report an exception " +
525                                         "if this fails.");
526
527                         string exe = @"c:\shouldnoteverexist.exe";
528
529                         try {
530                                 Process.Start ("whatever.exe", (string) null);
531                                 Assert.Fail ("#1");
532                         } catch (Win32Exception ex) {
533                                 // The system cannot find the file specified
534                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#B2");
535                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#B3");
536                                 Assert.IsNull (ex.InnerException, "#B4");
537                                 Assert.IsNotNull (ex.Message, "#B5");
538                                 Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
539                         }
540                 }
541
542                 [Test] // Start (string, string)
543                 public void Start4_FileName_Empty ()
544                 {
545                         try {
546                                 Process.Start (string.Empty, string.Empty);
547                                 Assert.Fail ("#1");
548                         } catch (InvalidOperationException ex) {
549                                 // Cannot start process because a file name has
550                                 // not been provided
551                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
552                                 Assert.IsNull (ex.InnerException, "#3");
553                                 Assert.IsNotNull (ex.Message, "#4");
554                         }
555                 }
556
557                 [Test] // Start (string, string)
558                 public void Start4_FileName_NotFound ()
559                 {
560                         if (RunningOnUnix)
561                                 Assert.Ignore ("On Unix and Mac OS X, we try " +
562                                         "to open any file (using xdg-open, ...)" +
563                                         " and we do not report an exception " +
564                                         "if this fails.");
565
566                         string exe = @"c:\shouldnoteverexist.exe";
567
568                         // absolute path, no shell
569                         try {
570                                 Process.Start (exe, string.Empty);
571                                 Assert.Fail ("#A1");
572                         } catch (Win32Exception ex) {
573                                 // The system cannot find the file specified
574                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#A2");
575                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#A3");
576                                 Assert.IsNull (ex.InnerException, "#A4");
577                                 Assert.IsNotNull (ex.Message, "#A5");
578                                 Assert.AreEqual (2, ex.NativeErrorCode, "#A6");
579                         }
580
581                         // relative path, no shell
582                         try {
583                                 Process.Start ("shouldnoteverexist.exe", string.Empty);
584                                 Assert.Fail ("#B1");
585                         } catch (Win32Exception ex) {
586                                 // The system cannot find the file specified
587                                 Assert.AreEqual (typeof (Win32Exception), ex.GetType (), "#B2");
588                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#B3");
589                                 Assert.IsNull (ex.InnerException, "#B4");
590                                 Assert.IsNotNull (ex.Message, "#B5");
591                                 Assert.AreEqual (2, ex.NativeErrorCode, "#B6");
592                         }
593                 }
594
595                 [Test] // Start (string, string)
596                 public void Start4_FileName_Null ()
597                 {
598                         try {
599                                 Process.Start ((string) null, string.Empty);
600                                 Assert.Fail ("#1");
601                         } catch (InvalidOperationException ex) {
602                                 // Cannot start process because a file name has
603                                 // not been provided
604                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
605                                 Assert.IsNull (ex.InnerException, "#3");
606                                 Assert.IsNotNull (ex.Message, "#4");
607                         }
608                 }
609
610                 [Test]
611                 public void StartInfo ()
612                 {
613                         ProcessStartInfo startInfo = new ProcessStartInfo ();
614
615                         Process p = new Process ();
616                         Assert.IsNotNull (p.StartInfo, "#A1");
617                         p.StartInfo = startInfo;
618                         Assert.AreSame (startInfo, p.StartInfo, "#A2");
619                 }
620
621                 [Test]
622                 public void StartInfo_Null ()
623                 {
624                         Process p = new Process ();
625                         try {
626                                 p.StartInfo = null;
627                                 Assert.Fail ("#1");
628                         } catch (ArgumentNullException ex) {
629                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
630                                 Assert.IsNull (ex.InnerException, "#3");
631                                 Assert.IsNotNull (ex.Message, "#4");
632                                 Assert.IsNotNull (ex.ParamName, "#5");
633                                 Assert.AreEqual ("value", ex.ParamName, "#6");
634                         }
635                 }
636
637                 [Test]
638                 [NUnit.Framework.Category ("NotDotNet")]
639                 public void TestRedirectedOutputIsAsync ()
640                 {
641                         // Test requires cygwin, so we just bail out for now.
642                         if (Path.DirectorySeparatorChar == '\\')
643                                 return;
644                         
645                         Process p = new Process ();
646                         p.StartInfo = new ProcessStartInfo ("/bin/sh", "-c \"sleep 2; echo hello\"");
647                         p.StartInfo.RedirectStandardOutput = true;
648                         p.StartInfo.UseShellExecute = false;
649                         p.Start ();
650
651                         Stream stdout = p.StandardOutput.BaseStream;
652
653                         byte [] buffer = new byte [200];
654
655                         // start async Read operation
656                         DateTime start = DateTime.Now;
657                         IAsyncResult ar = stdout.BeginRead (buffer, 0, buffer.Length,
658                                                             new AsyncCallback (Read), stdout);
659
660                         Assert.IsTrue ((DateTime.Now - start).TotalMilliseconds < 1000, "#01 BeginRead was not async");
661                         p.WaitForExit ();
662                         Assert.AreEqual (0, p.ExitCode, "#02 script failure");
663
664                         /*
665                         ar.AsyncWaitHandle.WaitOne (2000, false);
666                         if (bytesRead < "hello".Length)
667                                 Assert.Fail ("#03 got {0} bytes", bytesRead);
668                         Assert.AreEqual ("hello", Encoding.Default.GetString (buffer, 0, 5), "#04");
669                         */
670                 }
671
672                 void Read (IAsyncResult ar)
673                 {
674                         Stream stm = (Stream) ar.AsyncState;
675                         bytesRead = stm.EndRead (ar);
676                 }
677
678                 static bool RunningOnUnix {
679                         get {
680                                 PlatformID platform = Environment.OSVersion.Platform;
681 #if NET_2_0
682                                 return platform == PlatformID.Unix;
683 #else
684                                 return ((int) platform) == 128;
685 #endif
686                         }
687                 }
688
689                 int bytesRead = -1;
690         }
691 }