Added implementation for System.Net.Dns.BeginResolve() and System.Net.Dns.EndResolve...
authorMads Pultz <mpultz@mono-cvs.ximian.com>
Mon, 11 Feb 2002 10:12:25 +0000 (10:12 -0000)
committerMads Pultz <mpultz@mono-cvs.ximian.com>
Mon, 11 Feb 2002 10:12:25 +0000 (10:12 -0000)
svn path=/trunk/mcs/; revision=2312

mcs/class/System/System.Net/Dns.cs
mcs/class/System/Test/DnsTest.cs
mcs/class/System/Test/System.Net/DnsTest.cs

index da8b18e40f9062877d80919fb4bf9da1fff32dcf..f08f2f85a340c4d289c30f975607ec55b4a50527 100644 (file)
@@ -12,196 +12,195 @@ using System.Threading;
 using System.Runtime.CompilerServices;
 
 namespace System.Net {
+        public sealed class Dns {
+                
+                /// <summary>
+                /// Helper class
+                /// </summary>
+                private sealed class DnsAsyncResult: IAsyncResult {
+                        private object state;
+                        private WaitHandle waitHandle;
+                        private bool completedSync, completed;
+                        private Worker worker;
+                
+                        public DnsAsyncResult(object state) {
+                                this.state = state;
+                                waitHandle = new ManualResetEvent(false);
+                                completedSync = completed = false;
+                        }       
+                        public object AsyncState {
+                                get { return state; }
+                        }
+                        public WaitHandle AsyncWaitHandle {
+                                set { waitHandle = value; }
+                                get { return waitHandle; }
+                        }
+                        public bool CompletedSynchronously {
+                                get { return completedSync; }
+                        }
+                        public bool IsCompleted {
+                                set { completed = value; }
+                                get { return completed; }
+                        }
+                        public Worker Worker {
+                                set { worker = value; }
+                                get { return worker; }
+                        }
+                }
 
-       public sealed class Dns {
-               
-               /// <summary>
-               /// Helper class
-               /// </summary>
-               private sealed class DnsAsyncResult: IAsyncResult {
-                       private object state;
-                       private WaitHandle waitHandle;
-                       private bool completedSync, completed;
-                       private Worker worker;
-               
-                       public DnsAsyncResult(object state) {
-                               this.state = state;
-                               waitHandle = new ManualResetEvent(false);
-                               completedSync = completed = false;
-                       }       
-                       public object AsyncState {
-                               get { return state; }
-                       }
-                       public WaitHandle AsyncWaitHandle {
-                               set { waitHandle = value; }
-                               get { return waitHandle; }
-                       }
-                       public bool CompletedSynchronously {
-                               get { return completedSync; }
-                       }
-                       public bool IsCompleted {
-                               set { completed = value; }
-                               get { return completed; }
-                       }
-                       public Worker Worker {
-                               set { worker = value; }
-                               get { return worker; }
-                       }
-               }
-
-               /// <summary>
-               /// Helper class for asynchronous calls to DNS server
-               /// </summary>
-               private sealed class Worker {
-                       private AsyncCallback reqCallback;
-                       private DnsAsyncResult reqRes;
-                       private string req;
-                       private IPHostEntry result;
-                       
-                       public Worker(string req, AsyncCallback reqCallback, DnsAsyncResult reqRes) {
-                               this.req = req;
-                               this.reqCallback = reqCallback;
-                               this.reqRes = reqRes;
-                       }
-                       private void End() {
-                               reqCallback(reqRes);
-                               ((ManualResetEvent)reqRes.AsyncWaitHandle).Set();
-                               reqRes.IsCompleted = true;
-                       }
-                       public void GetHostByName() {
-                               lock(reqRes) {
-                                       result = Dns.GetHostByName(req);
-                                       End();
-                               }
-                       }
-                       public void Resolve() {
-                               lock(reqRes) {
-                                       result = Dns.Resolve(req);
-                                       End();
-                               }
-                       }
-                       public IPHostEntry Result {
-                               get { return result; }
-                       }
-               }
-               
-               public static IAsyncResult BeginGetHostByName(string hostName,
-                                                  AsyncCallback requestCallback,
-                                                  object stateObject) {
+                /// <summary>
+                /// Helper class for asynchronous calls to DNS server
+                /// </summary>
+                private sealed class Worker {
+                        private AsyncCallback reqCallback;
+                        private DnsAsyncResult reqRes;
+                        private string req;
+                        private IPHostEntry result;
+                        
+                        public Worker(string req, AsyncCallback reqCallback, DnsAsyncResult reqRes) {
+                                this.req = req;
+                                this.reqCallback = reqCallback;
+                                this.reqRes = reqRes;
+                        }
+                        private void End() {
+                                reqCallback(reqRes);
+                                ((ManualResetEvent)reqRes.AsyncWaitHandle).Set();
+                                reqRes.IsCompleted = true;
+                        }
+                        public void GetHostByName() {
+                                lock(reqRes) {
+                                        result = Dns.GetHostByName(req);
+                                        End();
+                                }
+                        }
+                        public void Resolve() {
+                                lock(reqRes) {
+                                        result = Dns.Resolve(req);
+                                        End();
+                                }
+                        }
+                        public IPHostEntry Result {
+                                get { return result; }
+                        }
+                }
+                
+                public static IAsyncResult BeginGetHostByName(string hostName,
+                       AsyncCallback requestCallback, object stateObject)
+                       {
                         DnsAsyncResult requestResult = new DnsAsyncResult(stateObject);
                         Worker worker = new Worker(hostName, requestCallback, requestResult);
-                       Thread child = new Thread(new ThreadStart(worker.GetHostByName));
+                        Thread child = new Thread(new ThreadStart(worker.GetHostByName));
                         child.Start();
                         return requestResult;
-               }
+                }
 
-               [MonoTODO]
-               public static IAsyncResult BeginResolve(string hostName,
-                                               AsyncCallback requestCallback,
-                                               object stateObject) {
-                       // TODO
-                       throw new NotImplementedException();
-               }
-               
-               public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) {
-                       return ((DnsAsyncResult)asyncResult).Worker.Result;
-               }
+                public static IAsyncResult BeginResolve(string hostName,
+                       AsyncCallback requestCallback, object stateObject)
+                {
+                        DnsAsyncResult requestResult = new DnsAsyncResult(stateObject);
+                        Worker worker = new Worker(hostName, requestCallback, requestResult);
+                        Thread child = new Thread(new ThreadStart(worker.Resolve));
+                        child.Start();
+                        return requestResult;
+                }
+                
+                public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) {
+                        return ((DnsAsyncResult)asyncResult).Worker.Result;
+                }
 
-               [MonoTODO]
-               public static IPHostEntry EndResolve(IAsyncResult asyncResult) {
-                       // TODO
-                       throw new NotImplementedException();
-               }
-               
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern static bool GetHostByName_internal(string host, out string h_name, out string[] h_aliases, out string[] h_addr_list);
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern static bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list);
-               
-               private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist) {
-                       IPHostEntry he = new IPHostEntry();
-                       IPAddress[] addrlist = new IPAddress[h_addrlist.Length];
-                       
-                       he.HostName=h_name;
-                       he.Aliases=h_aliases;
-                       for(int i=0; i<h_addrlist.Length; i++) {
-                               addrlist[i]=IPAddress.Parse(h_addrlist[i]);
-                       }
-                       he.AddressList=addrlist;
+                public static IPHostEntry EndResolve(IAsyncResult asyncResult) {
+                        return ((DnsAsyncResult)asyncResult).Worker.Result;
+                }
+                
+                
+                [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                private extern static bool GetHostByName_internal(string host, out string h_name, out string[] h_aliases, out string[] h_addr_list);
+                [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                private extern static bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list);
+                
+                private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist) {
+                        IPHostEntry he = new IPHostEntry();
+                        IPAddress[] addrlist = new IPAddress[h_addrlist.Length];
+                        
+                        he.HostName=h_name;
+                        he.Aliases=h_aliases;
+                        for(int i=0; i<h_addrlist.Length; i++) {
+                                addrlist[i]=IPAddress.Parse(h_addrlist[i]);
+                        }
+                        he.AddressList=addrlist;
 
-                       return(he);
-               }
+                        return(he);
+                }
 
