Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,237 @@
2009-09-26 Sebastien Pouliot <sebastien@ximian.com>
* SocketAsyncEventArgsTest.cs: New. Unit tests
2009-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* SocketTest.cs: Added tests for argument checks, and improved tests
for disposed socket.
2009-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* IPv6MulticastOptionTest.cs: Added .ctor and property tests.
* MulticastOptionTest.cs: Added .ctor and property tests.
* SocketTest.cs: Fixed compiler warnings. Improved tests for
closed socket. Added tests fr GetSocketOption, and SetSocketOption
overloads (for Linger, DontLinger, AddMembership and DropMembership).
* UdpClientTest.cs: Added .ctor and JoinMulticastGroup tests.
2009-06-26 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SocketTest.cs: tests for DontLinger.
2009-06-26 Robert Jordan <robertj@gmx.net>
* *.cs: Upgrade to new NUnit style.
2009-01-26 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SocketTest.cs:
(TestSelect1) avoid RST by reading the bytes from the client.
2009-01-07 Geoff Norton <gnorton@novell.com>
* SocketTest.cs: Disable some tests on the Mac that rely on socket
options that are unavailable.
2008-12-03 Gonzalo Paniagua Javier <gonzalo@novell.com>
* UdpClientTest.cs: test closing a UDP socket while receiving.
2008-11-12 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SocketTest.cs: added test case based on the one in bug
#443346.
2008-06-19 Dick Porter <dick@ximian.com>
* SocketTest.cs: Tests for generic Send() and Receive() methods.
2007-11-22 Gert Driesen <drieseng@users.sourceforge.net>
* UdpClientTest.cs: Fixed line endings.
2007-11-02 Zoltan Varga <vargaz@gmail.com>
* SocketTest.cs: Disable the send/receive buffer size tests.
2007-10-30 Dick Porter <dick@ximian.com>
* UdpClientTest.cs: Test for 324033.
2007-10-21 Robert Jordan <robertj@gmx.net>
* SocketTest.cs: Enable GetHashCodeTest.
2007-08-15 Gert Driesen <drieseng@users.sourceforge.net>
* SocketTest.cs: Improved EndConnect test. Added test for bug #82446,
and marked it NotWorking for 2.0 profile.
2007-05-14 Dick Porter <dick@ximian.com>
* SocketTest.cs: Tests for bug 75705
2007-04-21 Gert Driesen <drieseng@users.sourceforge.net>
* TcpClientTest.cs: Enabled test for bug #81105.
2007-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* TcpClientTest.cs: ... and disable it again, since it fails buildbot
sles-9 x86-64.
2007-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* TcpClientTest.cs: Re-enabled test for bug #81105 since it passes
on both linux and windows. I'll monitor the build bots to spot if it
breaks the tests.
2007-03-11 Gert Driesen <drieseng@users.sourceforge.net>
* TcpClientTest.cs: Added test for bug #81105.
2007-03-07 Vladimir Krasnov <vladimirk@mainsoft.com>
* SocketTest.jvm.cs: removed not supported calls for TARGET_JVM because
of validation failures
2007-02-08 Ilya Kharmatsky <ilyak -at- mainsoft.com>
* SocketTest.jvm.cs: added 'Ignore' attributes for non working tests.
2007-01-30 Ilya Kharmatsky <ilyak -at- mainsoft.com>
* SocketTest.jvm.cs: added - forked out from SocketTest.cs due to
a lot 'TARGET_JVM' specific changes.
2007-01-26 Dick Porter <dick@ximian.com>
* SocketTest.cs: New test for SO_ERROR reading, returning the same
value over and over.
2007-01-25 Ilya Kharmatsky <ilyak -at- mainsoft.com>
* UdbClientTest.cs: Added Ignore attribute for entire test fixture
under TARGET_JVM directive.
2007-01-24 Dick Porter <dick@ximian.com>
* NetworkStreamTest.cs: Test 2.0 ReadTimeout property
2007-01-23 Dick Porter <dick@ximian.com>
* TcpListenerTest.cs: Test 2.0 Start(int) overload
* TcpClientTest.cs: Test 2.0 Connect(IPAddress[], port) overload
2007-01-11 Dick Porter <dick@ximian.com>
* SocketTest.cs:
* UdpClientTest.cs: Test 2.0 additions
2006-11-24 Dick Porter <dick@ximian.com>
* SocketTest.cs: Add a test for async non blocking connects that
should fail, leaving Socket.Connected == false. Based on test
case in bug 79878.
2005-09-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SocketTest.cs: added a bunch of tests expecting
ObjectDisposedException to be thrown.
2005-06-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SocketTest.cs: added new test for Select.
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* SocketTest.cs: added test for bug #75158 (incompatible address).
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* SocketTest.cs: use IPAddress.Loopback in IPEndPoint to allow
AcceptBlockingStatus test to pass on both Mono and MS.NET.
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* SocketTest.cs: added test for bug #75154.
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* TcpListenerTest.cs: remove NotDotNet category from TcpListener
test as its working just fine on both MS.NET 1.x and 2.0.
2005-06-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* TcpListenerTest.cs: actually connect the socket to the listener. Fixes
the test.
2005-05-20 Sebastien Pouliot <sebastien@ximian.com>
* NetworkStreamCas.cs: New. CAS unit tests for NetworkStream.
* SocketCas.cs: New. CAS unit tests for Socket.
* SocketTest.cs: Make some fields public so they can be reused.
* TcpClientCas.cs: New. CAS unit tests for TcpClient (currently
commented as the Begin* methods aren't yet implemented).
2005-05-06 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SocketTest.cs: added test for setting a boolean socket option.
2005-03-06 Nick Drochak <ndrochak@ieee.org>
* TcpClientTest.cs: Choose a different port so test will pass on MS.NET
* TcpListenerTest.cs: Ignore test that doesn't play well on MS.NET
2005-02-23 Dick Porter <dick@ximian.com>
* UdpClientTest.cs: Added, with UdpClientBroadcastTest from Chris
Bacon <chris.bacon@docobo.co.uk>
2005-02-01 Zoltan Varga <vargaz@freemail.hu>
* SocketTest.cs: Mark some tests with [Category ("InetAccess")].
2005-01-08 Nick Drochak <ndrochak@ieee.org>
* SocketTest.cs: Ignore test on MS.NET
2004-10-14 Dick Porter <dick@ximian.com>
* SocketTest.cs: Test the blocking status of accepted sockets
2004-06-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SocketTest.cs: added test for Select with empty lists. Changed the
'bogus' address of EndConnect test.
2003-12-30 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SocketTest.cs: new test for asynchronous connection failure.
Test by Brad FitzpatrickBrad Fitzpatrick <brad@danga.com>.
2003-08-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* TcpListenerTest.cs: added more tests.
2003-07-16 Peter Williams <peter@newton.cx>
* TcpListenerTest.cs: Initialize outSock to null to
prevent an mcs compile error.
2003-07-14 Jerome Laban <jlaban@wanadoo.fr>
* TcpListenerTest.cs: Forced IPv4 listener test.
2002-11-03 Phillip Pearson <pp@myelin.co.nz>
* AllTests.cs: Fixed Lawrence's e-mail address.
2002-05-17 Lawrence Pit <loz@cable.a2000.nl>
* AllTests.cs: added

View File

@@ -0,0 +1,229 @@
// System.Net.Sockets.IPv6MulticastOptionTest.cs
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (c) 2009 Gert Driesen
//
using System;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class IPv6MulticastOptionTest
{
[Test] // .ctor (IPAddress)
public void Constructor1 ()
{
IPv6MulticastOption option;
IPAddress group;
group = IPAddress.Parse ("ff02::1");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("224.0.0.23");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
}
[Test] // .ctor (IPAddress)
public void Constructor1_Group_Null ()
{
try {
new IPv6MulticastOption ((IPAddress) null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, Int64)
public void Constructor2 ()
{
IPv6MulticastOption option;
IPAddress group;
long interfaceIndex;
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#B:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#C:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#C:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#D:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#D:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#E:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#E:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#F:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#F:InterfaceIndex");
}
[Test] // .ctor (IPAddress, Int64)
public void Constructor2_Group_Null ()
{
IPAddress group = null;
try {
new IPv6MulticastOption (group, 0);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, Int64)
public void Constructor2_Ifindex_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("ff02::1");
try {
new IPv6MulticastOption (group, -1);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("ifindex", ex.ParamName, "#A5");
}
try {
new IPv6MulticastOption (group, 0x100000000);
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("ifindex", ex.ParamName, "#B5");
}
}
[Test]
public void Group ()
{
IPAddress group;
IPv6MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new IPv6MulticastOption (group, 5L);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (5L, option.InterfaceIndex, "#A2");
group = IPAddress.Parse ("239.255.255.250");
option.Group = group;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (5L, option.InterfaceIndex, "#B2");
group = IPAddress.Parse ("ff02::1");
option.Group = group;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (5L, option.InterfaceIndex, "#C2");
}
[Test]
public void Group_Value_Null ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPv6MulticastOption option = new IPv6MulticastOption (group, 10);
try {
option.Group = null;
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("value", ex.ParamName, "#5");
}
}
[Test]
public void InterfaceIndex ()
{
IPAddress group;
IPv6MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new IPv6MulticastOption (group, 10);
option.InterfaceIndex = 0;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
option.InterfaceIndex = 124;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (124, option.InterfaceIndex, "#B2");
option.InterfaceIndex = 0xFFFFFFFF;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (0xFFFFFFFF, option.InterfaceIndex, "#C3");
}
[Test]
public void InterfaceIndex_Value_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPv6MulticastOption option = new IPv6MulticastOption (group, 10);
try {
option.InterfaceIndex = -1;
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
try {
option.InterfaceIndex = 0x100000000;
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("value", ex.ParamName, "#B5");
}
// ensure original value was retained
Assert.AreEqual (10, option.InterfaceIndex, "#C");
}
}
}

View File

@@ -0,0 +1,364 @@
// System.Net.Sockets.MulticastOptionTest.cs
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (c) 2009 Gert Driesen
//
using System;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class MulticastOptionTest
{
[Test] // .ctor (IPAddress)
public void Constructor1 ()
{
MulticastOption option;
IPAddress group;
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group);
Assert.AreSame (group, option.Group, "#A:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
#endif
Assert.AreEqual (IPAddress.Any, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
option = new MulticastOption (group);
Assert.AreSame (group, option.Group, "#B:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
#endif
Assert.AreEqual (IPAddress.Any, option.LocalAddress, "#B:LocalAddress");
}
[Test] // .ctor (IPAddress)
public void Constructor1_Group_Null ()
{
try {
new MulticastOption ((IPAddress) null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2 ()
{
MulticastOption option;
IPAddress group;
IPAddress mcint;
group = IPAddress.Parse ("239.255.255.250");
mcint = IPAddress.Any;
option = new MulticastOption (group, mcint);
Assert.AreSame (group, option.Group, "#A:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
#endif
Assert.AreEqual (mcint, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
mcint = IPAddress.IPv6Any;
option = new MulticastOption (group, mcint);
Assert.AreSame (group, option.Group, "#B:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
#endif
Assert.AreEqual (mcint, option.LocalAddress, "#B:LocalAddress");
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2_Group_Null ()
{
IPAddress group = null;
IPAddress mcint = IPAddress.Any;
try {
new MulticastOption (group, mcint);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2_Mcint_Null ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPAddress mcint = null;
try {
new MulticastOption (group, mcint);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("mcint", ex.ParamName, "#5");
}
}
#if NET_2_0
[Test] // .ctor (IPAddress, Int32)
public void Constructor3 ()
{
MulticastOption option;
IPAddress group;
int interfaceIndex;
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#A:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#B:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#B:LocalAddress");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 124;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#C:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#C:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#C:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 124;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#D:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#D:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#D:LocalAddress");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0xFFFFFF;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#E:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#E:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#E:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0xFFFFFF;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#F:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#F:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#F:LocalAddress");
}
[Test] // .ctor (IPAddress, Int32)
public void Constructor3_Group_Null ()
{
IPAddress group = null;
try {
new MulticastOption (group, int.MaxValue);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, Int32)
public void Constructor3_InterfaceIndex_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
try {
new MulticastOption (group, -1);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("interfaceIndex", ex.ParamName, "#A5");
}
try {
new MulticastOption (group, 0x1000000);
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("interfaceIndex", ex.ParamName, "#B5");
}
}
#endif
[Test]
public void Group ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, local);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreSame (local, option.LocalAddress, "#A2");
group = IPAddress.Parse ("239.255.255.250");
option.Group = group;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreSame (local, option.LocalAddress, "#B2");
group = IPAddress.Parse ("ff02::1");
option.Group = group;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreSame (local, option.LocalAddress, "#C2");
option.Group = null;
Assert.IsNull (option.Group, "#D1");
Assert.AreSame (local, option.LocalAddress, "#D2");
#if NET_2_0
option = new MulticastOption (group, 5);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#E1");
Assert.AreEqual (5, option.InterfaceIndex, "#E2");
Assert.IsNull (option.LocalAddress, "#E3");
#endif
}
#if NET_2_0
[Test]
public void InterfaceIndex ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, 10);
option.InterfaceIndex = 0;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
Assert.IsNull (option.LocalAddress, "#A3");
option.InterfaceIndex = 124;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (124, option.InterfaceIndex, "#B2");
Assert.IsNull (option.LocalAddress, "#B3");
option.InterfaceIndex = 0xFFFFFF;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (0xFFFFFF, option.InterfaceIndex, "#C2");
Assert.IsNull (option.LocalAddress, "#C3");
local = Dns.GetHostEntry (string.Empty).AddressList [0];
option = new MulticastOption (group, local);
option.InterfaceIndex = 10;
Assert.AreSame (group, option.Group, "#D1");
Assert.AreEqual (10, option.InterfaceIndex, "#D2");
Assert.IsNull (option.LocalAddress, "#D3");
}
[Test]
public void InterfaceIndex_Value_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
MulticastOption option = new MulticastOption (group, 10);
try {
option.InterfaceIndex = -1;
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
try {
option.InterfaceIndex = 0x1000000;
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("value", ex.ParamName, "#B5");
}
// ensure original value was retained
Assert.AreEqual (10, option.InterfaceIndex, "#C");
}
#endif
[Test]
public void LocalAddress ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, local);
local = IPAddress.Loopback;
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#A1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
#endif
Assert.AreSame (local, option.LocalAddress, "#A3");
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#B1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B2");
#endif
Assert.AreSame (local, option.LocalAddress, "#B3");
option.LocalAddress = null;
Assert.AreSame (group, option.Group, "#C1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#C2");
#endif
Assert.IsNull (option.LocalAddress, "#C3");
#if NET_2_0
option = new MulticastOption (group, 5);
local = IPAddress.Loopback;
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#D1");
Assert.AreEqual (0, option.InterfaceIndex, "#D2");
Assert.AreSame (local, option.LocalAddress, "#D3");
#endif
}
}
}

View File

@@ -0,0 +1,155 @@
//
// NetworkStreamCas.cs -CAS unit tests for System.Net.Sockets.NetworkStream
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Text;
namespace MonoCasTests.System.Net.Sockets {
[TestFixture]
[Category ("CAS")]
public class NetworkStreamCas {
private const int timeout = 30000;
private string message;
static ManualResetEvent reset;
static Socket socket;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
reset = new ManualResetEvent (false);
IPHostEntry host = Dns.Resolve ("www.google.com");
IPAddress ip = host.AddressList[0];
socket = new Socket (ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect (new IPEndPoint (ip, 80));
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
reset.Close ();
socket.Close ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// async tests (for stack propagation)
private void ReadCallback (IAsyncResult ar)
{
NetworkStream s = (NetworkStream)ar.AsyncState;
s.EndRead (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncRead ()
{
message = "AsyncRead";
reset.Reset ();
NetworkStream ns = new NetworkStream (socket, false);
StreamWriter sw = new StreamWriter (ns);
sw.Write ("GET / HTTP/1.0\n\n");
sw.Flush ();
IAsyncResult r = ns.BeginRead (new byte [1024], 0, 1024, new AsyncCallback (ReadCallback), ns);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
ns.Close ();
}
private void WriteCallback (IAsyncResult ar)
{
NetworkStream s = (NetworkStream)ar.AsyncState;
s.EndWrite (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncWrite ()
{
message = "AsyncWrite";
reset.Reset ();
NetworkStream ns = new NetworkStream (socket, false);
byte[] get = Encoding.ASCII.GetBytes ("GET / HTTP/1.0\n\n");
IAsyncResult r = ns.BeginWrite (get, 0, get.Length, new AsyncCallback (WriteCallback), ns);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
ns.Close ();
}
}
}

View File

@@ -0,0 +1,76 @@
// System.Net.Sockets.NetworkStreamTest.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
using System.Net.Sockets;
using System.Net;
using System;
using System.IO;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class NetworkStreamTest
{
#if NET_2_0
[Test]
// See bug #371923
[ExpectedException(typeof(IOException))]
public void NetworkStreamConnection ()
{
IPEndPoint ipe = new IPEndPoint(Dns.GetHostEntry ("www.google.com").AddressList [0], 80);
Socket s = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
s.Close ();
NetworkStream ns = new NetworkStream (s);
}
[Test]
public void ReadTimeout ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
Socket listen = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
listen.Bind (ep);
listen.Listen (1);
sock.Connect (listen.LocalEndPoint);
NetworkStream stream = new NetworkStream (sock);
stream.ReadTimeout = 1000;
byte[] buf = new byte[1024];
try {
stream.Read (buf, 0, buf.Length);
Assert.Fail ("ReadTimeout #1");
} catch (IOException ex) {
Exception inner = ex.InnerException;
SocketException sockex = inner as SocketException;
Assert.IsNotNull (sockex, "ReadTimeout #2");
/* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
Assert.AreEqual (10060, sockex.ErrorCode, "ReadTimeout #3");
*/
} catch {
Assert.Fail ("ReadTimeout #4");
} finally {
stream.Close ();
sock.Close ();
listen.Close ();
}
}
#endif
}
}

View File

@@ -0,0 +1,255 @@
//
// SocketAsyncEventArgsTest.cs - NUnit Test Cases for SocketAsyncEventArgs
//
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets {
[TestFixture]
public class SocketAsyncEventArgsTest {
[Test]
public void Defaults ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
Assert.IsNull (saea.AcceptSocket, "AcceptSocket");
Assert.IsNull (saea.Buffer, "Buffer");
Assert.IsNull (saea.BufferList, "BufferList");
Assert.AreEqual (0, saea.BytesTransferred, "BytesTransferred");
Assert.AreEqual (0, saea.Count, "Count");
Assert.IsFalse (saea.DisconnectReuseSocket, "DisconnectReuseSocket");
Assert.AreEqual (SocketAsyncOperation.None, saea.LastOperation, "LastOperation");
Assert.AreEqual (0, saea.Offset, "Offset");
Assert.IsNull (saea.RemoteEndPoint, "RemoteEndPoint");
#if !MOBILE
Assert.IsNotNull (saea.ReceiveMessageFromPacketInfo, "ReceiveMessageFromPacketInfo");
Assert.IsNull (saea.SendPacketsElements, "SendPacketsElements");
Assert.AreEqual (TransmitFileOptions.UseDefaultWorkerThread, saea.SendPacketsFlags, "SendPacketsFlags");
#endif
Assert.AreEqual (-1, saea.SendPacketsSendSize, "SendPacketsSendSize");
Assert.AreEqual (SocketError.Success, saea.SocketError, "SocketError");
Assert.AreEqual (SocketFlags.None, saea.SocketFlags, "SocketFlags");
Assert.IsNull (saea.UserToken, "UserToken");
saea.Dispose ();
saea.Dispose (); // twice
}
[Test]
public void SetBuffer_ByteArray ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
byte [] buffer = new byte [0];
saea.SetBuffer (buffer, 0, 0);
Assert.AreEqual (0, saea.Buffer.Length, "0");
Assert.AreSame (saea.Buffer, buffer, "same");
saea.SetBuffer (null, 0, 0);
Assert.IsNull (saea.Buffer, "null");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void SetBuffer_BufferList_ByteArray ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.BufferList = new List<ArraySegment<byte>> ();
saea.SetBuffer (new byte [0], 0, 0);
}
[Test]
public void SetBuffer_BufferList_NullByteArray ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.BufferList = new List<ArraySegment<byte>> ();
saea.SetBuffer (null, 0, 0);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void SetBuffer_ByteArray_BufferList ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [0], 0, 0);
saea.BufferList = new List<ArraySegment<byte>> ();
}
[Test]
public void SetBuffer_NullByteArray_BufferList ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (null, 0, 0);
saea.BufferList = new List<ArraySegment<byte>> ();
Assert.IsNull (saea.Buffer, "Buffer");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_ByteArray_StartNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], -1, 0);
}
[Test]
public void SetBuffer_Null_StartNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (null, -1, 0);
Assert.IsNull (saea.Buffer, "Buffer");
Assert.IsNull (saea.BufferList, "BufferList");
Assert.AreEqual (0, saea.Count, "Count");
Assert.AreEqual (0, saea.Offset, "Offset");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_ByteArray_CountNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], 1, -1);
}
[Test]
public void SetBuffer_BufferList ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.BufferList = new List<ArraySegment<byte>> ();
saea.SetBuffer (1, -1);
saea.SetBuffer (-1, 0);
}
[Test]
public void SetBuffer_Null_CountNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (null, 1, -1);
Assert.IsNull (saea.Buffer, "Buffer");
Assert.IsNull (saea.BufferList, "BufferList");
Assert.AreEqual (0, saea.Count, "Count");
Assert.AreEqual (0, saea.Offset, "Offset");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_ByteArray_StartOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], Int32.MaxValue, 1);
}
[Test]
public void SetBuffer_Null_StartOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (null, Int32.MaxValue, 1);
Assert.IsNull (saea.Buffer, "Buffer");
Assert.IsNull (saea.BufferList, "BufferList");
Assert.AreEqual (0, saea.Count, "Count");
Assert.AreEqual (0, saea.Offset, "Offset");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_ByteArray_CountOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], 1, Int32.MaxValue);
}
[Test]
public void SetBuffer_Null_CountOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (null, 1, Int32.MaxValue);
Assert.IsNull (saea.Buffer, "Buffer");
Assert.IsNull (saea.BufferList, "BufferList");
Assert.AreEqual (0, saea.Count, "Count");
Assert.AreEqual (0, saea.Offset, "Offset");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_StartNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [0], 0, 0);
saea.SetBuffer (-1, 0);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_CountNegative ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], 1, -1);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_StartOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], Int32.MaxValue, 1);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetBuffer_CountOverflow ()
{
SocketAsyncEventArgs saea = new SocketAsyncEventArgs ();
saea.SetBuffer (new byte [10], 1, Int32.MaxValue);
}
class SocketAsyncEventArgsPoker : SocketAsyncEventArgs {
public void OnCompleted_ (SocketAsyncEventArgs e)
{
base.OnCompleted (e);
}
}
[Test]
public void OnCompleted_Null ()
{
SocketAsyncEventArgsPoker saea = new SocketAsyncEventArgsPoker ();
saea.OnCompleted_ (null);
}
}
}
#endif

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class SocketAsyncTest
{
Socket serverSocket;
Socket clientSocket;
ManualResetEvent readyEvent;
ManualResetEvent mainEvent;
Exception error;
[TestFixtureSetUp]
public void SetUp ()
{
readyEvent = new ManualResetEvent (false);
mainEvent = new ManualResetEvent (false);
ThreadPool.QueueUserWorkItem (_ => DoWork ());
readyEvent.WaitOne ();
clientSocket = new Socket (
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect (serverSocket.LocalEndPoint);
clientSocket.NoDelay = true;
}
[TestFixtureTearDown]
public void TearDown ()
{
if (serverSocket != null)
serverSocket.Close ();
readyEvent.Close ();
mainEvent.Close ();
}
void DoWork ()
{
serverSocket = new Socket (
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
serverSocket.Bind (new IPEndPoint (IPAddress.Loopback, 0));
serverSocket.Listen (1);
var async = new SocketAsyncEventArgs ();
async.Completed += (s,e) => OnAccepted (e);
readyEvent.Set ();
if (!serverSocket.AcceptAsync (async))
OnAccepted (async);
}
void OnAccepted (SocketAsyncEventArgs e)
{
var acceptSocket = e.AcceptSocket;
try {
var header = new byte [4];
acceptSocket.Receive (header);
if ((header [0] != 0x12) || (header [1] != 0x34) ||
(header [2] != 0x56) || (header [3] != 0x78))
throw new InvalidOperationException ();
} catch (Exception ex) {
error = ex;
return;
}
var recvAsync = new SocketAsyncEventArgs ();
recvAsync.Completed += (sender, args) => OnReceived (args);
recvAsync.SetBuffer (new byte [4], 0, 4);
if (!acceptSocket.ReceiveAsync (recvAsync))
OnReceived (recvAsync);
mainEvent.Set ();
}
void OnReceived (SocketAsyncEventArgs e)
{
if (e.SocketError != SocketError.Success)
error = new SocketException ((int) e.SocketError);
else if (e.Buffer [0] != 0x9a)
error = new InvalidOperationException ();
mainEvent.Set ();
}
[Test]
[Category("Test")]
public void SendAsync ()
{
var buffer = new byte [] { 0x12, 0x34, 0x56, 0x78 };
var m = new ManualResetEvent (false);
var e = new SocketAsyncEventArgs ();
e.SetBuffer (buffer, 0, buffer.Length);
e.Completed += (s,o) => {
if (o.SocketError != SocketError.Success)
error = new SocketException ((int)o.SocketError);
m.Set ();
};
bool res = clientSocket.SendAsync (e);
if (res) {
if (!m.WaitOne (1500))
throw new TimeoutException ();
}
if (!mainEvent.WaitOne (1500))
throw new TimeoutException ();
if (error != null)
throw error;
m.Reset ();
mainEvent.Reset ();
buffer [0] = 0x9a;
buffer [1] = 0xbc;
buffer [2] = 0xde;
buffer [3] = 0xff;
res = clientSocket.SendAsync (e);
if (res) {
if (!m.WaitOne (1500))
throw new TimeoutException ();
}
if (!mainEvent.WaitOne (1500))
throw new TimeoutException ();
if (error != null)
throw error;
}
}
}

View File

@@ -0,0 +1,283 @@
//
// SocketCas.cs - CAS unit tests for System.Net.WebRequest class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using MonoTests.System.Net.Sockets;
namespace MonoCasTests.System.Net.Sockets {
[TestFixture]
[Category ("CAS")]
public class SocketCas {
private const int timeout = 30000;
static ManualResetEvent reset;
private string message;
static Socket socket;
static EndPoint ep;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
reset = new ManualResetEvent (false);
IPHostEntry host = Dns.Resolve ("www.google.com");
IPAddress ip = host.AddressList[0];
ep = new IPEndPoint (ip, 80);
socket = new Socket (ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect (ep);
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
reset.Close ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// async tests (for stack propagation)
private void AcceptCallback (IAsyncResult ar)
{
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncAccept ()
{
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 16279);
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Bind (ep);
s.Listen (0);
message = "AsyncAccept";
reset.Reset ();
IAsyncResult r = s.BeginAccept (new AsyncCallback (AcceptCallback), s);
Assert.IsNotNull (r, "IAsyncResult");
Socket c = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
c.Connect (ep);
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
private void ConnectCallback (IAsyncResult ar)
{
Socket s = (Socket)ar.AsyncState;
s.EndConnect (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncConnect ()
{
message = "AsyncConnect";
reset.Reset ();
Socket s = new Socket (ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult r = s.BeginConnect (ep, new AsyncCallback (ConnectCallback), s);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
private void ReceiveCallback (IAsyncResult ar)
{
Socket s = (Socket)ar.AsyncState;
s.EndReceive (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncReceive ()
{
message = "AsyncReceive";
reset.Reset ();
NetworkStream ns = new NetworkStream (socket, false);
StreamWriter sw = new StreamWriter (ns);
sw.Write ("GET / HTTP/1.0\n\n");
sw.Flush ();
IAsyncResult r = socket.BeginReceive (new byte[1024], 0, 1024,
SocketFlags.None, new AsyncCallback (ReceiveCallback), socket);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
private void ReceiveFromCallback (IAsyncResult ar)
{
Socket s = (Socket)ar.AsyncState;
s.EndReceiveFrom (ar, ref ep);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncReceiveFrom ()
{
message = "AsyncReceiveFrom";
reset.Reset ();
NetworkStream ns = new NetworkStream (socket, false);
StreamWriter sw = new StreamWriter (ns);
sw.Write ("GET / HTTP/1.0\n\n");
sw.Flush ();
IAsyncResult r = socket.BeginReceiveFrom (new byte[1024], 0, 1024,
SocketFlags.None, ref ep, new AsyncCallback (ReceiveFromCallback), socket);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
private void SendCallback (IAsyncResult ar)
{
Socket s = (Socket)ar.AsyncState;
s.EndSend (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncSend ()
{
message = "AsyncSend";
reset.Reset ();
byte[] get = Encoding.ASCII.GetBytes ("GET / HTTP/1.0\n\n");
IAsyncResult r = socket.BeginSend (get, 0, get.Length, SocketFlags.None,
new AsyncCallback (SendCallback), socket);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
private void SendToCallback (IAsyncResult ar)
{
Socket s = (Socket)ar.AsyncState;
s.EndSendTo (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncSendTo ()
{
message = "AsyncSendTo";
reset.Reset ();
byte[] get = Encoding.ASCII.GetBytes ("GET / HTTP/1.0\n\n");
IAsyncResult r = socket.BeginSendTo (get, 0, get.Length, SocketFlags.None,
ep, new AsyncCallback (SendToCallback), socket);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
}
}

View File

@@ -0,0 +1 @@
0ae72b4c29ac57ce57fafde17a909f16b88df913

View File

@@ -0,0 +1,123 @@
//
// TcpClientCas.cs - CAS unit tests for System.Net.Sockets.TcpClient class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using MonoTests.System.Net.Sockets;
namespace MonoCasTests.System.Net.Sockets {
[TestFixture]
[Category ("CAS")]
public class TcpClientCas {
private const int timeout = 30000;
static ManualResetEvent reset;
private string message;
private string uri = "http://www.google.com";
[TestFixtureSetUp]
public void FixtureSetUp ()
{
reset = new ManualResetEvent (false);
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
reset.Close ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// async tests (for stack propagation)
#if NET_2_0
/* Oops - not yet implemented in Mono
private void ConnectCallback (IAsyncResult ar)
{
TcpClient c = (TcpClient)ar.AsyncState;
c.EndConnect (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncConnect_StringIntAsyncCallbackObject ()
{
TcpClient s = new TcpClient ();
message = "AsyncConnect";
reset.Reset ();
IAsyncResult r = s.BeginConnect ("www.google.com", 80, new AsyncCallback (ConnectCallback), s);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncConnect_IPAddressIntAsyncCallbackObject ()
{
IPHostEntry host = Dns.Resolve ("www.google.com");
TcpClient s = new TcpClient ();
message = "AsyncConnect";
reset.Reset ();
IAsyncResult r = s.BeginConnect (host.AddressList[0], 80, new AsyncCallback (ConnectCallback), s);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
[Category ("InetAccess")]
public void AsyncConnect_IPAddressArrayIntAsyncCallbackObject ()
{
IPHostEntry host = Dns.Resolve ("www.google.com");
TcpClient s = new TcpClient ();
message = "AsyncConnect";
reset.Reset ();
IAsyncResult r = s.BeginConnect (host.AddressList, 80, new AsyncCallback (ConnectCallback), s);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
}
*/
#endif
}
}

View File

@@ -0,0 +1,197 @@
// System.Net.Sockets.TcpClientTest.cs
//
// Authors:
// Phillip Pearson (pp@myelin.co.nz)
// Martin Willemoes Hansen (mwh@sysrq.dk)
//
// (C) Copyright 2001 Phillip Pearson (http://www.myelin.co.nz)
// (C) Copyright 2003 Martin Willemoes Hansen
//
using System;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
/// <summary>
/// Tests System.Net.Sockets.TcpClient
/// </summary>
[TestFixture]
public class TcpClientTest
{
/// <summary>
/// Tests the TcpClient object
/// (from System.Net.Sockets)
/// </summary>
[Test]
public void TcpClient()
{
// set up a listening Socket
Socket lSock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
lSock.Bind(new IPEndPoint(IPAddress.Any, 8765));
lSock.Listen(-1);
// connect to it with a TcpClient
TcpClient outClient = new TcpClient("localhost", 8765);
Socket inSock = lSock.Accept();
// now try exchanging data
NetworkStream stream = outClient.GetStream();
const int len = 1024;
byte[] outBuf = new Byte[len];
for (int i=0; i<len; i++)
{
outBuf[i] = (byte)(i % 256);
}
// send it
stream.Write(outBuf,0,len);
// and see if it comes back
byte[] inBuf = new Byte[len];
int ret = inSock.Receive(inBuf, 0, len, 0);
Assert.IsTrue (ret != 0);
for (int i=0; i<len; i++)
{
Assert.IsTrue (inBuf[i] == outBuf[i]);
}
// tidy up
inSock.Close();
outClient.Close();
lSock.Close();
}
[Test] // bug #81105
public void CloseTest ()
{
IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765);
using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
sr.Start ();
TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
NetworkStream ns = tcpClient.GetStream ();
Assert.IsNotNull (ns, "#A1");
#if NET_2_0
Assert.AreEqual (0, tcpClient.Available, "#A2");
Assert.IsTrue (tcpClient.Connected, "#A3");
// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#A4");
#endif
tcpClient.Close ();
#if NET_2_0
Assert.IsNotNull (tcpClient.Client, "#A5");
try {
int available = tcpClient.Available;
Assert.Fail ("#A6: " + available);
} catch (ObjectDisposedException) {
}
Assert.IsFalse (tcpClient.Connected, "#A7");
// not supported on linux
/*
try {
bool exclusive = tcpClient.ExclusiveAddressUse;
Assert.Fail ("#A8: " + exclusive);
} catch (ObjectDisposedException) {
}
*/
#endif
}
using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
sr.Start ();
TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
#if NET_2_0
Assert.AreEqual (0, tcpClient.Available, "#B1");
Assert.IsTrue (tcpClient.Connected, "#B2");
// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#B3");
#endif
tcpClient.Close ();
#if NET_2_0
Assert.IsNull (tcpClient.Client, "#B4");
try {
int available = tcpClient.Available;
Assert.Fail ("#B5: " + available);
} catch (NullReferenceException) {
}
try {
bool connected = tcpClient.Connected;
Assert.Fail ("#B6: " + connected);
} catch (NullReferenceException) {
}
// not supported on linux
/*
try {
bool exclusive = tcpClient.ExclusiveAddressUse;
Assert.Fail ("#B7: " + exclusive);
} catch (NullReferenceException) {
}
*/
#endif
}
}
byte [] CloseRequestHandler (Socket socket)
{
return new byte [0];
}
#if NET_2_0
[Test]
[ExpectedException (typeof(ArgumentNullException))]
public void ConnectMultiNull ()
{
TcpClient client = new TcpClient ();
IPAddress[] ipAddresses = null;
client.Connect (ipAddresses, 1234);
}
[Test]
public void ConnectMultiAny ()
{
TcpClient client = new TcpClient ();
IPAddress[] ipAddresses = new IPAddress[1];
ipAddresses[0] = IPAddress.Any;
try {
client.Connect (ipAddresses, 1234);
Assert.Fail ("ConnectMultiAny #1");
} catch (SocketException ex) {
Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2");
} catch {
Assert.Fail ("ConnectMultiAny #3");
}
}
[Test]
public void ConnectMultiRefused ()
{
TcpClient client = new TcpClient ();
IPAddress[] ipAddresses = new IPAddress[1];
ipAddresses[0] = IPAddress.Loopback;
try {
client.Connect (ipAddresses, 1234);
Assert.Fail ("ConnectMultiRefused #1");
} catch (SocketException ex) {
Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiRefused #2");
} catch {
Assert.Fail ("ConnectMultiRefused #3");
}
}
#endif
}
}

View File

@@ -0,0 +1,194 @@
// System.Net.Sockets.TcpListenerTest.cs
//
// Authors:
// Phillip Pearson (pp@myelin.co.nz)
// Martin Willemoes Hansen (mwh@sysrq.dk)
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) Copyright 2001 Phillip Pearson (http://www.myelin.co.nz)
// (C) Copyright 2003 Martin Willemoes Hansen (mwh@sysrq.dk)
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class TcpListenerTest
{
[Test]
public void TcpListener ()
{
// listen with a new listener (IPv4 is the default)
TcpListener inListener = new TcpListener (8766);
inListener.Start();
// connect to it from a new socket
IPHostEntry hostent = Dns.GetHostByAddress (IPAddress.Loopback);
Socket outSock = null;
foreach (IPAddress address in hostent.AddressList) {
if (address.AddressFamily == AddressFamily.InterNetwork) {
/// Only keep IPv4 addresses, our Server is in IPv4 only mode.
outSock = new Socket (address.AddressFamily, SocketType.Stream,
ProtocolType.IP);
IPEndPoint remote = new IPEndPoint (address, 8766);
outSock.Connect (remote);
break;
}
}
// make sure the connection arrives
Assert.IsTrue (inListener.Pending ());
Socket inSock = inListener.AcceptSocket ();
// now send some data and see if it comes out the other end
const int len = 1024;
byte[] outBuf = new Byte [len];
for (int i=0; i<len; i++)
outBuf [i] = (byte) (i % 256);
outSock.Send (outBuf, 0, len, 0);
byte[] inBuf = new Byte[len];
int ret = inSock.Receive (inBuf, 0, len, 0);
// let's see if it arrived OK
Assert.IsTrue (ret != 0);
for (int i=0; i<len; i++)
Assert.IsTrue (inBuf[i] == outBuf [i]);
// tidy up after ourselves
inSock.Close ();
inListener.Stop ();
}
[Test]
public void CtorInt1 ()
{
int nex = 0;
try { new TcpListener (-1); } catch { nex++; }
new TcpListener (0);
new TcpListener (65535);
try { new TcpListener (65536); } catch { nex++; }
try { new TcpListener (100000); } catch { nex++; }
Assert.IsTrue (nex == 3);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorIPEndPoint ()
{
new TcpListener (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorIPAddressInt1 ()
{
new TcpListener (null, 100000);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CtorIPAddressInt2 ()
{
new TcpListener (IPAddress.Any, 100000);
}
class MyListener : TcpListener
{
public MyListener ()
: base (IPAddress.Loopback, 5000)
{
}
public Socket GetSocket ()
{
return Server;
}
public bool IsActive {
get { return Active; }
}
}
[Test]
public void PreStartStatus ()
{
MyListener listener = new MyListener ();
Assert.AreEqual (false, listener.IsActive, "#01");
Assert.IsTrue (null != listener.GetSocket (), "#02");
try {
listener.AcceptSocket ();
Assert.Fail ("Exception not thrown");
} catch (InvalidOperationException) {
}
try {
listener.AcceptTcpClient ();
Assert.Fail ("Exception not thrown");
} catch (InvalidOperationException) {
}
try {
listener.Pending ();
Assert.Fail ("Exception not thrown");
} catch (InvalidOperationException) {
}
listener.Stop ();
}
[Test]
public void PostStartStatus ()
{
MyListener listener = new MyListener ();
listener.Start ();
Assert.AreEqual (true, listener.IsActive, "#01");
Assert.IsTrue (null != listener.GetSocket (), "#02");
Socket sock = listener.GetSocket ();
listener.Start (); // Start called twice
Assert.AreEqual (true, listener.IsActive, "#03");
Assert.IsTrue (null != listener.GetSocket (), "#04");
Assert.AreEqual (false, listener.Pending (), "#05");
listener.Stop ();
Assert.AreEqual (false, listener.IsActive, "#06");
Assert.IsTrue (null != listener.GetSocket (), "#07");
Assert.IsTrue (sock != listener.GetSocket (), "#08");
}
#if NET_2_0
[Test]
public void StartListenMoreThan5 ()
{
TcpListener listen = new TcpListener (IPAddress.Loopback, 1234);
listen.Start (6);
listen.Stop ();
listen.Start (256);
listen.Stop ();
listen.Start (1024);
listen.Stop ();
listen.Start (32768);
listen.Stop ();
listen.Start (65536);
listen.Stop ();
}
#endif
}
}

File diff suppressed because it is too large Load Diff