X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FTest%2FSystem.Net%2FDnsTest.cs;h=e06ca4bf5d6ae6e16ca43665f144953ba1d2b1c0;hb=c213a51b7055d2e43e963664fe00fe6621430732;hp=dcc82f61678777cc202e1b94417d4b7a82c0d114;hpb=8f7a1683c23d483b40aa965801f5a7998b9bfd3a;p=mono.git diff --git a/mcs/class/System/Test/System.Net/DnsTest.cs b/mcs/class/System/Test/System.Net/DnsTest.cs index dcc82f61678..e06ca4bf5d6 100644 --- a/mcs/class/System/Test/System.Net/DnsTest.cs +++ b/mcs/class/System/Test/System.Net/DnsTest.cs @@ -32,28 +32,37 @@ namespace MonoTests.System.Net [Test] public void AsyncGetHostByName () { - IAsyncResult r; - r = Dns.BeginGetHostByName (site1Name, new AsyncCallback (GetHostByNameCallback), null); - IAsyncResult async = Dns.BeginGetHostByName (site1Name, null, null); IPHostEntry entry = Dns.EndGetHostByName (async); SubTestValidIPHostEntry (entry); Assert.IsTrue (entry.HostName == "google-public-dns-a.google.com"); } - void GetHostByNameCallback (IAsyncResult ar) - { - IPHostEntry h; - h = Dns.EndGetHostByName (ar); - SubTestValidIPHostEntry (h); + [Test] + public void AsyncGetHostByNameCallback () + { + var evt = new ManualResetEvent (false); + Exception ex = null; + Dns.BeginGetHostByName (site1Name, new AsyncCallback ((IAsyncResult ar) => + { + try { + IPHostEntry h; + h = Dns.EndGetHostByName (ar); + SubTestValidIPHostEntry (h); + } catch (Exception e) { + ex = e; + } finally { + evt.Set (); + } + }), null); + + Assert.IsTrue (evt.WaitOne (TimeSpan.FromSeconds (60)), "Wait"); + Assert.IsNull (ex, "Exception"); } [Test] public void AsyncResolve () { - IAsyncResult r; - r = Dns.BeginResolve (site1Name, new AsyncCallback (ResolveCallback), null); - IAsyncResult async = Dns.BeginResolve (site1Dot, null, null); IPHostEntry entry = Dns.EndResolve (async); SubTestValidIPHostEntry (entry); @@ -61,10 +70,25 @@ namespace MonoTests.System.Net Assert.AreEqual (site1Dot, ip.ToString ()); } - void ResolveCallback (IAsyncResult ar) - { - IPHostEntry h = Dns.EndResolve (ar); - SubTestValidIPHostEntry (h); + [Test] + public void AsyncResolveCallback () + { + var evt = new ManualResetEvent (false); + Exception ex = null; + Dns.BeginResolve (site1Name, new AsyncCallback ((IAsyncResult ar) => + { + try { + IPHostEntry h = Dns.EndResolve (ar); + SubTestValidIPHostEntry (h); + } catch (Exception e) { + ex = e; + } finally { + evt.Set (); + } + }), null); + + Assert.IsTrue (evt.WaitOne (TimeSpan.FromSeconds (60)), "Wait"); + Assert.IsNull (ex, "Exception"); } [Test] @@ -73,7 +97,7 @@ namespace MonoTests.System.Net try { Dns.BeginGetHostAddresses ( (string) null, - new AsyncCallback (GetHostAddressesCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { @@ -91,7 +115,7 @@ namespace MonoTests.System.Net try { Dns.BeginGetHostAddresses ( "0.0.0.0", - new AsyncCallback (GetHostAddressesCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#A1"); } catch (ArgumentException ex) { @@ -108,7 +132,7 @@ namespace MonoTests.System.Net try { Dns.BeginGetHostAddresses ( "::0", - new AsyncCallback (GetHostAddressesCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#B1"); } catch (ArgumentException ex) { @@ -122,10 +146,9 @@ namespace MonoTests.System.Net } } - void GetHostAddressesCallback (IAsyncResult ar) + void ShouldntBeCalled (IAsyncResult ar) { - IPAddress [] addresses = Dns.EndGetHostAddresses (ar); - Assert.IsNotNull (addresses); + Assert.Fail ("Should not be called"); } [Test] @@ -317,7 +340,7 @@ namespace MonoTests.System.Net { try { Dns.BeginResolve ((string) null, - new AsyncCallback (ResolveCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { @@ -363,7 +386,7 @@ namespace MonoTests.System.Net try { Dns.BeginGetHostEntry ( (IPAddress) null, - new AsyncCallback (GetHostAddressesCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { @@ -380,7 +403,7 @@ namespace MonoTests.System.Net try { Dns.BeginGetHostEntry ( (string) null, - new AsyncCallback (GetHostAddressesCallback), + new AsyncCallback (ShouldntBeCalled), null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) {