-               public static IPHostEntry GetHostByAddress(IPAddress address) {
-                       if (address == null)
-                               throw new ArgumentNullException();
-                       return GetHostByAddress(address.ToString());
-               }
-               
-               public static IPHostEntry GetHostByAddress(string address) {
-                       if (address == null) {
-                               throw new ArgumentNullException();
-                       }
-                       
-                       string h_name;
-                       string[] h_aliases, h_addrlist;
-                       
-                       bool ret = GetHostByAddr_internal(address, out h_name,
-                                                         out h_aliases,
-                                                         out h_addrlist);
-                       if (ret == false) {
-                               throw new SocketException();
-                       }
-                       
-                       return(hostent_to_IPHostEntry(h_name, h_aliases,
-                                                     h_addrlist));
-               }
+                public static IPHostEntry GetHostByAddress(IPAddress address) {
+                        if (address == null)
+                                throw new ArgumentNullException();
+                        return GetHostByAddress(address.ToString());
+                }
+                
+                public static IPHostEntry GetHostByAddress(string address) {
+                        if (address == null) {
+                                throw new ArgumentNullException();
+                        }
+                        
+                        string h_name;
+                        string[] h_aliases, h_addrlist;
+                        
+                        bool ret = GetHostByAddr_internal(address, out h_name,
+                                                          out h_aliases,
+                                                          out h_addrlist);
+                        if (ret == false) {
+                                throw new SocketException();
+                        }
+                        
+                        return(hostent_to_IPHostEntry(h_name, h_aliases,
+                                                      h_addrlist));
+                }
 
