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,15 @@
2009-02-19 Jonathan Pryor <jonpryor@vt.edu>
* RealTimeSignumTest.cs: Disable the tests on Mac OS X, as OS X
doesn't support real-time signals.
2008-12-19 Jonathan Pryor <jonpryor@vt.edu>
* RealTimeSignumTest.cs: Added; unit tests for RealTimeSignum.
Patch thanks to tim.jenks@realtimeworlds.com.
2005-11-28 Jonathan Pryor <jonpryor@vt.edu>
* ChangeLog: Started.
* StdlibTest.cs: Moved from ../Mono.Unix. Test Mono.Unix.Native namespace.

View File

@@ -0,0 +1,87 @@
//
// RealTimeSignumTests.cs - NUnit Test Cases for Mono.Unix.Native.RealTimeSignum
//
// Authors:
// Tim Jenks <tim.jenks@realtimeworlds.com>
//
// (C) 2008 Realtime Worlds Ltd
//
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using System;
using System.Text;
using System.Threading;
using Mono.Unix;
using Mono.Unix.Native;
namespace MonoTests.Mono.Unix.Native {
[TestFixture]
[Category ("NotOnMac")]
public class RealTimeSignumTest
{
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TestRealTimeOutOfRange ()
{
RealTimeSignum rts = new RealTimeSignum (int.MaxValue);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TestRealTimeSignumNegativeOffset ()
{
RealTimeSignum rts1 = new RealTimeSignum (-1);
}
[Test]
public void TestRTSignalEquality ()
{
RealTimeSignum rts1 = new RealTimeSignum (0);
RealTimeSignum rts2 = new RealTimeSignum (0);
Assert.That (rts1 == rts2, Is.True);
Assert.That (rts1 != rts2, Is.False);
}
[Test]
public void TestRTSignalInequality ()
{
RealTimeSignum rts1 = new RealTimeSignum (0);
RealTimeSignum rts2 = new RealTimeSignum (1);
Assert.That (rts1 == rts2, Is.False);
Assert.That (rts1 != rts2, Is.True);
}
[Test]
public void TestRTSignalGetHashCodeEquality ()
{
RealTimeSignum rts1 = new RealTimeSignum (0);
RealTimeSignum rts2 = new RealTimeSignum (0);
Assert.That (rts1.GetHashCode (), Is.EqualTo(rts2.GetHashCode ()));
}
[Test]
public void TestRTSignalGetHashCodeInequality ()
{
RealTimeSignum rts1 = new RealTimeSignum (0);
RealTimeSignum rts2 = new RealTimeSignum (1);
Assert.That (rts1.GetHashCode (), Is.Not.EqualTo(rts2.GetHashCode ()));
}
[Test]
public void TestIsRTSignalPropertyForRTSignum ()
{
UnixSignal signal1 = new UnixSignal(new RealTimeSignum (0));
Assert.That (signal1.IsRealTimeSignal, Is.True);
}
[Test]
public void TestIsRTSignalPropertyForSignum ()
{
UnixSignal signal1 = new UnixSignal (Signum.SIGSEGV);
Assert.That (signal1.IsRealTimeSignal, Is.False);
}
}
}

View File

@@ -0,0 +1,105 @@
//
// StdlibTest.cs:
// NUnit Test Cases for Mono.Unix.Native.Stdlib
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2004-2005 Jonathan Pryor
//
using System;
using System.Text;
using NUnit.Framework;
using Mono.Unix.Native;
namespace MonoTests.Mono.Unix.Native {
[TestFixture]
public class StdlibTest
{
private class SignalTest {
public int signalReceived;
public void Handler (int sn)
{
signalReceived = sn;
}
}
// [Test]
#if !NET_2_0
// .NET 1.1 marshals delegates as Stdcall functions, while signal(3)
// expects a Cdecl function. Result: stack corruption.
// DO NOT USE Stdlib.signal under .NET 1.1!
// .NET 2.0 allows us to specify how delegates should be marshaled, so
// this isn't an issue there.
[Category ("NotDotNet")]
#endif
public void Signal ()
{
SignalTest st = new SignalTest ();
// Insert handler
SignalHandler oh = Stdlib.signal (Signum.SIGURG,
new SignalHandler (st.Handler));
st.signalReceived = ~NativeConvert.FromSignum (Signum.SIGURG);
// Send signal
Stdlib.raise (Signum.SIGURG);
Assert.IsTrue (
NativeConvert.ToSignum (st.signalReceived) == Signum.SIGURG,
"#IH: Signal handler not invoked for SIGURG");
// Reset old signal
Stdlib.signal (Signum.SIGURG, oh);
st.signalReceived = NativeConvert.FromSignum (Signum.SIGUSR1);
Stdlib.raise (Signum.SIGURG);
Assert.IsFalse (NativeConvert.ToSignum (st.signalReceived) == Signum.SIGURG,
"#IH: Signal Handler invoked when it should have been removed!");
}
[Test]
// MSVCRT.DLL doesn't export snprintf(3).
[Category ("NotDotNet")]
[Category ("NotWorking")]
public void Snprintf ()
{
StringBuilder s = new StringBuilder (1000);
Stdlib.snprintf (s, "hello, %s world!\n");
Assert.AreEqual (s.ToString(), "hello, %s world!\n",
"#SNPF: string not echoed");
s = new StringBuilder (1000);
Stdlib.snprintf (s, "yet another %s test", "simple");
Assert.AreEqual (s.ToString(), "yet another simple test",
"#SNPF: string argument not printed");
s = new StringBuilder (1000);
string fmt =
@"this is another test:
char: '%c'
short: %i
int: %i
long: %li
float: %g
double: %g" + "\n";
Stdlib.snprintf (s, fmt, 'a', (short) 16, 32, (long) 64, (double) 32.23, 64.46);
string expected =
@"this is another test:
char: 'a'
short: 16
int: 32
long: 64
float: 32.23
double: 64.46" + "\n";
Assert.AreEqual (s.ToString(), expected,
"#SNPF: printf of many builtin types failed");
}
}
}

View File

@@ -0,0 +1,144 @@
2009-08-28 Atsushi Enomoto <atsushi@ximian.com>
* UnixEncodingTest.cs : upgrade to modern nunit style.
2009-02-20 Jonathan Pryor <jpryor@novell.com>
* UnixSignalTest.cs: Add tests to check for concurrent
UnixSignal.WaitOne() invocations. Tests thanks to
tim.jenks@realtimeworlds.com.
2009-02-19 Jonathan Pryor <jpryor@novell.com>
* UnixSignalTest.cs: Disable the tests that use RealTimeSignum on OS X,
as OS X doesn't support real-time signals (and thus these will
always error, often for the "wrong" reason).
2009-01-08 Rodrigo Kumpera <rkumpera@novell.com>
* UnixSignalTest.cs: Fix the RealTimeSignum constructor
tests to take into account the fact that some signals might be
in used by the runtime. Added a test for multiple registration
of a rt signal.
2009-01-07 Geoff Norton <gnorton@novell.com>
* UnixSignalTest.cs: Disable the tests that storm signals on OSX.
(They wont work)
2008-11-19 Jonathan Pryor <jpryor@novell.com>
* UnixSignalTest.cs: Add tests for RealTimeSignum constructors,
.RealTimeSignum and .IsRealTimeSignal properties.
Patch thanks to tim.jenks@realtimeworlds.com.
2008-11-12 Gonzalo Paniagua Javier <gonzalo@novell.com>
* UnixSignalTest.cs: use WaitAny + 30s timeout.
2008-02-12 Zoltan Varga <vargaz@gmail.com>
* UnixSignalTest.cs: Fix the build.
2008-02-09 Jonathan Pryor <jonpryor@vt.edu>
* UnixSignalTest.cs: Added; tests Mono.Unix.UnixSignal.
2006-07-02 Jonathan Pryor <jonpryor@vt.edu>
* UnixPathTest.cs: Added; test UnixPath.Combine().
2005-12-07 Jonathan Pryor <jonpryor@vt.edu>
* UnixMarshalTest.cs: Make test public so that it's actually executed by
NUnit; NUnit doesn't like private Test* methods -- rename; test
UnixMarshal.PtrToString for a string containing 0 characters (this used to
cause an ArgumentOutOfRangeException due to a bug).
2005-12-05 Jonathan Pryor <jonpryor@vt.edu>
* UnixUserTest.cs: s/UnixUser/UnixUserInfo/g (UnixUser is obsolete).
2005-12-05 Jonathan Pryor <jonpryor@vt.edu>
* UnixMarshalTest.cs: s/Free/FreeHeap/g (UnixMarshal.Free will be removed).
2005-11-28 Jonathan Pryor <jonpryor@vt.edu>
* UnixGroupTest.cs: The type of UnixGroupInfo.GroupId changed. UnixGroup is
deprecated; use UnixGroupInfo instead.
* UnixUserTest.cs: The type of UnixUserInfo.UserId changed. UnixUser if
deprecated; use UnixUserInfo instead.
2005-10-26 Jonathan Pryor <jonpryor@vt.edu>
* UnixMarshalTest.cs: s/StringToAlloc/StringToHeap/g (UnixMarshal change).
* UnixEncodingTest.cs: Deal with UnixEncoding.EscapeByte value change.
2005-10-25 Jonathan Pryor <jonpryor@vt.edu>
* UnixEncodingTest.cs: Added string/byte[] encoding tests for
Mono.Unix.UnixEncoding.
2005-10-17 Jonathan Pryor <jonpryor@vt.edu>
* UnixMarshalTest.cs: Added string marshaling tests for Mono.Unix.UnixMarshal.
2005-06-29 Miguel de Icaza <miguel@ximian.com>
* StdioFileStreamTest.cs: comment out tests that depend on the
underlying Stdio implementation.
2005-05-21 Ben Maurer <bmaurer@ximian.com>
* UnixUserTest.cs, UnixGroupTest.cs: Disable tests that might not
work on a Solaris box with NIS. Bug #72293.
2005-04-29 Jonathan Pryor <jonpryor@vt.edu>
* StdioFileStreamTest.cs: Add FilePosition tests; remove `var = var`
lines (added to remove warnings, but now produces other warnings).
2005-04-28 Jonathan Pryor <jonpryor@vt.edu>
* StdlibTest.cs: Calling a P/Invoke function from signal-handler context is
*bad*, which is why I've had so much trouble getting consistent results
getting this test to work -- it was broken by design. Instead, just save
the signum passed to the handler (which is reentrant safe), and compare
the saved value with the expected value after the signal handler returns.
This should always work. Use SIGURG instead of SIGUSR1 because SIGURG is
ignored by default (allowing us to call it without adding your own
handler), unlike SIGUSR1 which terminates the program.
2005-03-28 Jonathan Pryor <jonpryor@vt.edu>
* StdioFileStreamTest.cs: Added; based on MonoTests.System.IO.FileStreamTest.
2005-02-09 Jonathan Pryor <jonpryor@vt.edu>
* StdlibTest.cs: Signal is currently ignored, but add Category(NotDotNet) so
it isn't run even when we fix it. .NET 1.1 doesn't marshal delegates
properly for signal (different calling conventions).
Add Category(NotDotNet) for Snprintf(), as MSVCRT.dll doesn't export it.
* UnixGroupTest.cs, UnixUserTest.cs: Don't run these under .NET, as Windows
doesn't support the Syscall and related classes.
2005-02-01 Raja R Harinath <rharinath@novell.com>
* UnixUserTest.cs (UnixUserTest.ReentrantConstructors): Don't
assume userid<->username mapping is a bijection.
(UnixUserTest.NonReentrantSyscalls): Likewise.
2005-01-20 Jonathan Pryor <jonpryor@vt.edu>
* StdlibTest.cs: Ignore the signal(3) test, as it's currently hanging Mono.
2005-01-13 Jonathan Pryor <jonpryor@vt.edu>
* StdlibTest.cs: Added tests for signal(3) and snprintf(3).
2005-01-05 Jonathan Pryor <jonpryor@vt.edu>
* ChangeLog: Started.
* UnixGroupTest.cs, UnixUserTest.cs: Added.

