Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2015-10-17 20:27:23 +0300
committerDavid Lechner <david@lechnology.com>2016-03-01 19:52:17 +0300
commit0f0d4804b19543fef3f64abc2e3b2941ab19fa62 (patch)
tree1a7ad4553405b347508d6e56837214eb973a1b26 /mcs/class/Mono.Posix
parentce285efd3a98dd0faa15e654dd7bc40eda457c1d (diff)
Add unit tests for Mono.Unix.UnixEndpoint and Mono.Unix.UnixListener
Tests for regression of https://bugzilla.xamarin.com/show_bug.cgi?id=35004
Diffstat (limited to 'mcs/class/Mono.Posix')
-rw-r--r--mcs/class/Mono.Posix/Mono.Posix_test.dll.sources2
-rw-r--r--mcs/class/Mono.Posix/Test/Mono.Unix/UnixEndPointTest.cs45
-rw-r--r--mcs/class/Mono.Posix/Test/Mono.Unix/UnixListenerTest.cs36
3 files changed, 83 insertions, 0 deletions
diff --git a/mcs/class/Mono.Posix/Mono.Posix_test.dll.sources b/mcs/class/Mono.Posix/Mono.Posix_test.dll.sources
index e2a49354a8e..a2f290f8656 100644
--- a/mcs/class/Mono.Posix/Mono.Posix_test.dll.sources
+++ b/mcs/class/Mono.Posix/Mono.Posix_test.dll.sources
@@ -1,7 +1,9 @@
Mono.Unix/ReadlinkTest.cs
Mono.Unix/StdioFileStreamTest.cs
Mono.Unix/UnixEncodingTest.cs
+Mono.Unix/UnixEndPointTest.cs
Mono.Unix/UnixGroupTest.cs
+Mono.Unix/UnixListenerTest.cs
Mono.Unix/UnixMarshalTest.cs
Mono.Unix/UnixPathTest.cs
Mono.Unix/UnixSignalTest.cs
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix/UnixEndPointTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixEndPointTest.cs
new file mode 100644
index 00000000000..21e5b791636
--- /dev/null
+++ b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixEndPointTest.cs
@@ -0,0 +1,45 @@
+// UnixEndPointTest.cs: Unit tests for Mono.Unix.UnixListener
+//
+// Authors:
+// David Lechner (david@lechnology.com)
+//
+// (c) 2015 David Lechner
+//
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+
+using NUnit.Framework;
+using Mono.Unix;
+
+namespace MonoTests.Mono.Unix {
+
+ [TestFixture]
+ public class UnixEndPointTest {
+
+ // Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=35004
+ [Test]
+ public void TestCreate ()
+ {
+ const string socketFile = "test";
+ // mangledSocketFile simulates the socket file name with a null
+ // terminator and junk after the null terminator. This can be present
+ // in a SocketAddress when marshaled from native code.
+ const string mangledSocketFile = socketFile + "\0junk";
+
+ var bytes = Encoding.Default.GetBytes (mangledSocketFile);
+ var socketAddress = new SocketAddress (AddressFamily.Unix, bytes.Length + 2);
+ for (int i = 0; i < bytes.Length; i++) {
+ socketAddress [i + 2] = bytes [i];
+ }
+ var dummyEndPoint = new UnixEndPoint (socketFile);
+
+ // testing that the Create() method strips off the null terminator and the junk
+ var endPoint = (UnixEndPoint)dummyEndPoint.Create (socketAddress);
+ Assert.AreEqual (socketFile, endPoint.Filename, "#A01");
+ }
+ }
+}
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix/UnixListenerTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixListenerTest.cs
new file mode 100644
index 00000000000..b2312b5590f
--- /dev/null
+++ b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixListenerTest.cs
@@ -0,0 +1,36 @@
+// UnixListenerTest.cs: Unit tests for Mono.Unix.UnixListener
+//
+// Authors:
+// David Lechner (david@lechnology.com)
+//
+// (c) 2015 David Lechner
+//
+
+using System;
+using System.IO;
+
+using NUnit.Framework;
+using Mono.Unix;
+
+namespace MonoTests.Mono.Unix {
+
+ [TestFixture]
+ public class UnixListenerTest {
+
+ // test that a socket file is created and deleted by the UnixListener
+ [Test]
+ public void TestSocketFileCreateDelete ()
+ {
+ var socketFile = Path.GetTempFileName ();
+ // we just want the file name, not the file
+ File.Delete (socketFile);
+
+ using (var listener = new UnixListener (socketFile)) {
+ // creating an instance of UnixListener should create the file
+ Assert.IsTrue (File.Exists (socketFile), "#A01");
+ }
+ // and disposing the UnixListener should delete the file
+ Assert.IsFalse (File.Exists (socketFile), "#A02");
+ }
+ }
+}