-               public static IPHostEntry GetHostByName(string hostName) {
-                       if (hostName == null) {
-                               throw new ArgumentNullException();
-                       }
-                       
-                       string h_name;
-                       string[] h_aliases, h_addrlist;
-                       
-                       bool ret = GetHostByName_internal(hostName, out h_name,
-                                                         out h_aliases,
-                                                         out h_addrlist);
-                       if (ret == false) {
-                               throw new SocketException();
-                       }
+                public static IPHostEntry GetHostByName(string hostName) {
+                        if (hostName == null) {
+                                throw new ArgumentNullException();
+                        }
+                        
+                        string h_name;
+                        string[] h_aliases, h_addrlist;
+                        
+                        bool ret = GetHostByName_internal(hostName, out h_name,
+                                                          out h_aliases,
+                                                          out h_addrlist);
+                        if (ret == false) {
+                                throw new SocketException();
+                        }
 
-                       return(hostent_to_IPHostEntry(h_name, h_aliases,
-                                                     h_addrlist));
-               }
-               
-               /// <summary>
-               /// This method returns the host name associated with the local host.
-               /// </summary>
-               public static string GetHostName() {
-                       IPHostEntry h = GetHostByAddress("127.0.0.1");
-                       return h.HostName;
-               }
-               
-               /// <summary>
-               /// This method resovles a DNS-style host name or IP
-               /// address.
-               /// </summary>
-               /// <param name=hostName>
-               /// A string containing either a DNS-style host name (e.g.
-               /// www.go-mono.com) or IP address (e.g. 129.250.184.233).
-               /// </param>
-               public static IPHostEntry Resolve(string hostName) {
-                       if (hostName == null)
-                               throw new ArgumentNullException();
-                       try {
-                               return GetHostByAddress(hostName);
-                       } catch (SocketException) {
-                               return GetHostByName(hostName);
-                       }
-               }
-       }
+                        return(hostent_to_IPHostEntry(h_name, h_aliases,
+                                                      h_addrlist));
+                }
+                
+                /// <summary>
+                /// This method returns the host name associated with the local host.
+                /// </summary>
+                public static string GetHostName() {
+                        IPHostEntry h = GetHostByAddress("127.0.0.1");
+                        return h.HostName;
+                }
+                
+                /// <summary>
+                /// This method resovles a DNS-style host name or IP
+                /// address.
+                /// </summary>
+                /// <param name=hostName>
+                /// A string containing either a DNS-style host name (e.g.
+                /// www.go-mono.com) or IP address (e.g. 129.250.184.233).
+                /// </param>
+                public static IPHostEntry Resolve(string hostName) {
+                        if (hostName == null)
+                                throw new ArgumentNullException();
+                        try {
+                                return GetHostByAddress(hostName);
+                        } catch (SocketException) {
+                                return GetHostByName(hostName);
+                        }
+                }
+        }
 }
 
