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