* ProcessTest.cs: Added null check tests.
authorGert Driesen <drieseng@users.sourceforge.net>
Tue, 2 Jan 2007 15:07:35 +0000 (15:07 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Tue, 2 Jan 2007 15:07:35 +0000 (15:07 -0000)
* Process.cs: Allow GetProcesses and GetProcessById overloads with
machine name to work for local machine.
* System_test.dll.sources: Added ProcessTest.cs.

svn path=/trunk/mcs/; revision=70366

mcs/class/System/ChangeLog
mcs/class/System/System.Diagnostics/ChangeLog
mcs/class/System/System.Diagnostics/Process.cs
mcs/class/System/System_test.dll.sources
mcs/class/System/Test/System.Diagnostics/ChangeLog
mcs/class/System/Test/System.Diagnostics/ProcessTest.cs [new file with mode: 0644]

index f3c46934567226f29414a65dc7cd6ea352065779..0d2627ddcabb8bbc536614090133fc308bc7f9fe 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-02  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * System_test.dll.sources: Added ProcessTest.cs.
+
 2006-12-22  Rolf Bjarne Kvinge  <RKvinge@novell.com>
 
        * System_test.dll.sources: added DefaultBindingPropertyAttributeTest.cs
index 18008435236ca43f68958dfdabb305b05578129a..3ffca1d4835b16997c1050e85b780f01003d5d87 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-02  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * Process.cs: Allow GetProcesses and GetProcessById overloads with 
+       machine name to work for local machine.
+
 2006-12-29  Robert Jordan  <robertj@gmx.net>
 
        * TraceImpl.cs (Assert): Include line numbers in the stack trace
index 930074d7e87a2faeb4c36a939d8386b2ecba52db..3f11b7de381596da7308c4fc256ec56723dae08d 100644 (file)
@@ -776,9 +776,15 @@ namespace System.Diagnostics {
                        return (new Process (proc, processId));
                }
 
-               [MonoTODO]
+               [MonoTODO ("There is no support for retrieving process information from a remote machine")]
                public static Process GetProcessById(int processId, string machineName) {
-                       throw new NotImplementedException();
+                       if (machineName == null)
+                               throw new ArgumentNullException ("machineName");
+
+                       if (!IsLocalMachine (machineName))
+                               throw new NotImplementedException ();
+
+                       return GetProcessById (processId);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -806,7 +812,13 @@ namespace System.Diagnostics {
 
                [MonoTODO ("There is no support for retrieving process information from a remote machine")]
                public static Process[] GetProcesses(string machineName) {
-                       throw new NotImplementedException();
+                       if (machineName == null)
+                               throw new ArgumentNullException ("machineName");
+
+                       if (!IsLocalMachine (machineName))
+                               throw new NotImplementedException ();
+
+                       return GetProcesses ();
                }
 
                public static Process[] GetProcessesByName(string processName)
@@ -1126,6 +1138,13 @@ namespace System.Diagnostics {
                        return(false);
                }
 
+               private static bool IsLocalMachine (string machineName)
+               {
+                       if (machineName == "." || machineName.Length == 0)
+                               return true;
+
+                       return (string.Compare (machineName, Environment.MachineName, true) == 0);
+               }
 
 #if NET_2_0
                public event DataReceivedEventHandler OutputDataReceived;
index 8d093ba403f8d0e602020760e04aa7901e3f7ac1..31a23135f1faa85d8e28daf15830d40ec32efcfa 100644 (file)
@@ -151,6 +151,7 @@ System.Diagnostics/EventLogPermissionTest.cs
 System.Diagnostics/EventSourceCreationDataTest.cs
 System.Diagnostics/PerformanceCounterPermissionAttributeTest.cs
 System.Diagnostics/PerformanceCounterPermissionTest.cs
+System.Diagnostics/ProcessTest.cs
 System.IO/FileSystemWatcherTest.cs
 System.IO.Compression/DeflateStreamTest.cs
 System.IO.Compression/GzipStreamTest.cs
index 7e6e522c8e1894cc6fdea0db679066c0045cef09..ad2ae85c003d3ef70f498c1b6b08d2290d83f1a8 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-02  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * ProcessTest.cs: Added null check tests.
+
 2006-08-27  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * EventLogTest.cs: Added tests for log name validation in 
diff --git a/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs b/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
new file mode 100644 (file)
index 0000000..73a3988
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// ProcessTest.cs - NUnit Test Cases for System.Diagnostics.Process
+//
+// Authors:
+//   Gert Driesen (drieseng@users.sourceforge.net)
+//
+// (C) 2007 Gert Driesen
+// 
+
+using System;
+using System.Diagnostics;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Diagnostics
+{
+       [TestFixture]
+       public class ProcessTest
+       {
+               [Test]
+               public void GetProcessById_MachineName_Null ()
+               {
+                       try {
+                               Process.GetProcessById (1, (string) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+                               Assert.IsNotNull (ex.ParamName, "#4");
+                               Assert.AreEqual ("machineName", ex.ParamName, "#5");
+                               Assert.IsNull (ex.InnerException, "#6");
+                       }
+               }
+
+               [Test]
+               public void GetProcesses_MachineName_Null ()
+               {
+                       try {
+                               Process.GetProcesses ((string) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+                               Assert.IsNotNull (ex.ParamName, "#4");
+                               Assert.AreEqual ("machineName", ex.ParamName, "#5");
+                               Assert.IsNull (ex.InnerException, "#6");
+                       }
+               }
+       }
+}