index 37987f370cf2e73e25f07f5a9ddb602194904383..532cd0fa2ed934a5b42a8e5594784c283354eccc 100644 (file)
@@ -6,10 +6,10 @@
 // 
 // This test assumes the following:
 // 1) The following Internet sites exist:
-//       www.go-mono.com with IP address 129.250.184.233
-//       info.diku.dk with IP address 130.225.96.4
+//        www.go-mono.com with IP address 129.250.184.233
+//        info.diku.dk with IP address 130.225.96.4
 // 2) The following DNS name does not exist:
-//       www.hopefullydoesnotexist.dk
+//        www.hopefullydoesnotexist.dk
 //
 
 using NUnit.Framework;
@@ -20,147 +20,140 @@ using System.Threading;
 using System.Collections;
 
 public class DnsTest: TestCase {
-       
-       private String site1Name = "www.go-mono.com",
-               site1Dot = "129.250.184.233",
-               site2Name = "info.diku.dk",
-               site2Dot = "130.225.96.4",
-               noneExistingSite = "www.hopefullydoesnotexist.dk";
-       private uint site1IP = 2180692201, site2IP = 2195808260; // Big-Endian
-       
-       public DnsTest(String name): base(name) {
-       }
+        
+        private String site1Name = "www.go-mono.com",
+                site1Dot = "129.250.184.233",
+                site2Name = "info.diku.dk",
+                site2Dot = "130.225.96.4",
+                noneExistingSite = "www.hopefullydoesnotexist.dk";
+        private uint site1IP = 2180692201, site2IP = 2195808260; // Big-Endian
+        
+        public DnsTest(String name): base(name) {
+        }
 
-       public static ITest Suite {
-               get { return new TestSuite(typeof(DnsTest)); }
-       }
-       
-       private void Callback1(IAsyncResult ar) { 
-               IPHostEntry h;
-               h = System.Net.Dns.EndGetHostByName(ar);
-               SubTestValidIPHostEntry(h);
-       }
+        public static ITest Suite {
+                get { return new TestSuite(typeof(DnsTest)); }
+        }
+        
+        private void Callback(IAsyncResult ar) { 
+                IPHostEntry h;
+                h = System.Net.Dns.EndGetHostByName(ar);
+                SubTestValidIPHostEntry(h);
+        }
 
-       public void TestAsynGetHostByName(){
-               IAsyncResult r;
-               r = System.Net.Dns.BeginGetHostByName(site1Name, new AsyncCallback(Callback1), null);
-       }
-       
-       private void Callback2(IAsyncResult ar) { 
-               IPHostEntry h;
-               h = System.Net.Dns.EndResolve(ar);
-               // TODO
-       }
-       
-       public void TestAsyncResolve() {
-/*             IAsyncResult r;
-               r = System.Net.Dns.BeginResolve(site1Name, new AsyncCallback(Callback2), null);
-*/             // TODO
-       }
-       
-       public void TestGetHostName() {
-               string hostName = System.Net.Dns.GetHostName();
-               Assert(hostName != null);
-       }
-       
-       private void SubTestGetHostByName(string siteName, string siteDot) {
-               IPHostEntry h = System.Net.Dns.GetHostByName(siteName);
-               SubTestValidIPHostEntry(h);
-               Assert(h.HostName.Equals(siteName));
-               Assert(h.AddressList[0].ToString() == siteDot);
-       }
-       
-       public void TestGetHostByName() {
-               SubTestGetHostByName(site1Name, site1Dot);
-               SubTestGetHostByName(site2Name, site2Dot);
-               try {
-                       System.Net.Dns.GetHostByName(noneExistingSite);
-                       Fail("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");
-               } catch (SocketException) {
-               } 
-               try {
-                       System.Net.Dns.GetHostByName(null);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               } 
-       }
-       
-       private void SubTestGetHostByAddressStringFormatException(string addr) {
-               try {
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise a FormatException");
-               } catch (FormatException) {
-               } 
-       }
-       
-       private void SubTestGetHostByAddressString(string addr) {
-               IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
-               SubTestValidIPHostEntry(h);
-       }
-       
-       public void TestGetHostByAddressString() {
-               try {
-                       String addr = null;
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               }
-               SubTestGetHostByAddressStringFormatException("123.255.23");
-               SubTestGetHostByAddressStringFormatException("123.256.34.10");
-               SubTestGetHostByAddressStringFormatException("not an IP address");
-               SubTestGetHostByAddressString(site1Dot);
-               SubTestGetHostByAddressString(site2Dot);
-       }
-       
-       private void SubTestGetHostByAddressIPAddress(IPAddress addr) {
-               IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
-               SubTestValidIPHostEntry(h);
-               Assert(h.AddressList[0].ToString() == addr.ToString());
-       }
-       
-       public void TestGetHostByAddressIPAddress() {
-               try {
-                       IPAddress addr = null;
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               }
-               SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site1IP)));
-               SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site2IP)));
-       }
-       
-       private void SubTestResolve(string addr) {
-               IPHostEntry h = System.Net.Dns.Resolve(addr);
-               SubTestValidIPHostEntry(h);
-       }
-       
-       public void TestResolve() {
-               SubTestResolve(site1Name);
-               SubTestResolve(site2Name);
-               SubTestResolve(site1Dot);
-               SubTestResolve(site2Dot);
-       }
-       
-       private void SubTestValidIPHostEntry(IPHostEntry h) {
-               Assert(h.HostName != null);
-               Assert(h.AddressList != null);
-               Assert(h.AddressList.Length > 0);
-       }
-       
-       private static void printIPHostEntry(IPHostEntry h)
-       {
-               Console.WriteLine("----------------------------------------------------");
-               Console.WriteLine("Host name:");
-               Console.WriteLine(h.HostName);
-               Console.WriteLine("IP addresses:");
-               IPAddress[] list = h.AddressList;
-               for(int i = 0; i < list.Length; ++i)
-                       Console.WriteLine(list[i]);
-               Console.WriteLine("Aliases:");
-               string[] aliases = h.Aliases;
-               for(int i = 0; i < aliases.Length; ++i)
-                       Console.WriteLine(aliases[i]);
-               Console.WriteLine("----------------------------------------------------");
-       }
+        public void TestAsyncGetHostByName(){
+                IAsyncResult r;
+                r = System.Net.Dns.BeginGetHostByName(site1Name, new AsyncCallback(Callback), null);
+        }
+        
+        public void TestAsyncResolve() {
+                IAsyncResult r;
+                r = System.Net.Dns.BeginResolve(site1Name, new AsyncCallback(Callback), null);
+        }
+        
+        public void TestGetHostName() {
+                string hostName = System.Net.Dns.GetHostName();
+                Assert(hostName != null);
+        }
+        
+        private void SubTestGetHostByName(string siteName, string siteDot) {
+                IPHostEntry h = System.Net.Dns.GetHostByName(siteName);
+                SubTestValidIPHostEntry(h);
+                Assert(h.HostName.Equals(siteName));
+                Assert(h.AddressList[0].ToString() == siteDot);
+        }
+        
+        public void TestGetHostByName() {
+                SubTestGetHostByName(site1Name, site1Dot);
+                SubTestGetHostByName(site2Name, site2Dot);
+                try {
+                        System.Net.Dns.GetHostByName(noneExistingSite);
+                        Fail("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");
+                } catch (SocketException) {
+                } 
+                try {
+                        System.Net.Dns.GetHostByName(null);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                } 
+        }
+        
+        private void SubTestGetHostByAddressStringFormatException(string addr) {
+                try {
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise a FormatException");
+                } catch (FormatException) {
+                } 
+        }
+        
+        private void SubTestGetHostByAddressString(string addr) {
+                IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
+                SubTestValidIPHostEntry(h);
+        }
+        
+        public void TestGetHostByAddressString() {
+                try {
+                        String addr = null;
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                SubTestGetHostByAddressStringFormatException("123.255.23");
+                SubTestGetHostByAddressStringFormatException("123.256.34.10");
+                SubTestGetHostByAddressStringFormatException("not an IP address");
+                SubTestGetHostByAddressString(site1Dot);
+                SubTestGetHostByAddressString(site2Dot);
+        }
+        
+        private void SubTestGetHostByAddressIPAddress(IPAddress addr) {
+                IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
+                SubTestValidIPHostEntry(h);
+                Assert(h.AddressList[0].ToString() == addr.ToString());
+        }
+        
+        public void TestGetHostByAddressIPAddress() {
+                try {
+                        IPAddress addr = null;
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site1IP)));
+                SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site2IP)));
+        }
+        
+        private void SubTestResolve(string addr) {
+                IPHostEntry h = System.Net.Dns.Resolve(addr);
+                SubTestValidIPHostEntry(h);
+        }
+        
+        public void TestResolve() {
+                SubTestResolve(site1Name);
+                SubTestResolve(site2Name);
+                SubTestResolve(site1Dot);
+                SubTestResolve(site2Dot);
+        }
+        
+        private void SubTestValidIPHostEntry(IPHostEntry h) {
+                Assert(h.HostName != null);
+                Assert(h.AddressList != null);
+                Assert(h.AddressList.Length > 0);
+        }
+        
+        private static void printIPHostEntry(IPHostEntry h)
+        {
+                Console.WriteLine("----------------------------------------------------");
+                Console.WriteLine("Host name:");
+                Console.WriteLine(h.HostName);
+                Console.WriteLine("IP addresses:");
+                IPAddress[] list = h.AddressList;
+                for(int i = 0; i < list.Length; ++i)
+                        Console.WriteLine(list[i]);
+                Console.WriteLine("Aliases:");
+                string[] aliases = h.Aliases;
+                for(int i = 0; i < aliases.Length; ++i)
+                        Console.WriteLine(aliases[i]);
+                Console.WriteLine("----------------------------------------------------");
+        }
 }
 