View File

@@ -0,0 +1,288 @@
//
// readlink() / readlinkat() Test Cases
//
// Authors:
// Steffen Kiess (s-kiess@web.de)
//
// Copyright (C) 2013 Steffen Kiess
//
using System;
using System.IO;
using System.Text;
using Mono.Unix;
using Mono.Unix.Native;
using NUnit.Framework;
namespace MonoTests.Mono.Unix
{
[TestFixture, Category ("NotDotNet")]
public class ReadlinkTest {
static string[] Targets = {
// Simple test cases
"a",
"test",
// With non-ASCII characters
"ä",
"test ö test",
// With non-UTF8 bytes
UnixEncoding.Instance.GetString (new byte[] {0xff, 0x80, 0x41, 0x80}),
// Size is roughly initial size of buffer
new string ('a', 255),
new string ('a', 256),
new string ('a', 257),
// With non-ASCII characters, size is roughly initial size of buffer
"ä" + new string ('a', 253), // 254 chars, 255 bytes
"ä" + new string ('a', 254), // 255 chars, 256 bytes
"ä" + new string ('a', 255), // 256 chars, 257 bytes
"ä" + new string ('a', 256), // 257 chars, 258 bytes
new string ('a', 253) + "ä", // 254 chars, 255 bytes
new string ('a', 254) + "ä", // 255 chars, 256 bytes
new string ('a', 255) + "ä", // 256 chars, 257 bytes
new string ('a', 256) + "ä", // 257 chars, 258 bytes
// With non-UTF8 bytes, size is roughly initial size of buffer
"\0\u00ff" + new string ('a', 253), // 255 chars, 254 bytes
"\0\u00ff" + new string ('a', 254), // 256 chars, 255 bytes
"\0\u00ff" + new string ('a', 255), // 257 chars, 256 bytes
"\0\u00ff" + new string ('a', 256), // 258 chars, 257 bytes
new string ('a', 253) + "\0\u00ff", // 255 chars, 254 bytes
new string ('a', 254) + "\0\u00ff", // 256 chars, 255 bytes
new string ('a', 255) + "\0\u00ff", // 257 chars, 256 bytes
new string ('a', 256) + "\0\u00ff", // 258 chars, 257 bytes
};
bool HaveReadlinkAt;
string TempFolder;
int TempFD;
[SetUp]
public void SetUp ()
{
HaveReadlinkAt = false;
try {
Syscall.readlinkat (-1, "", new byte[1]);
HaveReadlinkAt = true;
} catch (EntryPointNotFoundException) {
}
TempFolder = Path.Combine (Path.GetTempPath (), this.GetType ().FullName);
if (Directory.Exists (TempFolder))
//Directory.Delete (TempFolder, true); // Fails for long link target paths
new UnixDirectoryInfo (TempFolder).Delete (true);
Directory.CreateDirectory (TempFolder);
TempFD = Syscall.open (TempFolder, OpenFlags.O_RDONLY | OpenFlags.O_DIRECTORY);
if (TempFD < 0)
UnixMarshal.ThrowExceptionForLastError ();
}
[TearDown]
public void TearDown()
{
if (Syscall.close (TempFD) < 0)
UnixMarshal.ThrowExceptionForLastError ();
if (Directory.Exists (TempFolder))
//Directory.Delete (TempFolder, true); // Fails for long link target paths
new UnixDirectoryInfo (TempFolder).Delete (true);
}
void CreateLink (string s)
{
string link = UnixPath.Combine (TempFolder, "link");
//File.Delete (link); // Fails for long link target paths
if (Syscall.unlink (link) < 0 && Stdlib.GetLastError () != Errno.ENOENT)
UnixMarshal.ThrowExceptionForLastError ();
if (Syscall.symlink (s, link) < 0)
UnixMarshal.ThrowExceptionForLastError ();
}
[Test]
public void ReadLink ()
{
foreach (string s in Targets) {
string link = UnixPath.Combine (TempFolder, "link");
CreateLink (s);
var target = UnixPath.ReadLink (link);
Assert.AreEqual (s, target);
}
}
[Test]
public void ReadLinkAt ()
{
if (!HaveReadlinkAt)
Assert.Ignore ("No ReadlinkAt.");
foreach (string s in Targets) {
CreateLink (s);
var target = UnixPath.ReadLinkAt (TempFD, "link");
Assert.AreEqual (s, target);
}
}
[Test]
public void TryReadLink ()
{
foreach (string s in Targets) {
string link = UnixPath.Combine (TempFolder, "link");
CreateLink (s);
var target = UnixPath.TryReadLink (link);
Assert.AreEqual (s, target);
}
}
[Test]
public void TryReadLinkAt ()
{
if (!HaveReadlinkAt)
Assert.Ignore ("No ReadlinkAt.");
foreach (string s in Targets) {
CreateLink (s);
var target = UnixPath.TryReadLinkAt (TempFD, "link");
Assert.AreEqual (s, target);
}
}
[Test]
public void readlink_byte ()
{
foreach (string s in Targets) {
string link = UnixPath.Combine (TempFolder, "link");
CreateLink (s);
string target = null;
byte[] buf = new byte[256];
do {
long r = Syscall.readlink (link, buf);
if (r < 0)
UnixMarshal.ThrowExceptionForLastError ();
Assert.GreaterOrEqual (buf.Length, r);
if (r == buf.Length)
buf = new byte[checked (buf.Length * 2)];
else
target = UnixEncoding.Instance.GetString (buf, 0, checked ((int) r));
} while (target == null);
Assert.AreEqual (s, target);
}
}
[Test]
public void readlinkat_byte ()
{
if (!HaveReadlinkAt)
Assert.Ignore ("No ReadlinkAt.");
foreach (string s in Targets) {
CreateLink (s);
string target = null;
byte[] buf = new byte[256];
do {
long r = Syscall.readlinkat (TempFD, "link", buf);
if (r < 0)
UnixMarshal.ThrowExceptionForLastError ();
Assert.GreaterOrEqual (buf.Length, r);
if (r == buf.Length)
buf = new byte[checked (buf.Length * 2)];
else
target = UnixEncoding.Instance.GetString (buf, 0, checked ((int) r));
} while (target == null);
Assert.AreEqual (s, target);
}
}
[Test]
public void readlink_char ()
{
foreach (string s in Targets) {
string link = UnixPath.Combine (TempFolder, "link");
CreateLink (s);
var sb = new StringBuilder (256);
do {
int oldCapacity = sb.Capacity;
int r = Syscall.readlink (link, sb);
Assert.AreEqual (oldCapacity, sb.Capacity);
if (r < 0)
UnixMarshal.ThrowExceptionForLastError ();
Assert.AreEqual (r, sb.Length);
Assert.GreaterOrEqual (sb.Capacity, r);
if (r == sb.Capacity)
checked { sb.Capacity *= 2; }
else
break;
} while (true);
var target = sb.ToString ();
Assert.AreEqual (s, target);
}
}
[Test]
public void readlinkat_char ()
{
if (!HaveReadlinkAt)
Assert.Ignore ("No ReadlinkAt.");
foreach (string s in Targets) {
CreateLink (s);
var sb = new StringBuilder (256);
do {
int oldCapacity = sb.Capacity;
int r = Syscall.readlinkat (TempFD, "link", sb);
Assert.AreEqual (oldCapacity, sb.Capacity);
if (r < 0)
UnixMarshal.ThrowExceptionForLastError ();
Assert.AreEqual (r, sb.Length);
Assert.GreaterOrEqual (sb.Capacity, r);
if (r == sb.Capacity)
checked { sb.Capacity *= 2; }
else
break;
} while (true);
var target = sb.ToString ();
Assert.AreEqual (s, target);
}
}
[Test]
public void ReadlinkMultiByteChar ()
{
string link = UnixPath.Combine (TempFolder, "link");
CreateLink ("á");
var sb = new StringBuilder (2);
int res = Syscall.readlink (link, sb);
if (res < 0)
UnixMarshal.ThrowExceptionForLastError ();
Assert.AreEqual (res, 2);
Assert.AreEqual (sb.Length, 2);
Assert.AreEqual (sb.Capacity, 2);
Assert.AreEqual (sb.ToString (), "á\u0000");
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
//
// UnixGroupTest.cs:
// NUnit Test Cases for Mono.Unix.UnixGroup
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2004 Jonathan Pryor
//
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using Mono.Unix;
using Group = Mono.Unix.Native.Group;
using Syscall = Mono.Unix.Native.Syscall;
namespace MonoTests.Mono.Unix {
[TestFixture, Category ("NotDotNet")]
public class UnixGroupTest
{
[Test]
public void ListAllGroups_ToString ()
{
try {
Console.WriteLine ("Listing all groups");
foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
Console.WriteLine ("\t{0}", group);
}
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TLAU_TS: Exception listing local groups: {0}",
e.ToString()));
}
}
[Test]
public void ReentrantConstructors ()
{
var seen = new Dictionary<string, object> ();
foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
if (seen.ContainsKey (group.GroupName))
continue;
seen.Add (group.GroupName, null);
try {
UnixGroupInfo byName = new UnixGroupInfo (group.GroupName);
UnixGroupInfo byId = new UnixGroupInfo (group.GroupId);
Assert.AreEqual (group, byName, "#TRC: construct by name");
Assert.AreEqual (group, byId, "#TRC: construct by gid");
Assert.AreEqual (byName, byId, "#TRC: name == gid?");
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TRC: Exception constructing UnixGroupInfo: {0}",
e.ToString()));
}
}
}
[Test]
public void NonReentrantSyscalls ()
{
var seen = new Dictionary<string, object> ();
foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
if (seen.ContainsKey (group.GroupName))
continue;
seen.Add (group.GroupName, null);
try {
Group byName = Syscall.getgrnam (group.GroupName);
Group byId = Syscall.getgrgid ((uint) group.GroupId);
Assert.IsNotNull (byName, "#TNRS: access by name");
Assert.IsNotNull (byId, "#TNRS: access by gid");
UnixGroupInfo n = new UnixGroupInfo (byName);
UnixGroupInfo u = new UnixGroupInfo (byId);
Assert.AreEqual (group, n, "#TNRS: construct by name");
Assert.AreEqual (group, u, "#TNRS: construct by gid");
Assert.AreEqual (n, u, "#TNRS: name == gid?");
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TRC: Exception constructing UnixGroupInfo: {0}",
e.ToString()));
}
}
}
[Test]
public void InvalidGroups_Constructor_Name ()
{
string[] badGroups = new string[]{"i'm bad", "so am i", "does-not-exist"};
foreach (string u in badGroups) {
try {
new UnixGroupInfo (u);
Assert.Fail ("#TIUCN: exception not thrown");
}
catch (ArgumentException) {
// expected
}
catch (Exception e) {
Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
"expected ArgumentException, got {0}: {1}",
e.GetType().FullName, e.Message));
}
}
}
[Test]
public void InvalidGroups_Syscall_Name ()
{
string[] badGroups = new string[]{"i'm bad", "so am i", "does-not-exist"};
foreach (string u in badGroups) {
try {
Group pw = Syscall.getgrnam (u);
Assert.IsNull (pw, "#TIUSN: invalid groups should return null!");
}
catch (Exception e) {
Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
"expected null return, got {0}: {1}",
e.GetType().FullName, e.Message));
}
}
}
[Test]
public void Equality ()
{
Group orig = new Group ();
Group mod = new Group ();
mod.gr_name = orig.gr_name = "some name";
mod.gr_passwd = orig.gr_passwd = "some passwd";
mod.gr_gid = orig.gr_gid = 500;
mod.gr_mem = orig.gr_mem = new string[]{"foo", "bar"};
Assert.AreEqual (orig, mod, "#TE: copies should be equal");
mod.gr_name = "another name";
Assert.IsFalse (orig.Equals (mod), "#TE: changes should be reflected");
}
}
}