index 37987f370cf2e73e25f07f5a9ddb602194904383..532cd0fa2ed934a5b42a8e5594784c283354eccc 100644 (file)
@@ -6,10 +6,10 @@
 // 
 // This test assumes the following:
 // 1) The following Internet sites exist:
-//       www.go-mono.com with IP address 129.250.184.233
-//       info.diku.dk with IP address 130.225.96.4
+//        www.go-mono.com with IP address 129.250.184.233
+//        info.diku.dk with IP address 130.225.96.4
 // 2) The following DNS name does not exist:
-//       www.hopefullydoesnotexist.dk
+//        www.hopefullydoesnotexist.dk
 //
 
 using NUnit.Framework;
@@ -20,147 +20,140 @@ using System.Threading;
 using System.Collections;
 
 public class DnsTest: TestCase {
-       
-       private String site1Name = "www.go-mono.com",
-               site1Dot = "129.250.184.233",
-               site2Name = "info.diku.dk",
-               site2Dot = "130.225.96.4",
-               noneExistingSite = "www.hopefullydoesnotexist.dk";
-       private uint site1IP = 2180692201, site2IP = 2195808260; // Big-Endian
-       
-       public DnsTest(String name): base(name) {
-       }
+        
+        private String site1Name = "www.go-mono.com",
+                site1Dot = "129.250.184.233",
+                site2Name = "info.diku.dk",
+                site2Dot = "130.225.96.4",
+                noneExistingSite = "www.hopefullydoesnotexist.dk";
+        private uint site1IP = 2180692201, site2IP = 2195808260; // Big-Endian
+        
+        public DnsTest(String name): base(name) {
+        }
 
-       public static ITest Suite {
-               get { return new TestSuite(typeof(DnsTest)); }
-       }
-       
-       private void Callback1(IAsyncResult ar) { 
-               IPHostEntry h;
-               h = System.Net.Dns.EndGetHostByName(ar);
-               SubTestValidIPHostEntry(h);
-       }
+        public static ITest Suite {
+                get { return new TestSuite(typeof(DnsTest)); }
+        }
+        
+        private void Callback(IAsyncResult ar) { 
+                IPHostEntry h;
+                h = System.Net.Dns.EndGetHostByName(ar);
+                SubTestValidIPHostEntry(h);
+        }
 
-       public void TestAsynGetHostByName(){
-               IAsyncResult r;
-               r = System.Net.Dns.BeginGetHostByName(site1Name, new AsyncCallback(Callback1), null);
-       }
-       
-       private void Callback2(IAsyncResult ar) { 
-               IPHostEntry h;
-               h = System.Net.Dns.EndResolve(ar);
-               // TODO
-       }
-       
-       public void TestAsyncResolve() {
-/*             IAsyncResult r;
-               r = System.Net.Dns.BeginResolve(site1Name, new AsyncCallback(Callback2), null);
-*/             // TODO
-       }
-       
-       public void TestGetHostName() {
-               string hostName = System.Net.Dns.GetHostName();
-               Assert(hostName != null);
-       }
-       
-       private void SubTestGetHostByName(string siteName, string siteDot) {
-               IPHostEntry h = System.Net.Dns.GetHostByName(siteName);
-               SubTestValidIPHostEntry(h);
-               Assert(h.HostName.Equals(siteName));
-               Assert(h.AddressList[0].ToString() == siteDot);
-       }
-       
-       public void TestGetHostByName() {
-               SubTestGetHostByName(site1Name, site1Dot);
-               SubTestGetHostByName(site2Name, site2Dot);
-               try {
-                       System.Net.Dns.GetHostByName(noneExistingSite);
-                       Fail("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");
-               } catch (SocketException) {
-               } 
-               try {
-                       System.Net.Dns.GetHostByName(null);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               } 
-       }
-       
-       private void SubTestGetHostByAddressStringFormatException(string addr) {
-               try {
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise a FormatException");
-               } catch (FormatException) {
-               } 
-       }
-       
-       private void SubTestGetHostByAddressString(string addr) {
-               IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
-               SubTestValidIPHostEntry(h);
-       }
-       
-       public void TestGetHostByAddressString() {
-               try {
-                       String addr = null;
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               }
-               SubTestGetHostByAddressStringFormatException("123.255.23");
-               SubTestGetHostByAddressStringFormatException("123.256.34.10");
-               SubTestGetHostByAddressStringFormatException("not an IP address");
-               SubTestGetHostByAddressString(site1Dot);
-               SubTestGetHostByAddressString(site2Dot);
-       }
-       
-       private void SubTestGetHostByAddressIPAddress(IPAddress addr) {
-               IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
-               SubTestValidIPHostEntry(h);
-               Assert(h.AddressList[0].ToString() == addr.ToString());
-       }
-       
-       public void TestGetHostByAddressIPAddress() {
-               try {
-                       IPAddress addr = null;
-                       System.Net.Dns.GetHostByAddress(addr);
-                       Fail("Should raise an ArgumentNullException");
-               } catch (ArgumentNullException) {
-               }
-               SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site1IP)));
-               SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site2IP)));
-       }
-       
-       private void SubTestResolve(string addr) {
-               IPHostEntry h = System.Net.Dns.Resolve(addr);
-               SubTestValidIPHostEntry(h);
-       }
-       
-       public void TestResolve() {
-               SubTestResolve(site1Name);
-               SubTestResolve(site2Name);
-               SubTestResolve(site1Dot);
-               SubTestResolve(site2Dot);
-       }
-       
-       private void SubTestValidIPHostEntry(IPHostEntry h) {
-               Assert(h.HostName != null);
-               Assert(h.AddressList != null);
-               Assert(h.AddressList.Length > 0);
-       }
-       
-       private static void printIPHostEntry(IPHostEntry h)
-       {
-               Console.WriteLine("----------------------------------------------------");
-               Console.WriteLine("Host name:");
-               Console.WriteLine(h.HostName);
-               Console.WriteLine("IP addresses:");
-               IPAddress[] list = h.AddressList;
-               for(int i = 0; i < list.Length; ++i)
-                       Console.WriteLine(list[i]);
-               Console.WriteLine("Aliases:");
-               string[] aliases = h.Aliases;
-               for(int i = 0; i < aliases.Length; ++i)
-                       Console.WriteLine(aliases[i]);
-               Console.WriteLine("----------------------------------------------------");
-       }
+        public void TestAsyncGetHostByName(){
+                IAsyncResult r;
+                r = System.Net.Dns.BeginGetHostByName(site1Name, new AsyncCallback(Callback), null);
+        }
+        
+        public void TestAsyncResolve() {
+                IAsyncResult r;
+                r = System.Net.Dns.BeginResolve(site1Name, new AsyncCallback(Callback), null);
+        }
+        
+        public void TestGetHostName() {
+                string hostName = System.Net.Dns.GetHostName();
+                Assert(hostName != null);
+        }
+        
+        private void SubTestGetHostByName(string siteName, string siteDot) {
+                IPHostEntry h = System.Net.Dns.GetHostByName(siteName);
+                SubTestValidIPHostEntry(h);
+                Assert(h.HostName.Equals(siteName));
+                Assert(h.AddressList[0].ToString() == siteDot);
+        }
+        
+        public void TestGetHostByName() {
+                SubTestGetHostByName(site1Name, site1Dot);
+                SubTestGetHostByName(site2Name, site2Dot);
+                try {
+                        System.Net.Dns.GetHostByName(noneExistingSite);
+                        Fail("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");
+                } catch (SocketException) {
+                } 
+                try {
+                        System.Net.Dns.GetHostByName(null);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                } 
+        }
+        
+        private void SubTestGetHostByAddressStringFormatException(string addr) {
+                try {
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise a FormatException");
+                } catch (FormatException) {
+                } 
+        }
+        
+        private void SubTestGetHostByAddressString(string addr) {
+                IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
+                SubTestValidIPHostEntry(h);
+        }
+        
+        public void TestGetHostByAddressString() {
+                try {
+                        String addr = null;
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                SubTestGetHostByAddressStringFormatException("123.255.23");
+                SubTestGetHostByAddressStringFormatException("123.256.34.10");
+                SubTestGetHostByAddressStringFormatException("not an IP address");
+                SubTestGetHostByAddressString(site1Dot);
+                SubTestGetHostByAddressString(site2Dot);
+        }
+        
+        private void SubTestGetHostByAddressIPAddress(IPAddress addr) {
+                IPHostEntry h = System.Net.Dns.GetHostByAddress(addr);
+                SubTestValidIPHostEntry(h);
+                Assert(h.AddressList[0].ToString() == addr.ToString());
+        }
+        
+        public void TestGetHostByAddressIPAddress() {
+                try {
+                        IPAddress addr = null;
+                        System.Net.Dns.GetHostByAddress(addr);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site1IP)));
+                SubTestGetHostByAddressIPAddress(new IPAddress(IPAddress.NetworkToHostOrder((int)site2IP)));
+        }
+        
+        private void SubTestResolve(string addr) {
+                IPHostEntry h = System.Net.Dns.Resolve(addr);
+                SubTestValidIPHostEntry(h);
+        }
+        
+        public void TestResolve() {
+                SubTestResolve(site1Name);
+                SubTestResolve(site2Name);
+                SubTestResolve(site1Dot);
+                SubTestResolve(site2Dot);
+        }
+        
+        private void SubTestValidIPHostEntry(IPHostEntry h) {
+                Assert(h.HostName != null);
+                Assert(h.AddressList != null);
+                Assert(h.AddressList.Length > 0);
+        }
+        
+        private static void printIPHostEntry(IPHostEntry h)
+        {
+                Console.WriteLine("----------------------------------------------------");
+                Console.WriteLine("Host name:");
+                Console.WriteLine(h.HostName);
+                Console.WriteLine("IP addresses:");
+                IPAddress[] list = h.AddressList;
+                for(int i = 0; i < list.Length; ++i)
+                        Console.WriteLine(list[i]);
+                Console.WriteLine("Aliases:");
+                string[] aliases = h.Aliases;
+                for(int i = 0; i < aliases.Length; ++i)
+                        Console.WriteLine(aliases[i]);
+                Console.WriteLine("----------------------------------------------------");
+        }
 }