View File

@@ -0,0 +1,92 @@
// UnixMarshalTests.cs - NUnit2 Test Cases for Mono.Unix.UnixMarshal class
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (c) 2005 Jonathan Pryor
//
using NUnit.Framework;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Mono.Unix;
namespace MonoTests.Mono.Unix {
class RandomEncoding : UTF8Encoding {
public RandomEncoding ()
: base (false, true)
{
}
public override int GetMaxByteCount (int value)
{
return value*6;
}
}
[TestFixture]
public class UnixMarshalTest {
#if false
public static void Main ()
{
string s = UnixMarshal.GetErrorDescription (Errno.ERANGE);
Console.WriteLine ("ERANGE={0}", s);
s = UnixMarshal.GetErrorDescription ((Errno) 999999);
Console.WriteLine ("Invalid={0}", s);
}
#endif
[Test]
public void TestStringToHeap ()
{
object[] data = {
"Hello, world!", true, true,
" Pゴシック", false, true,
};
for (int i = 0; i < data.Length; i += 3) {
string s = (string) data [i+0];
bool valid_ascii = (bool) data [i+1];
bool valid_unicode = (bool) data [i+2];
StringToHeap (s, valid_ascii, valid_unicode);
}
}
private static void StringToHeap (string s, bool validAscii, bool validUnicode)
{
StringToHeap (s, Encoding.ASCII, validAscii);
StringToHeap (s, Encoding.UTF7, validUnicode);
StringToHeap (s, Encoding.UTF8, validUnicode);
StringToHeap (s, Encoding.Unicode, validUnicode);
StringToHeap (s, Encoding.BigEndianUnicode, validUnicode);
StringToHeap (s, new RandomEncoding (), validUnicode);
}
private static void StringToHeap (string s, Encoding e, bool mustBeEqual)
{
IntPtr p = UnixMarshal.StringToHeap (s, e);
try {
string _s = UnixMarshal.PtrToString (p, e);
if (mustBeEqual)
Assert.AreEqual (s, _s, "#TSTA (" + e.GetType() + ")");
}
finally {
UnixMarshal.FreeHeap (p);
}
}
[Test]
public void TestPtrToString ()
{
IntPtr p = UnixMarshal.AllocHeap (1);
Marshal.WriteByte (p, 0);
string s = UnixMarshal.PtrToString (p);
UnixMarshal.FreeHeap (p);
}
}
}

View File

@@ -0,0 +1,86 @@
//
// Mono.Unix.UnixPath Test Cases
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (c) 2006 Jonathan Pryor
//
using NUnit.Framework;
using System.IO;
using System;
using System.Text;
using Mono.Unix;
namespace MonoTests.Mono.Unix
{
[TestFixture, Category ("NotDotNet")]
public class UnixPathTest {
private static readonly char DSC = UnixPath.DirectorySeparatorChar;
[Test]
public void Combine ()
{
string path, expected;
string current = UnixDirectoryInfo.GetCurrentDirectory ();
path = UnixPath.Combine ("/etc", "init.d");
Assert.AreEqual ("/etc/init.d", path);
path = UnixPath.Combine ("one", "");
Assert.AreEqual ("one", path);
path = UnixPath.Combine ("", "one");
Assert.AreEqual ("one", path);
path = UnixPath.Combine (current, "one");
expected = current + DSC + "one";
Assert.AreEqual (expected, path);
path = UnixPath.Combine ("one", current);
Assert.AreEqual (current, path);
path = UnixPath.Combine (current, expected);
Assert.AreEqual (expected, path);
path = DSC + "one";
path = UnixPath.Combine (path, "two" + DSC);
expected = DSC + "one" + DSC + "two" + DSC;
Assert.AreEqual (expected, path);
path = "one" + DSC;
path = UnixPath.Combine (path, DSC + "two");
expected = DSC + "two";
Assert.AreEqual (expected, path);
path = "one" + DSC;
path = UnixPath.Combine (path, "two" + DSC);
expected = "one" + DSC + "two" + DSC;
Assert.AreEqual (expected, path);
path = UnixPath.Combine ("/a", "b", "c", "/d", "e");
expected = "/d/e";
Assert.AreEqual (expected, path);
try {
path = UnixPath.Combine ("one", null);
Assert.Fail ("Combine Fail #01");
}
catch (Exception e) {
Assert.AreEqual (typeof (ArgumentNullException), e.GetType ());
}
try {
path = UnixPath.Combine (null, "one");
Assert.Fail ("Combine Fail #02");
}
catch (Exception e) {
Assert.AreEqual (typeof (ArgumentNullException), e.GetType ());
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
//
// UnixUserTest.cs:
// NUnit Test Cases for Mono.Unix.UnixUser
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2004 Jonathan Pryor
//
using NUnit.Framework;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Collections;
using Mono.Unix;
using Passwd = Mono.Unix.Native.Passwd;
using Syscall = Mono.Unix.Native.Syscall;
namespace MonoTests.Mono.Unix {
[TestFixture, Category ("NotDotNet")]
public class UnixUserTest
{
[Test]
public void ListAllUsers_ToString ()
{
try {
Console.WriteLine ("Listing all users");
foreach (UnixUserInfo user in UnixUserInfo.GetLocalUsers ()) {
Console.WriteLine ("\t{0}", user);
}
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TLAU_TS: Exception listing local users: {0}",
e.ToString()));
}
}
[Test]
// According to bug 72293, this may not work:
// On systems with NIS, it is possible to have multiple users in the passwd
// file with the same name, so the assertion above no longer holds.
[Category ("NotWorking")]
public void ReentrantConstructors ()
{
ArrayList user_ids = new ArrayList (4);
IList users = UnixUserInfo.GetLocalUsers ();
foreach (UnixUserInfo user in users) {
try {
UnixUserInfo byName = new UnixUserInfo (user.UserName);
Assert.AreEqual (user, byName, "#TRC: construct by name");
if (! user_ids.Contains (user.UserId))
user_ids.Add (user.UserId);
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TRC: Exception constructing UnixUserInfo (string): {0}",
e.ToString()));
}
}
foreach (uint uid in user_ids) {
try {
UnixUserInfo byId = new UnixUserInfo (uid);
Assert.IsTrue (users.Contains (byId), "TRC: construct by uid");
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TRC: Exception constructing UnixUserInfo (uint): {0}",
e.ToString()));
}
}
}
[Test]
[Category ("NotOnMac")]
public void NonReentrantSyscalls ()
{
ArrayList user_ids = new ArrayList (4);
IList users = UnixUserInfo.GetLocalUsers ();
foreach (UnixUserInfo user in users) {
try {
Passwd byName = Syscall.getpwnam (user.UserName);
Assert.IsNotNull (byName, "#TNRS: access by name");
UnixUserInfo n = new UnixUserInfo (byName);
Assert.AreEqual (user, n, "#TNRS: construct by name");
if (! user_ids.Contains (user.UserId))
user_ids.Add (user.UserId);
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TNRS: Exception constructing UnixUserInfo (string): {0}",
e.ToString()));
}
}
foreach (long uid in user_ids) {
try {
Passwd byId = Syscall.getpwuid (Convert.ToUInt32 (uid));
Assert.IsNotNull (byId, "#TNRS: access by uid");
UnixUserInfo u = new UnixUserInfo (byId);
Assert.IsTrue (users.Contains (u), "TNRS: construct by uid");
}
catch (Exception e) {
Assert.Fail (
string.Format ("#TNRS: Exception constructing UnixUserInfo (uint): {0}",
e.ToString()));
}
}
}
[Test]
public void InvalidUsers_Constructor_Name ()
{
string[] badUsers = new string[]{"i'm bad", "so am i", "does-not-exist"};
foreach (string u in badUsers) {
try {
new UnixUserInfo (u);
Assert.Fail ("#TIUCN: exception not thrown");
}
catch (ArgumentException) {
// expected
}
catch (Exception e) {
Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
"expected ArgumentException, got {0}: {1}",
e.GetType().FullName, e.Message));
}
}
}
[Test]
public void InvalidUsers_Syscall_Name ()
{
string[] badUsers = new string[]{"i'm bad", "so am i", "does-not-exist"};
foreach (string u in badUsers) {
try {
Passwd pw = Syscall.getpwnam (u);
Assert.IsNull (pw, "#TIUSN: invalid users should return null!");
}
catch (Exception e) {
Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
"expected ArgumentException, got {0}: {1}",
e.GetType().FullName, e.Message));
}
}
}
[Test]
public void Equality ()
{
Passwd orig = new Passwd ();
Passwd mod = new Passwd ();
mod.pw_name = orig.pw_name = "some name";
mod.pw_passwd = orig.pw_passwd = "some passwd";
mod.pw_uid = orig.pw_uid = 500;
mod.pw_gid = orig.pw_gid = 500;
mod.pw_gecos = orig.pw_gecos = "some gecos";
mod.pw_dir = orig.pw_dir = "/some/dir";
mod.pw_shell = orig.pw_shell = "/some/shell";
Assert.AreEqual (orig, mod, "#TE: copies should be equal");
mod.pw_name = "another name";
Assert.IsFalse (orig.Equals (mod), "#TE: changes should be reflected");
}
}
}