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,73 @@
//
// ActivatorCas.cs - CAS unit tests for System.Activator
//
// 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.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System {
[TestFixture]
[Category ("CAS")]
public class ActivatorCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// we use reflection to call Activator as the GetObject methods are protected
// by LinkDemand (which will be converted into full demand, i.e. a stack walk)
// when reflection is used (i.e. it gets testable).
[Test]
[SecurityPermission (SecurityAction.Deny, RemotingConfiguration = true)]
[ExpectedException (typeof (SecurityException))]
public void GetObject2 ()
{
Type[] parameters = new Type [2] { typeof (Type), typeof (string) };
MethodInfo mi = typeof (Activator).GetMethod ("GetObject", parameters);
Assert.IsNotNull (mi.Invoke (null, new object [2] { typeof (object), String.Empty }), "GetObject");
}
[Test]
[SecurityPermission (SecurityAction.Deny, RemotingConfiguration = true)]
[ExpectedException (typeof (SecurityException))]
public void GetObject3 ()
{
Type[] parameters = new Type [3] { typeof (Type), typeof (string), typeof (object) };
MethodInfo mi = typeof (Activator).GetMethod ("GetObject", parameters);
Assert.IsNotNull (mi.Invoke (null, new object [3] { typeof (object), String.Empty, null }), "GetObject");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,144 @@
// AggregateExceptionTests.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// 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_4_0
using System;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
using NUnit;
using NUnit.Framework;
namespace MonoTests.System
{
[TestFixture]
public class AggregateExceptionTest
{
AggregateException e;
[SetUpAttribute]
public void Setup()
{
e = new AggregateException(new Exception("foo"), new AggregateException(new Exception("bar"), new Exception("foobar")));
}
[Test]
public void SimpleInnerExceptionTestCase ()
{
var message = "Foo";
var inner = new ApplicationException (message);
var ex = new AggregateException (inner);
Assert.IsNotNull (ex.InnerException);
Assert.IsNotNull (ex.InnerExceptions);
Assert.AreEqual (inner, ex.InnerException);
Assert.AreEqual (1, ex.InnerExceptions.Count);
Assert.AreEqual (inner, ex.InnerExceptions[0]);
Assert.AreEqual (message, ex.InnerException.Message);
Assert.AreEqual (inner, ex.GetBaseException ());
}
[TestAttribute]
public void FlattenTestCase()
{
AggregateException ex = e.Flatten();
Assert.AreEqual(3, ex.InnerExceptions.Count, "#1");
Assert.AreEqual(3, ex.InnerExceptions.Where((exception) => !(exception is AggregateException)).Count(), "#2");
}
[Test, ExpectedException (typeof (ArgumentException))]
public void InitializationWithNullInnerValuesTest ()
{
var foo = new AggregateException (new Exception[] { new Exception (), null, new ApplicationException ()});
}
[Test]
public void InitializationWithNullValuesTest ()
{
Throws (typeof (ArgumentNullException), () => new AggregateException ((IEnumerable<Exception>)null));
Throws (typeof (ArgumentNullException), () => new AggregateException ((Exception[])null));
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Handle_Invalid ()
{
e.Handle (null);
}
[Test]
public void Handle_AllHandled ()
{
e.Handle (l => true);
}
[Test]
public void Handle_Unhandled ()
{
try {
e.Handle (l => l is AggregateException);
Assert.Fail ();
} catch (AggregateException e) {
Assert.AreEqual (1, e.InnerExceptions.Count);
}
}
[Test]
public void GetBaseWithInner ()
{
var ae = new AggregateException ("x", new [] { new ArgumentException (), new ArgumentNullException () });
Assert.AreEqual (ae, ae.GetBaseException (), "#1");
var expected = new ArgumentException ();
var ae2 = new AggregateException ("x", new AggregateException (expected, new Exception ()));
Assert.AreEqual (expected, ae2.GetBaseException ().InnerException, "#2");
}
[Test]
public void GetBaseException_stops_at_first_inner_exception_that_is_not_AggregateException()
{
var inner = new ArgumentNullException ();
var outer = new InvalidOperationException ("x", inner);
Assert.AreEqual (outer, new AggregateException (outer).GetBaseException ());
}
static void Throws (Type t, Action action)
{
Exception e = null;
try {
action ();
} catch (Exception ex) {
e = ex;
}
if (e == null || e.GetType () != t)
Assert.Fail ();
}
}
}
#endif

View File

@@ -0,0 +1,406 @@
//
// AppDomainCas.cs - CAS unit tests for System.AppDomain
//
// 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.Reflection;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
namespace MonoCasTests.System {
[TestFixture]
[Category ("CAS")]
public class AppDomainCas {
private AppDomain ad;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// it's safe to create the AppDomain here
string temp = Path.GetTempPath ();
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationName = "CAS";
setup.PrivateBinPath = temp;
setup.DynamicBase = temp;
ad = AppDomain.CreateDomain ("CAS", null, setup);
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// Partial Trust Tests
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void PartialTrust_Deny_Unrestricted ()
{
// static
Assert.IsNotNull (AppDomain.CurrentDomain, "CurrentDomain");
// instance
Assert.IsNotNull (ad.FriendlyName, "FriendlyName");
Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
Assert.IsFalse (ad.ShadowCopyFiles, "ShadowCopyFiles");
}
// see http://bugzilla.ximian.com/show_bug.cgi?id=74411
[Category ("NotWorking")]
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void BaseDirectory_Deny_FileIOPermission ()
{
Assert.IsNotNull (ad.BaseDirectory, "BaseDirectory");
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateDomain1_Deny_ControlAppDomain ()
{
AppDomain.CreateDomain (null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateDomain2_Deny_ControlAppDomain ()
{
AppDomain.CreateDomain (null, null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateDomain3_Deny_ControlAppDomain ()
{
AppDomain.CreateDomain (null, null, null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateDomain5_Deny_ControlAppDomain ()
{
AppDomain.CreateDomain (null, null, null, null, false);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateDomain7_Deny_ControlAppDomain ()
{
AppDomain.CreateDomain (null, null, null, null, false, null, null);
}
// see http://bugzilla.ximian.com/show_bug.cgi?id=74411
[Category ("NotWorking")]
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void DynamicDirectory_Deny_FileIOPermission ()
{
Assert.IsNotNull (ad.DynamicDirectory, "DynamicDirectory");
}
[Category ("NotWorking")] // check not yet implemented
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void Evidence_Deny_ControlEvidence ()
{
Assert.IsNotNull (ad.Evidence, "Evidence");
}
// see http://bugzilla.ximian.com/show_bug.cgi?id=74411
[Category ("NotWorking")]
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void RelativeSearchPath_Deny_FileIOPermission ()
{
Assert.IsNotNull (ad.RelativeSearchPath, "RelativeSearchPath");
}
// see http://bugzilla.ximian.com/show_bug.cgi?id=74411
[Category ("NotWorking")]
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPrincipal = true)]
[ExpectedException (typeof (SecurityException))]
public void SetPrincipalPolicy_Deny_ControlPrincipal ()
{
ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
}
// see http://bugzilla.ximian.com/show_bug.cgi?id=74411
[Category ("NotWorking")]
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPrincipal = true)]
[ExpectedException (typeof (SecurityException))]
public void SetThreadPrincipal_Deny_ControlPrincipal ()
{
ad.SetThreadPrincipal (new GenericPrincipal (new GenericIdentity ("me"), null));
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void Unload_Deny_ControlAppDomain ()
{
AppDomain.Unload (null);
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void PermitOnly_FileIOPermission ()
{
Assert.IsNotNull (ad.BaseDirectory, "BaseDirectory");
Assert.IsNotNull (ad.DynamicDirectory, "DynamicDirectory");
Assert.IsNotNull (ad.RelativeSearchPath, "RelativeSearchPath");
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true)]
public void PermitOnly_ControlEvidence ()
{
// other permissions required to get evidence from another domain
Assert.IsNotNull (AppDomain.CurrentDomain.Evidence, "Evidence");
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPrincipal = true)]
public void PermitOnly_ControlPrincipal ()
{
ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
ad.SetThreadPrincipal (new GenericPrincipal (new GenericIdentity ("me"), null));
}
// we use reflection to call AppDomain as some methods and events are protected
// by LinkDemand (which will be converted into full demand, i.e. a stack walk)
// when reflection is used (i.e. it gets testable).
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AppendPrivatePath ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("AppendPrivatePath");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { String.Empty });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void ClearPrivatePath ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("ClearPrivatePath");
mi.Invoke (AppDomain.CurrentDomain, null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void ClearShadowCopyPath ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("ClearShadowCopyPath");
mi.Invoke (AppDomain.CurrentDomain, null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void SetCachePath ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("SetCachePath");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { String.Empty });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void SetData ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("SetData");
mi.Invoke (AppDomain.CurrentDomain, new object [2] { String.Empty, null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void SetShadowCopyFiles ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("SetShadowCopyFiles");
mi.Invoke (AppDomain.CurrentDomain, null);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void SetDynamicBase ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("SetDynamicBase");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { String.Empty });
}
// events
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddDomainUnload ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_DomainUnload");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveDomainUnload ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_DomainUnload");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddAssemblyLoad ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_AssemblyLoad");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveAssemblyLoad ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_AssemblyLoad");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddProcessExit ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_ProcessExit");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveProcessExit ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_ProcessExit");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddTypeResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_TypeResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveTypeResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_TypeResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddResourceResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_ResourceResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveResourceResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_ResourceResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddAssemblyResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_AssemblyResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveAssemblyResolve ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_AssemblyResolve");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void AddUnhandledException ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("add_UnhandledException");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlAppDomain = true)]
[ExpectedException (typeof (SecurityException))]
public void RemoveUnhandledException ()
{
MethodInfo mi = typeof (AppDomain).GetMethod ("remove_UnhandledException");
mi.Invoke (AppDomain.CurrentDomain, new object [1] { null });
}
}
}

View File

@@ -0,0 +1,58 @@
//
// AppDomainManagerTest.cs - NUnit Test Cases for AppDomainManager
//
// 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.
//
using System;
using System.Security;
using NUnit.Framework;
namespace MonoTests.System {
[TestFixture]
public class AppDomainManagerTest {
class ContreteSecurityState : SecurityState {
public override void EnsureState ()
{
throw new NotImplementedException ();
}
}
[Test]
public void CheckSecuritySettings ()
{
AppDomainManager adm = new AppDomainManager ();
Assert.IsFalse (adm.CheckSecuritySettings (null), "null");
ContreteSecurityState ss = new ContreteSecurityState ();
Assert.IsFalse (adm.CheckSecuritySettings (ss), "ContreteSecurityState");
}
}
}

View File

@@ -0,0 +1,223 @@
//
// AppDomainSetupTest.cs - NUnit Test Cases for the System.AppDomainSetup class
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.IO;
namespace MonoTests.System
{
[TestFixture]
public class AppDomainSetupTest {
static readonly string tmpPath = Path.GetTempPath ();
static readonly string curDir = Directory.GetCurrentDirectory ();
private bool RunningOnWindows {
get {
int os = (int)Environment.OSVersion.Platform;
return (os != 4);
}
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ConfigurationFile_Relative_ApplicationBase ()
{
string fileName = "blar.config";
AppDomainSetup setup = new AppDomainSetup();
string dir = "app_base";
setup.ApplicationBase = dir;
setup.ConfigurationFile = fileName;
string baseDir = Path.GetFullPath(dir);
string configFile = Path.Combine(baseDir, fileName);
Assert.AreEqual(configFile, setup.ConfigurationFile, "Check relative to ApplicationBase");
}
[Test]
public void ConfigurationFile_Null ()
{
AppDomainSetup setup = new AppDomainSetup();
Assert.IsNull(setup.ConfigurationFile);
}
[Test]
[ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
[Category ("TargetJvmNotWorking")]
public void ConfigurationFile_Relative_NoApplicationBase ()
{
AppDomainSetup setup = new AppDomainSetup();
setup.ConfigurationFile = "blar.config";
string configFile = setup.ConfigurationFile;
if (configFile == null) {
// avoid compiler warning
}
}
[Test]
public void ConfigurationFile_Absolute_NoApplicationBase ()
{
AppDomainSetup setup = new AppDomainSetup();
string configFile = Path.GetFullPath("blar.config");
setup.ConfigurationFile = configFile;
Assert.AreEqual(configFile, setup.ConfigurationFile);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase1 ()
{
string expected_path = tmpPath.Replace(@"\", @"/");
AppDomainSetup setup = new AppDomainSetup ();
string fileUri = "file://" + expected_path;
setup.ApplicationBase = fileUri;
// with MS 1.1 SP1 the expected_path starts with "//" but this make
// sense only under Windows (i.e. reversed \\ for local files)
if (RunningOnWindows)
expected_path = "//" + expected_path;
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual (expected_path, setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
if (!RunningOnWindows)
throw;
}
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase2 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = curDir;
Assert.AreEqual (curDir, setup.ApplicationBase);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase3 ()
{
AppDomainSetup setup = new AppDomainSetup ();
string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
setup.ApplicationBase = "lalala";
Assert.AreEqual (expected, setup.ApplicationBase);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase4 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "lala:la";
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
// (same exceptions as Path.GetFullPath)
if (!RunningOnWindows)
throw;
}
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase5 ()
{
// This is failing because of (probably) a windows-ism, so don't worry
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "file:///lala:la";
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual ("/lala:la", setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
// (same exceptions as Path.GetFullPath)
if (!RunningOnWindows)
throw;
}
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase6 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "la?lala";
// paths containing "?" are *always* bad on Windows
// but are legal for linux so we return a full path
if (RunningOnWindows) {
try {
// ArgumentException is throw when getting
// (and not setting) the ApplicationBase property
Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Unexpected exception: " + e.ToString ());
}
} else {
Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
}
}
[Test]
#if MOBILE
[Category ("NotWorking")]
#endif
public void AppDomainInitializer1 ()
{
AppDomainSetup s = new AppDomainSetup ();
s.AppDomainInitializer = AppDomainInitialized1;
s.AppDomainInitializerArguments = new string [] {"A", "B"};
AppDomain domain = AppDomain.CreateDomain ("MyDomain", null, s);
object data = domain.GetData ("Initialized");
Assert.IsNotNull (data);
Assert.IsTrue ((bool) data);
}
static void AppDomainInitialized1 (string [] args)
{
bool initialized = true;
initialized &= args [0] == "A";
initialized &= args [1] == "B";
initialized &= AppDomain.CurrentDomain.FriendlyName == "MyDomain";
AppDomain.CurrentDomain.SetData ("Initialized", initialized);
}
public void InstanceInitializer (string [] args)
{
}
[Test]
#if MOBILE
[Category ("NotWorking")]
#else
[ExpectedException (typeof (ArgumentException))]
#endif
public void AppDomainInitializerNonStaticMethod ()
{
AppDomainSetup s = new AppDomainSetup ();
s.AppDomainInitializer = InstanceInitializer;
AppDomain.CreateDomain ("MyDomain", null, s);
}
}
}

View File

@@ -0,0 +1 @@
8772d7afdea04e8771c54266715144cacfffa015

View File

@@ -0,0 +1,165 @@
//
// ApplicationIdTest.cs - NUnit Test Cases for ApplicationId
//
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
// Copyright (C) 2004 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 NUnit.Framework;
using System;
namespace MonoTests.System {
[TestFixture]
public class ApplicationIdTest {
static byte[] defaultPublicKeyToken = new byte [0];
static string defaultName = "name";
static Version defaultVersion = new Version (1, 0, 0, 0);
static string defaultProc = "proc";
static string defaultCulture = "culture";
[Test]
public void ApplicationId ()
{
ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
Assert.IsNotNull (id, "ApplicationId");
// wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
Assert.AreEqual (defaultName, id.Name, "Name");
Assert.AreEqual (defaultVersion, id.Version, "Version");
Assert.AreEqual (defaultProc, id.ProcessorArchitecture, "ProcessorArchitecture");
Assert.AreEqual (defaultCulture, id.Culture, "Culture");
Assert.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id.ToString (), "ToString");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationId_PublicKeyTokenNull ()
{
new ApplicationId (null, defaultName, defaultVersion, defaultProc, defaultCulture);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationId_NameNull ()
{
new ApplicationId (defaultPublicKeyToken, null, defaultVersion, defaultProc, defaultCulture);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationId_VersionNull ()
{
new ApplicationId (defaultPublicKeyToken, defaultName, null, defaultProc, defaultCulture);
}
[Test]
public void ApplicationId_ProcessorArchitectureNull ()
{
ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, null, defaultCulture);
// wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
Assert.AreEqual (defaultName, id.Name, "Name");
Assert.AreEqual (defaultVersion, id.Version, "Version");
Assert.IsNull (id.ProcessorArchitecture, "ProcessorArchitecture");
Assert.AreEqual (defaultCulture, id.Culture, "Culture");
Assert.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\"", id.ToString (), "ToString");
}
[Test]
public void ApplicationId_CultureNull ()
{
ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, null);
// wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
Assert.AreEqual (defaultName, id.Name, "Name");
Assert.AreEqual (defaultVersion, id.Version, "Version");
Assert.AreEqual (defaultProc, id.ProcessorArchitecture, "ProcessorArchitecture");
Assert.IsNull (id.Culture, "Culture");
Assert.AreEqual ("name, version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id.ToString (), "ToString");
}
[Test]
public void PublicKeyToken ()
{
byte[] token = new byte [1];
ApplicationId id = new ApplicationId (token, defaultName, defaultVersion, null, null);
token = id.PublicKeyToken;
Assert.AreEqual (0, token [0], "PublicKeyToken");
token [0] = 1;
Assert.AreEqual (1, token [0], "token");
token = id.PublicKeyToken;
Assert.AreEqual (0, token [0], "PublicKeyToken");
}
[Test]
public void Copy ()
{
ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
ApplicationId id2 = id1.Copy ();
Assert.IsTrue (id1.Equals (id2), "Equals-1");
Assert.IsTrue (id2.Equals (id1), "Equals-2");
Assert.IsFalse (Object.ReferenceEquals (id1, id2), "ReferenceEquals");
}
[Test]
public void Equals ()
{
ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
ApplicationId id2 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
Assert.IsTrue (id1.Equals (id2), "Equals-1");
Assert.IsTrue (id2.Equals (id1), "Equals-2");
Assert.AreEqual (id1.GetHashCode (), id2.GetHashCode (), "GetHashCode");
}
[Test]
public void Equals_Subset ()
{
ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
ApplicationId id2 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, null, defaultCulture);
Assert.IsFalse (id1.Equals (id2), "Equals-A1");
Assert.IsFalse (id2.Equals (id1), "Equals-A2");
// would have expected IsFalse
Assert.IsTrue (id1.GetHashCode () == id2.GetHashCode (), "GetHashCode-A");
ApplicationId id3 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, null);
Assert.IsFalse (id1.Equals (id3), "Equals-B1");
Assert.IsFalse (id3.Equals (id1), "Equals-B2");
// would have expected IsFalse
Assert.IsTrue (id1.GetHashCode () == id3.GetHashCode (), "GetHashCode-B");
}
[Test]
public void ToString_ ()
{
byte[] token = new byte [256];
for (int i=0; i < token.Length; i++)
token [i] = (byte)i;
ApplicationId id = new ApplicationId (token, "Mono", new Version (1, 2), "Multiple", "neutral");
Assert.AreEqual ("Mono, culture=\"neutral\", version=\"1.2\", publicKeyToken=\"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\", processorArchitecture =\"Multiple\"", id.ToString (), "ToString");
}
}
}
#endif

View File

@@ -0,0 +1,66 @@
//
// ApplicationIdentityTest.cs - NUnit Test Cases for ApplicationIdentity
//
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
// Copyright (C) 2004 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 NUnit.Framework;
using System;
namespace MonoTests.System {
[TestFixture]
public class ApplicationIdentityTest {
[Test]
public void ApplicationIdentity ()
{
ApplicationIdentity appid = new ApplicationIdentity ("Mono");
Assert.IsNull (appid.CodeBase, "CodeBase");
Assert.AreEqual ("Mono, Culture=neutral", appid.FullName);
Assert.AreEqual ("Mono, Culture=neutral", appid.ToString ());
}
[Test]
public void ApplicationIdentity_WithCulture ()
{
ApplicationIdentity appid = new ApplicationIdentity ("Mono, Culture=fr-ca");
Assert.IsNull (appid.CodeBase, "CodeBase");
Assert.AreEqual ("Mono, Culture=fr-ca", appid.FullName);
Assert.AreEqual ("Mono, Culture=fr-ca", appid.ToString ());
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationIdentity_Null ()
{
new ApplicationIdentity (null);
}
}
}
#endif

View File

@@ -0,0 +1,109 @@
//
// ArgumentExceptionTest.cs - Unit tests for
// System.ArgumentException
//
// Author:
// Gert Driesen <drieseng@users.sourceforge.net>
//
// Copyright (C) 2007 Gert Driesen
//
// 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 System;
using NUnit.Framework;
namespace MonoTests.System
{
[TestFixture]
public class ArgumentExceptionTest
{
[Test] // ctor ()
public void Constructor0 ()
{
// Value does not fall within the expected range
ArgumentException ae = new ArgumentException ();
Assert.IsNull (ae.InnerException, "#1");
Assert.IsNotNull (ae.Message, "#2");
Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#3");
Assert.IsFalse (ae.Message.IndexOf (Environment.NewLine) != -1, "#4");
Assert.IsNull (ae.ParamName, "#5");
}
[Test] // ctor (string)
public void Constructor1 ()
{
ArgumentException ae;
ae = new ArgumentException ((string) null);
Assert.IsNull (ae.InnerException, "#A1");
Assert.IsNotNull (ae.Message, "#A2");
Assert.IsTrue (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#A3");
Assert.IsFalse (ae.Message.IndexOf (Environment.NewLine) != -1, "#A4");
Assert.IsNull (ae.ParamName, "#A5");
ae = new ArgumentException ("MSG");
Assert.IsNull (ae.InnerException, "#B1");
Assert.IsNotNull (ae.Message, "#B2");
Assert.AreEqual ("MSG", ae.Message, "#B3");
Assert.IsNull (ae.ParamName, "#B4");
ae = new ArgumentException (string.Empty);
Assert.IsNull (ae.InnerException, "#C1");
Assert.IsNotNull (ae.Message, "#C2");
Assert.AreEqual (string.Empty, ae.Message, "#C3");
Assert.IsNull (ae.ParamName, "#C4");
}
[Test] // ctor (string, string)
public void Constructor4 ()
{
ArgumentException ae = new ArgumentException ("MSG", (string) null);
Assert.IsNotNull (ae.Message, "#A1");
Assert.AreEqual ("MSG", ae.Message, "#A2");
Assert.IsNull (ae.ParamName, "#A3");
ae = new ArgumentException ("MSG", string.Empty);
Assert.IsNotNull (ae.Message, "#B1");
Assert.AreEqual ("MSG", ae.Message, "#B2");
Assert.IsNotNull (ae.ParamName, "#B3");
Assert.AreEqual (string.Empty, ae.ParamName, "#B4");
ae = new ArgumentException ("MSG", "PARAM");
Assert.IsNotNull (ae.Message, "#C1");
Assert.IsTrue (ae.Message.StartsWith ("MSG"), "#C2");
Assert.IsTrue (ae.Message.IndexOf (Environment.NewLine) != -1, "#C3");
Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#C4");
Assert.IsTrue (ae.Message.IndexOf ("PARAM") != -1, "#C5");
Assert.IsNotNull (ae.ParamName, "#C6");
Assert.AreEqual ("PARAM", ae.ParamName, "#C7");
ae = new ArgumentException ("MSG", " \t ");
Assert.IsNotNull (ae.Message, "#D1");
Assert.IsTrue (ae.Message.StartsWith ("MSG"), "#D2");
Assert.IsTrue (ae.Message.IndexOf (Environment.NewLine) != -1, "#D3");
Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#D4");
Assert.IsTrue (ae.Message.IndexOf (" \t ") != -1, "#D5");
Assert.IsNotNull (ae.ParamName, "#D6");
Assert.AreEqual (" \t ", ae.ParamName, "#D7");
}
}
}

View File

@@ -0,0 +1,283 @@
// ArraySegmentTest.cs - NUnit Test Cases for the System.ArraySegment class
//
// Ankit Jain <jankit@novell.com>
// Raja R Harinath <rharinath@novell.com>
// Jensen Somers <jensen.somers@gmail.com>
// Marek Safar (marek.safar@gmail.com)
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
// Copyright (C) 2012 Xamarin, Inc (http://www.xamarin.com)
//
using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace MonoTests.System
{
[TestFixture]
public class ArraySegmentTest
{
[Test]
public void CtorTest1 ()
{
byte[] b_arr = new byte[4096];
Array arr;
ArraySegment<byte> seg = new ArraySegment<byte> (b_arr, 0, b_arr.Length);
Assert.AreEqual (seg.Count, b_arr.Length, "#1");
Assert.AreEqual (seg.Offset, 0, "#2");
arr = seg.Array;
Assert.AreEqual (arr.Length, 4096, "#5");
seg = new ArraySegment<byte> (b_arr, 100, b_arr.Length - 100);
Assert.AreEqual (seg.Count, b_arr.Length - 100, "#3");
Assert.AreEqual (seg.Offset, 100, "#4");
arr = seg.Array;
Assert.AreEqual (arr.Length, 4096, "#5");
}
[Test]
public void CtorTest2 ()
{
byte[] b_arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (b_arr);
Assert.AreEqual (seg.Count, b_arr.Length, "#6");
Assert.AreEqual (seg.Offset, 0, "#7");
Array arr = seg.Array;
Assert.AreEqual (arr.Length, 4096, "#8");
}
[Test]
public void CtorTest3 ()
{
EmptyArraySegTest (0);
EmptyArraySegTest (10);
}
private void EmptyArraySegTest (int len)
{
byte[] b_arr = new byte[len];
ArraySegment<byte> seg = new ArraySegment<byte> (b_arr, 0, b_arr.Length);
Assert.AreEqual (seg.Count, b_arr.Length, "#1 [array len {0}] ", len);
Assert.AreEqual (seg.Offset, 0, "#2 [array len {0}] ", len);
Array arr = seg.Array;
Assert.AreEqual (arr.Length, len, "#3 [array len {0}] ", len);
seg = new ArraySegment<byte> (b_arr, b_arr.Length, 0);
Assert.AreEqual (seg.Count, 0, "#4 [array len {0}] ", len);
Assert.AreEqual (seg.Offset, b_arr.Length, "#5 [array len {0}] ", len);
arr = seg.Array;
Assert.AreEqual (arr.Length, len, "#6 [array len {0}] ", len);
seg = new ArraySegment<byte> (b_arr);
Assert.AreEqual (seg.Count, b_arr.Length, "#7 [array len {0}] ", len);
Assert.AreEqual (seg.Offset, 0, "#8 [array len {0}] ", len);
arr = seg.Array;
Assert.AreEqual (arr.Length, len, "#9 [array len {0}] ", len);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CtorErrorTest ()
{
byte[] arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (arr, 1, arr.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CtorErrorTest2 ()
{
byte[] arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (arr, 0, arr.Length + 2);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CtorErrorTest3 ()
{
byte[] arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (arr, -1, arr.Length);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CtorErrorTest4 ()
{
byte[] arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (arr, 2, -1);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CtorErrorTest5 ()
{
byte[] arr = new byte[4096];
ArraySegment<byte> seg = new ArraySegment<byte> (arr, 0, arr.Length + 2);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNullTest1 ()
{
ArraySegment<byte> seg = new ArraySegment<byte> (null, 0, 1);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNullTest2 ()
{
ArraySegment<byte> seg = new ArraySegment<byte> (null);
}
[Test]
public void TestArraySegmentEqual ()
{
string[] myArr_1 = { "The", "good" };
string[] myArr_2 = { "The", "good" };
ArraySegment<string> myArrSeg_1 = new ArraySegment<string> (myArr_1);
ArraySegment<string> myArrSeg_2 = new ArraySegment<string> (myArr_2);
// Should return true.
Assert.AreEqual (myArrSeg_1.Equals (myArrSeg_1), true);
// Should return false. Allthough the strings are the same.
Assert.AreEqual (myArrSeg_1.Equals (myArrSeg_2), false);
Assert.AreEqual (myArrSeg_1 == myArrSeg_2, false);
// Should return true.
Assert.AreEqual (myArrSeg_1 != myArrSeg_2, true);
}
#if NET_4_5
[Test]
public void IList_NotSupported ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
try {
s.Add (1);
Assert.Fail ("#1");
} catch (NotSupportedException) {
}
try {
s.Clear ();
Assert.Fail ("#2");
} catch (NotSupportedException) {
}
try {
s.Remove (3);
Assert.Fail ("#3");
} catch (NotSupportedException) {
}
try {
s.RemoveAt (3);
Assert.Fail ("#4");
} catch (NotSupportedException) {
}
try {
s.Insert (2, 3);
Assert.Fail ("#5");
} catch (NotSupportedException) {
}
}
[Test]
public void IList_GetEnumerator ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
long total = 0;
int count = 0;
foreach (var i in s) {
count++;
total += i;
}
Assert.AreEqual (3, count, "#1");
Assert.AreEqual (12, total, "#2");
}
[Test]
public void IList_IndexOf ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
Assert.AreEqual (-1, s.IndexOf (2), "#1");
Assert.AreEqual (1, s.IndexOf (4), "#2");
}
[Test]
public void IList_Contains ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
Assert.IsFalse (s.Contains (2), "#1");
Assert.IsTrue (s.Contains (4), "#2");
}
[Test]
public void IList_CopyTo ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
long[] target = new long[s.Count];
s.CopyTo (target, 0);
Assert.AreEqual (3, target[0], "#1");
Assert.AreEqual (4, target[1], "#2");
}
[Test]
public void IList_Indexer ()
{
var array = new long[] { 1, 2, 3, 4, 5, 6, -10 };
IList<long> s = new ArraySegment<long> (array, 2, 3);
Assert.AreEqual (3, s[0], "#1");
Assert.AreEqual (4, s[1], "#2");
// LAMESPEC: I have not idea why is this allowed on ReadOnly array
Assert.IsTrue (s.IsReadOnly, "#3");
s[1] = -3;
Assert.AreEqual (-3, s[1], "#2a");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void IList_IndexerErrorTest1 ()
{
byte[] arr = new byte[4];
IList<byte> seg = new ArraySegment<byte> (arr, 1, 2);
seg[-1] = 3;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void IList_IndexerErrorTest2 ()
{
byte[] arr = new byte[4];
IList<byte> seg = new ArraySegment<byte> (arr);
seg[4] = 3;
}
#endif
}
}

View File

@@ -0,0 +1,408 @@
//
// MonoTests.System.ArraySortArgChecks
//
// Authors:
// Juraj Skripsky (js@hotfeet.ch)
//
// Copyright (C) 2009 Juraj Skripsky (js@hotfeet.ch)
//
// 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.Collections;
#if NET_2_0
using System.Collections.Generic;
#endif
namespace MonoTests.System {
class SomeIncomparable {}
class SomeComparable : IComparable {
int IComparable.CompareTo (object other) {
return 0;
}
}
[TestFixture]
public class ArraySortArgChecks {
[Test]
public void Check_ArgumentNullException() {
try {
Array.Sort (null);
Assert.Fail ("#1");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, (Array)null);
Assert.Fail ("#2");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, (IComparer)null);
Assert.Fail ("#3");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, 0, 0);
Assert.Fail ("#4");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, null, null);
Assert.Fail ("#5");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, null, 0, 0);
Assert.Fail ("#6");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, 0, 0, null);
Assert.Fail ("#7");
} catch (ArgumentNullException) {}
try {
Array.Sort (null, null, 0, 0, null);
Assert.Fail ("#8");
} catch (ArgumentNullException) {}
#if NET_2_0
try {
Array.Sort<object> (null);
Assert.Fail ("#9");
} catch (ArgumentNullException) {}
try {
Array.Sort<object, object> (null, null);
Assert.Fail ("#10");
} catch (ArgumentNullException) {}
try {
Array.Sort<object> (null, (IComparer<object>)null);
Assert.Fail ("#11");
} catch (ArgumentNullException) {}
try {
Array.Sort<object, object> (null, null, null);
Assert.Fail ("#12");
} catch (ArgumentNullException) {}
try {
Array.Sort<object> (null, 0, 0);
Assert.Fail ("#13");
} catch (ArgumentNullException) {}
try {
Array.Sort<object, object> (null, null, 0, 0);
Assert.Fail ("#14");
} catch (ArgumentNullException) {}
try {
Array.Sort<object> (null, 0, 0, null);
Assert.Fail ("#15");
} catch (ArgumentNullException) {}
try {
Array.Sort<object, object> (null, null, 0, 0, null);
Assert.Fail ("#16");
} catch (ArgumentNullException) {}
try {
Array.Sort<object> (null, new Comparison<object>(ObjComparison));
Assert.Fail ("#17");
} catch (ArgumentNullException) {}
#endif
}
public static int ObjComparison (object o1, object o2) {
return 0;
}
[Test]
public void Check_ArgumentException() {
object[] arr = new object[] {1, 2, 3, 4, 5};
try {
Array.Sort (arr, 1, 5);
Assert.Fail ("#1");
} catch (ArgumentException) {}
try {
Array.Sort (arr, null, 1, 5);
Assert.Fail ("#2");
} catch (ArgumentException) {}
try {
Array.Sort (arr, 1, 5, null);
Assert.Fail ("#3");
} catch (ArgumentException) {}
try {
Array.Sort (arr, null, 1, 5, null);
Assert.Fail ("#4");
} catch (ArgumentException) {}
#if NET_2_0
try {
Array.Sort<object> (arr, 1, 5);
Assert.Fail ("#5");
} catch (ArgumentException) {}
try {
Array.Sort<object, object> (arr, null, 1, 5);
Assert.Fail ("#6");
} catch (ArgumentException) {}
try {
Array.Sort<object> (arr, 1, 5, null);
Assert.Fail ("#7");
} catch (ArgumentException) {}
try {
Array.Sort<object, object> (arr, null, 1, 5, null);
Assert.Fail ("#8");
} catch (ArgumentException) {}
#endif
}
[Test]
public void Check_ArgumentOurOfRangeException() {
object[] arr = new object[] {1, 2, 3, 4, 5};
try {
Array.Sort (arr, -1, 1);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, null, -1, 1);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, -1, 1, null);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, null, -1, 1, null);
Assert.Fail ("#4");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, 0, -1);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, null, 0, -1);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, 0, -1, null);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort (arr, null, 0, -1, null);
Assert.Fail ("#4");
} catch (ArgumentOutOfRangeException) {}
#if NET_2_0
try {
Array.Sort<object> (arr, -1, 1);
Assert.Fail ("#5");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object, object> (arr, null, -1, 1);
Assert.Fail ("#6");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object> (arr, -1, 1, null);
Assert.Fail ("#7");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object, object> (arr, null, -1, 1, null);
Assert.Fail ("#8");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object> (arr, 0, -1);
Assert.Fail ("#5");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object, object> (arr, null, 0, -1);
Assert.Fail ("#6");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object> (arr, 0, -1, null);
Assert.Fail ("#7");
} catch (ArgumentOutOfRangeException) {}
try {
Array.Sort<object, object> (arr, null, 0, -1, null);
Assert.Fail ("#8");
} catch (ArgumentOutOfRangeException) {}
#endif
}
[Test]
public void Check_RankException() {
object[,] arr = new object[2,2];
try {
Array.Sort (arr);
Assert.Fail ("#1");
} catch (RankException) {}
try {
Array.Sort (arr, (Array)null);
Assert.Fail ("#2");
} catch (RankException) {}
try {
Array.Sort (arr, (IComparer)null);
Assert.Fail ("#3");
} catch (RankException) {}
try {
Array.Sort (arr, 0, 0);
Assert.Fail ("#4");
} catch (RankException) {}
try {
Array.Sort (arr, null, null);
Assert.Fail ("#5");
} catch (RankException) {}
try {
Array.Sort (arr, null, 0, 0);
Assert.Fail ("#6");
} catch (RankException) {}
try {
Array.Sort (arr, 0, 0, null);
Assert.Fail ("#7");
} catch (RankException) {}
try {
Array.Sort (arr, null, 0, 0, null);
Assert.Fail ("#8");
} catch (RankException) {}
}
[Test]
public void Check_InvalidOperationException() {
object[] arr = new object[] {new SomeComparable (), new SomeIncomparable (), new SomeComparable ()};
try {
Array.Sort (arr);
Assert.Fail ("#1");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, (Array)null);
Assert.Fail ("#2");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, (IComparer)null);
Assert.Fail ("#3");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, 0, 3);
Assert.Fail ("#4");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, null, null);
Assert.Fail ("#5");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, null, 0, 3);
Assert.Fail ("#6");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, 0, 3, null);
Assert.Fail ("#7");
} catch (InvalidOperationException) {}
try {
Array.Sort (arr, null, 0, 3, null);
Assert.Fail ("#8");
} catch (InvalidOperationException) {}
#if NET_2_0
try {
Array.Sort<object> (arr);
Assert.Fail ("#9");
} catch (InvalidOperationException) {}
try {
Array.Sort<object, object> (arr, null);
Assert.Fail ("#10");
} catch (InvalidOperationException) {}
try {
Array.Sort<object> (arr, (IComparer<object>)null);
Assert.Fail ("#11");
} catch (InvalidOperationException) {}
try {
Array.Sort<object, object> (arr, null, null);
Assert.Fail ("#12");
} catch (InvalidOperationException) {}
try {
Array.Sort<object> (arr, 0, 3);
Assert.Fail ("#13");
} catch (InvalidOperationException) {}
try {
Array.Sort<object, object> (arr, null, 0, 3);
Assert.Fail ("#14");
} catch (InvalidOperationException) {}
try {
Array.Sort<object> (arr, 0, 3, null);
Assert.Fail ("#15");
} catch (InvalidOperationException) {}
try {
Array.Sort<object, object> (arr, null, 0, 3, null);
Assert.Fail ("#16");
} catch (InvalidOperationException) {}
#endif
}
}
}

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,172 @@
//
// BadImageFormatExceptionCas.cs -
// CAS unit tests for System.BadImageFormatException
//
// 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.Security;
using System.Security.Permissions;
namespace MonoCasTests.System {
[TestFixture]
[Category ("CAS")]
public class BadImageFormatExceptionCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
public void NoRestriction ()
{
BadImageFormatException fle = new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
Assert.IsNotNull (fle.ToString (), "ToString");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void FullRestriction ()
{
BadImageFormatException fle = new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
// ToString doesn't work in this case and strangely throws a BadImageFormatException
Assert.IsNotNull (fle.ToString (), "ToString");
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetFusionLog_Pass ()
{
BadImageFormatException fle = new BadImageFormatException ("message", "filename");
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
// note: ToString doesn't work in this case
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFusionLog_Fail_ControlEvidence ()
{
BadImageFormatException fle = new BadImageFormatException ();
Assert.IsNull (fle.FusionLog, "FusionLog");
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFusionLog_Fail_ControlPolicy ()
{
BadImageFormatException fle = new BadImageFormatException ();
Assert.IsNull (fle.FusionLog, "FusionLog");
// we don't have to throw the exception to have FusionLog
// informations restricted (even if there could be no
// data in this state).
}
[Test]
public void Throw_NoRestriction ()
{
try {
throw new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
}
catch (BadImageFormatException fle) {
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
Assert.IsNotNull (fle.ToString (), "ToString");
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Throw_FullRestriction ()
{
try {
throw new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
}
catch (BadImageFormatException fle) {
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
// both FusionLog and ToString doesn't work in this case
// but strangely we get a BadImageFormatException
Assert.IsNull (fle.FusionLog, "FusionLog");
Assert.IsNotNull (fle.ToString (), "ToString");
}
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void Throw_GetFusionLog_Fail_ControlEvidence ()
{
try {
throw new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
}
catch (BadImageFormatException fle) {
Assert.IsNull (fle.FusionLog, "FusionLog");
}
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void Throw_GetFusionLog_Fail_ControlPolicy ()
{
try {
throw new BadImageFormatException ("message", "filename",
new BadImageFormatException ("inner message", "inner filename"));
}
catch (BadImageFormatException fle) {
Assert.IsNull (fle.FusionLog, "FusionLog");
}
}
}
}

View File

@@ -0,0 +1,421 @@
//
// BadImageFormatExceptionTest.cs - Unit tests for
// System.BadImageFormatException
//
// Author:
// Gert Driesen <drieseng@users.sourceforge.net>
//
// Copyright (C) 2006 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 System;
using NUnit.Framework;
namespace MonoTests.System
{
[TestFixture]
public class BadImageFormatExceptionTest
{
[Test]
public void Constructor1 ()
{
BadImageFormatException bif = new BadImageFormatException ();
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library (.dll) is invalid
Assert.IsNull (bif.FusionLog, "#5");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName), "#6");
}
[Test]
public void Constructor2 ()
{
BadImageFormatException bif = new BadImageFormatException ("message");
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
Assert.IsNotNull (bif.Message, "#4");
Assert.AreEqual ("message", bif.Message, "#5");
Assert.IsNull (bif.FusionLog, "#6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName + ": message"), "#7");
#else
Assert.AreEqual (bif.GetType ().FullName + ": message",
bif.ToString (), "#7");
#endif // TARGET_JVM
}
[Test]
public void Constructor2_Message_Empty ()
{
BadImageFormatException bif = new BadImageFormatException (string.Empty);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
Assert.IsNotNull (bif.Message, "#4");
Assert.AreEqual (string.Empty, bif.Message, "#5");
Assert.IsNull (bif.FusionLog, "#6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#7");
#else
Assert.AreEqual (bif.GetType ().FullName + ": ",
bif.ToString (), "#7");
#endif // TARGET_JVM
}
[Test]
public void Constructor2_Message_Null ()
{
BadImageFormatException bif = new BadImageFormatException ((string) null);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
#if NET_2_0
Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
#else
Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
#endif
Assert.IsNull (bif.FusionLog, "#5");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#6");
#if NET_2_0
Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#7");
#else
Assert.IsFalse (bif.ToString ().IndexOf ("''") != -1, "#7");
#endif
}
[Test]
public void Constructor3 ()
{
ArithmeticException ame = new ArithmeticException ("something");
BadImageFormatException bif = new BadImageFormatException ("message",
ame);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNotNull (bif.InnerException, "#3");
Assert.AreSame (ame, bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual ("message", bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().IndexOf (ame.GetType ().FullName + ": something") != -1, "#8");
#else
Assert.AreEqual (bif.GetType ().FullName + ": message ---> "
+ ame.GetType ().FullName + ": something", bif.ToString (), "#8");
#endif // TARGET_JVM
}
[Test]
public void Constructor3_Message_Empty ()
{
ArithmeticException ame = new ArithmeticException ("something");
BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNotNull (bif.InnerException, "#3");
Assert.AreSame (ame, bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual (string.Empty, bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().IndexOf (ame.GetType ().FullName + ": something") != -1, "#8");
#else
Assert.AreEqual (bif.GetType ().FullName + ": ---> "
+ ame.GetType ().FullName + ": something", bif.ToString (), "#8");
#endif // TARGET_JVM
}
[Test]
public void Constructor3_Message_Null ()
{
ArithmeticException ame = new ArithmeticException ("something");
BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNotNull (bif.InnerException, "#3");
Assert.AreSame (ame, bif.InnerException, "#4");
#if NET_2_0
Assert.IsNotNull (bif.Message, "#5"); // Could not load file or assembly '' ...
Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#6");
#else
Assert.IsNotNull (bif.Message, "#5"); // Format of the executable (.exe) or library ...
Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#6");
#endif
Assert.IsNull (bif.FusionLog, "#7");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#8");
Assert.IsTrue (bif.ToString ().IndexOf ("---> " + ame.GetType ().FullName) != -1, "#9");
#if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#10");
#endif // TARGET_JVM
}
[Test]
public void Constructor3_InnerException_Null ()
{
BadImageFormatException bif = new BadImageFormatException ("message",
(Exception) null);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
Assert.IsNotNull (bif.Message, "#4");
Assert.AreEqual ("message", bif.Message, "#5");
Assert.IsNull (bif.FusionLog, "#6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#7");
#else
Assert.AreEqual (bif.GetType ().FullName + ": message",
bif.ToString (), "#7");
#endif // TARGET_JVM
}
[Test]
public void Constructor4 ()
{
BadImageFormatException bif = new BadImageFormatException ("message",
"file.txt");
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNotNull (bif.FileName, "#2");
Assert.AreEqual ("file.txt", bif.FileName, "#3");
Assert.IsNull (bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual ("message", bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
+ ": message" + Environment.NewLine), "#8");
#if NET_2_0
Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
#else
Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
#endif
}
[Test]
public void Constructor4_FileName_Empty ()
{
BadImageFormatException bif = new BadImageFormatException ("message",
string.Empty);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNotNull (bif.FileName, "#2");
Assert.AreEqual (string.Empty, bif.FileName, "#3");
Assert.IsNull (bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual ("message", bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#8");
#else
Assert.AreEqual (bif.GetType ().FullName + ": message",
bif.ToString (), "#8");
#endif // TARGET_JVM
}
[Test]
public void Constructor4_FileName_Null ()
{
BadImageFormatException bif = new BadImageFormatException ("message",
(string) null);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#A1");
#endif
Assert.IsNull (bif.FileName, "#A2");
Assert.IsNull (bif.InnerException, "#A3");
Assert.IsNotNull (bif.Message, "#A4");
Assert.AreEqual ("message", bif.Message, "#A5");
Assert.IsNull (bif.FusionLog, "#A6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#A7");
#else
Assert.AreEqual (bif.GetType ().FullName + ": message",
bif.ToString (), "#A7");
#endif // TARGET_JVM
bif = new BadImageFormatException (string.Empty, (string) null);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#B1");
#endif
Assert.IsNull (bif.FileName, "#B2");
Assert.IsNull (bif.InnerException, "#B3");
Assert.IsNotNull (bif.Message, "#B4");
Assert.AreEqual (string.Empty, bif.Message, "#B5");
Assert.IsNull (bif.FusionLog, "#B6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#B7");
#else
Assert.AreEqual (bif.GetType ().FullName + ": ",
bif.ToString (), "#B7");
#endif // TARGET_JVM
}
[Test]
public void Constructor4_FileNameAndMessage_Empty ()
{
BadImageFormatException bif = new BadImageFormatException (string.Empty,
string.Empty);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNotNull (bif.FileName, "#2");
Assert.AreEqual (string.Empty, bif.FileName, "#3");
Assert.IsNull (bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual (string.Empty, bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#8");
#else
Assert.AreEqual (bif.GetType ().FullName + ": ", bif.ToString (), "#8");
#endif // TARGET_JVM
}
[Test]
public void Constructor4_FileNameAndMessage_Null ()
{
BadImageFormatException bif = new BadImageFormatException ((string) null,
(string) null);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNull (bif.FileName, "#2");
Assert.IsNull (bif.InnerException, "#3");
#if NET_2_0
Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
#else
Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
#endif
Assert.IsNull (bif.FusionLog, "#5");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
+ ": "), "#6");
#if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
#endif // TARGET_JVM
}
[Test]
public void Constructor4_Message_Empty ()
{
BadImageFormatException bif = null;
bif = new BadImageFormatException (string.Empty, "file.txt");
#if NET_2_0
Assert.IsNotNull (bif.Data, "#1");
#endif
Assert.IsNotNull (bif.FileName, "#2");
Assert.AreEqual ("file.txt", bif.FileName, "#3");
Assert.IsNull (bif.InnerException, "#4");
Assert.IsNotNull (bif.Message, "#5");
Assert.AreEqual (string.Empty, bif.Message, "#6");
Assert.IsNull (bif.FusionLog, "#7");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
+ ": " + Environment.NewLine), "#8");
#if NET_2_0
Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
#else
Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
#endif
}
[Test]
public void Constructor4_Message_Null ()
{
BadImageFormatException bif = null;
bif = new BadImageFormatException ((string) null, "file.txt");
#if NET_2_0
Assert.IsNotNull (bif.Data, "#A1");
#endif
Assert.IsNotNull (bif.FileName, "#A2");
Assert.AreEqual ("file.txt", bif.FileName, "#A3");
Assert.IsNull (bif.InnerException, "#A4");
Assert.IsNotNull (bif.Message, "#A5");
Assert.IsNull (bif.FusionLog, "#A6");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
+ ": "), "#A7");
Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
bif = new BadImageFormatException ((string) null, string.Empty);
#if NET_2_0
Assert.IsNotNull (bif.Data, "#B1");
#endif
Assert.IsNotNull (bif.FileName, "#B2");
Assert.AreEqual (string.Empty, bif.FileName, "#B3");
Assert.IsNull (bif.InnerException, "#B4");
// .NET 1.1: The format of the file 'file.txt' is invalid
// .NET 2.0: Could not load file or assembly 'file.txt' or one of its ...
Assert.IsNotNull (bif.Message, "#B5");
Assert.IsNull (bif.FusionLog, "#B6");
Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
+ ": "), "#B7");
#if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
#endif // TARGET_JVM
Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,152 @@
//
// BooleanTest.cs - NUnit Test Cases for the System.Boolean class
//
// Authors
// Bob Doan <bdoan@sicompos.com>
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004 Novell (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Globalization;
namespace MonoTests.System {
[TestFixture]
public class BooleanTest {
[Test]
public void Strings ()
{
Assert.AreEqual("False", Boolean.FalseString, "Wrong False string");
Assert.AreEqual("True", Boolean.TrueString, "Wrong True string");
}
[Test]
public void CompareTo ()
{
Boolean t=true,f=false;
Assert.IsTrue (f.CompareTo(t) < 0, "f.CompareTo(t) < 0");
Assert.IsTrue (f.CompareTo(f) == 0, "f.CompareTo(f)");
Assert.IsTrue (t.CompareTo(t) == 0, "t.CompareTo(t) == 0");
Assert.IsTrue (t.CompareTo(f) > 0, "t.CompareTo(f) > 0");
Assert.IsTrue (t.CompareTo(null) > 0, "t.CompareTo(null) > 0");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (f.CompareTo(t2) < 0, "f.CompareTo(t2) < 0");
Assert.IsTrue (t2.CompareTo(t2) == 0, "t2.CompareTo(t2) == 0");
Assert.IsTrue (t2.CompareTo(f) > 0, "t2.CompareTo(f) > 0");
Assert.IsTrue (t2.CompareTo(null) > 0, "t2.CompareTo(null) > 0");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CompareToInvalidString ()
{
true.CompareTo ("What Ever");
}
[Test]
public void TestEquals ()
{
Boolean t=true, f=false;
string s = "What Ever";
Assert.IsTrue (t.Equals(t), "t.Equals(t)");
Assert.IsTrue (f.Equals(f), "f.Equals(f)");
Assert.IsTrue (!t.Equals(f), "!t.Equals(f)");
Assert.IsTrue (!f.Equals(t), "!f.Equals(t)");
Assert.IsTrue (!t.Equals(null), "!t.Equals(null)");
Assert.IsTrue (!f.Equals(null), "!f.Equals(null)");
Assert.IsTrue (!t.Equals(s), "!t.Equals(s)");
Assert.IsTrue (!f.Equals(s), "!f.Equals(s)");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (t2.Equals(t2), "t2.Equals(t2)");
Assert.IsTrue (t.Equals(t2), "t.Equals(t2)");
Assert.IsTrue (t2.Equals(t), "t2.Equals(t)");
Assert.IsTrue (!f.Equals(t2), "!f.Equals(t2)");
}
#pragma warning disable 1718
[Test]
public void TestEqualOperator ()
{
Boolean t=true, f=false;
Assert.IsTrue (t==t, "t==t");
Assert.IsTrue (f==f, "f==f");
Assert.IsTrue (t!=f, "t!=f");
Assert.IsTrue (f!=t, "f!=t");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (t2==t2, "t2==t2");
Assert.IsTrue (t==t2, "t==t2");
Assert.IsTrue (t2==t, "t2==t");
Assert.IsTrue (f!=t2, "f!=t2");
}
#pragma warning restore 1718
[Test]
public void TestGetHashCode ()
{
Boolean t=true, f=false;
Assert.AreEqual(1, t.GetHashCode(), "GetHashCode True failed");
Assert.AreEqual(0, f.GetHashCode(), "GetHashCode True failed");
}
[Test]
public void TestGetType ()
{
Boolean t=true, f=false;
Assert.AreEqual(true, Object.ReferenceEquals(t.GetType(), f.GetType()), "GetType failed");
}
[Test]
public void GetTypeCode ()
{
Boolean b=true;
Assert.AreEqual(TypeCode.Boolean, b.GetTypeCode(), "GetTypeCode failed");
}
[Test]
public void Parse ()
{
Assert.AreEqual(true, Boolean.Parse("True"), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse(" True"), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse("True "), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse("tRuE"), "Parse True failed");
Assert.AreEqual(false, Boolean.Parse("False"), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse(" False"), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse("False "), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse("fAlSe"), "Parse False failed");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ParseInvalid ()
{
Boolean.Parse ("not-t-or-f");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ParseNull ()
{
Boolean.Parse (null);
}
[Test]
public void TestToString ()
{
Boolean t=true,f=false;
Assert.AreEqual(Boolean.TrueString, t.ToString(), "ToString True Failed");
Assert.AreEqual(Boolean.FalseString, f.ToString(), "ToString False Failed");
}
}
}

View File

@@ -0,0 +1,282 @@
//
// BufferTest.cs - NUnit Test Cases for the Buffer class.
//
// Authors
// Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) Cesar Octavio Lopez Nataren 2002
// Copyright (C) 2004 Novell (http://www.novell.com)
//
using NUnit.Framework;
using System;
namespace MonoTests.System {
[TestFixture]
public class BufferTest {
const int SIZE = 10;
byte [] byteArray = new byte [SIZE]; // 8-bits unsigned integer array
[Test]
public void BlockCopy ()
{
int SizeOfInt32 = 4;
int [] myArray1 = new int [5] {1, 2, 3, 4, 5};
int [] myArray2 = new int [10] { 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 };
Buffer.BlockCopy (myArray1, 0, myArray2, 0, SizeOfInt32 * myArray1.Length);
for (int i = 0; i < myArray1.Length; i++)
Assert.AreEqual (i + 1, myArray2 [i], "TestBlockCopy Error at i=" + i);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void BlockCopy_NullSource ()
{
byte[] dest = new byte [8];
Buffer.BlockCopy (null, 0, dest, 0, dest.Length);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void BlockCopy_NullDest ()
{
byte[] src = new byte [8];
Buffer.BlockCopy (src, 0, null, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_ObjectSource ()
{
object[] src = new object [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_ObjectDest ()
{
byte[] src = new byte [8];
object[] dest = new object [8];
Buffer.BlockCopy (src, 0, dest, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_SourceTooShort ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 4, dest, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_DestTooShort ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, 4, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void BlockCopy_SourceOffsetNegative ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, -1, dest, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void BlockCopy_DestOffsetNegative ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, -1, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_SourceOffsetOverflow ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, Int32.MaxValue, dest, 0, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_DestOffsetOverflow ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, Int32.MaxValue, src.Length);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void BlockCopy_LengthNegative ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, 0, -1);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void BlockCopy_LengthOverflow ()
{
byte[] src = new byte [8];
byte[] dest = new byte [8];
Buffer.BlockCopy (src, 0, dest, 0, Int32.MaxValue);
}
[Test]
public void ByteLength ()
{
int numBytes;
float [] floatArray = new float [10];
float [,] floatArray2 = new float [10,10];
float [,,] floatArray3 = new float [10,10,10];
float [,,,] floatArray4 = new float [10,0,10,10];
float [,,,] floatArray5 = new float [0,0,0,0];
float [] floatArray6 = new float [0];
BufferTest [] someArray = new BufferTest [3];
try {
Buffer.ByteLength (null);
Assert.Fail ("TestByteLength: ArgumentNullException not thrown");
} catch (ArgumentNullException) {
// do nothing, this is expected
} catch (Exception e) {
Assert.Fail ("Unexpected exception on Buffer.ByteLength (null):" + e);
}
try {
Buffer.ByteLength (someArray);
Assert.Fail ("TestByteLength: ArgumentException not thrown");
} catch (ArgumentException) {
// do nothing, this is expected
} catch (Exception e) {
Assert.Fail ("Unexpected exception on Buffer.ByteLength (non primitive array):" + e);
}
numBytes = Buffer.ByteLength (floatArray);
Assert.AreEqual (40, numBytes, "TestByteLength: wrong byteLength for floatArray");
numBytes = Buffer.ByteLength (floatArray2);
Assert.AreEqual (400, numBytes, "TestByteLength: wrong byteLength for floatArray2");
numBytes = Buffer.ByteLength (floatArray3);
Assert.AreEqual (4000, numBytes, "TestByteLength: wrong byteLength for floatArray3");
numBytes = Buffer.ByteLength (floatArray4);
Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray4");
numBytes = Buffer.ByteLength (floatArray5);
Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray5");
numBytes = Buffer.ByteLength (floatArray6);
Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray6");
}
[Test]
public void GetByte ()
{
Byte [] byteArray;
bool errorThrown = false;
byteArray = new byte [10];
byteArray [5] = 8;
BufferTest [] someArray = new BufferTest [3];
try {
Buffer.GetByte (null, 5);
} catch (ArgumentNullException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestGetByte: ArgumentNullException not thrown");
errorThrown = false;
try {
Buffer.GetByte (byteArray, -1);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestGetByte: ArgumentOutOfRangeException (negative index) not implemented");
errorThrown = false;
try {
Buffer.GetByte (byteArray, 12);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestGetByte: ArgumentOutOfRangeException (index bigger/equal than array's size not thrown");
errorThrown = false;
try {
Buffer.GetByte (someArray, 0);
Assert.Fail ("TestGetByte: ArgumentException not thrown");
} catch (ArgumentException) {
// do nothing, this is expected
} catch (Exception e) {
Assert.Fail ("Unexpected exception on Buffer.GetByte (non primitive array):" + e);
}
Assert.AreEqual ((Byte)8, Buffer.GetByte (byteArray, 5), "TestGetByte Error");
}
[Test]
public void SetByte ()
{
bool errorThrown = false;
BufferTest [] someArray = new BufferTest [3];
try {
Buffer.SetByte (null, 5, 12);
} catch (ArgumentNullException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestSetByte: ArgumentNullException not thrown");
errorThrown = false;
try {
Buffer.SetByte (byteArray, -1, 32);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: negative index) not thrown");
errorThrown = false;
try {
Buffer.SetByte (byteArray, 12, 43);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: index bigger/equal than array'size");
errorThrown = false;
try {
Buffer.SetByte (someArray, 0, 42);
Assert.Fail ("TestSetByte: ArgumentException not thrown");
} catch (ArgumentException) {
// do nothing, this is expected
} catch (Exception e) {
Assert.Fail ("Unexpected exception on Buffer.SetByte (non primitive array):" + e);
}
Buffer.SetByte (byteArray, 3, (byte) 10);
Assert.AreEqual ((Byte)10, Buffer.GetByte (byteArray, 3), "TestSetByte");
}
}
}

View File

@@ -0,0 +1,251 @@
// ByteTest.cs - NUnit Test Cases for the System.Byte struct
//
// Mario Martinez (mariom925@home.om)
//
// (C) Ximian, Inc. http://www.ximian.com
//
using NUnit.Framework;
using System;
using System.Globalization;
using System.Threading;
namespace MonoTests.System
{
[TestFixture]
public class ByteTest
{
private const Byte MyByte1 = 42;
private const Byte MyByte2 = 0;
private const Byte MyByte3 = 255;
private const string MyString1 = "42";
private const string MyString2 = "0";
private const string MyString3 = "255";
private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
private string[] Results1 = { "",
"0", "0.000000e+000", "0.00",
"0", "0.00", "0.00 %", "0"};
private string[] Results1_Nfi = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"0.00",
"0", "0.000000e+000", "0.00",
"0", "0.00", "0.00 %", "0"};
private string[] Results2 = { "",
"00255", "2.55000e+002", "255.00000",
"255", "255.00000", "25,500.00000 %", "000ff"};
private string[] Results2_Nfi = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"255.00000",
"00255", "2.55000e+002", "255.00000",
"255", "255.00000", "25,500.00000 %", "000ff"};
private CultureInfo old_culture;
private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
[SetUp]
public void SetUp ()
{
old_culture = Thread.CurrentThread.CurrentCulture;
CultureInfo EnUs = new CultureInfo ("en-us", false);
EnUs.NumberFormat.NumberDecimalDigits = 2;
Thread.CurrentThread.CurrentCulture = EnUs;
int cdd = NumberFormatInfo.CurrentInfo.CurrencyDecimalDigits;
string sep = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
string csym = NumberFormatInfo.CurrentInfo.CurrencySymbol;
string csuffix = (cdd > 0 ? sep : "").PadRight(cdd + (cdd > 0 ? 1 : 0), '0');
switch (NumberFormatInfo.CurrentInfo.CurrencyPositivePattern) {
case 0: // $n
Results1[0] = csym + "0" + csuffix;
Results2[0] = csym + "255" + sep + "00000";
break;
case 1: // n$
Results1[0] = "0" + csuffix + csym;
Results2[0] = "255" + sep + "00000" + csym;
break;
case 2: // $ n
Results1[0] = csym + " 0" + csuffix;
Results2[0] = csym + " 255" + sep + "00000";
break;
case 3: // n $
Results1[0] = "0" + csuffix + " " + csym;
Results2[0] = "255" + sep + "00000 " + csym;
break;
}
sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
string decimals = new String ('0', NumberFormatInfo.CurrentInfo.NumberDecimalDigits);
string perPattern = new string[] {"n %","n%","%n"} [NumberFormatInfo.CurrentInfo.PercentPositivePattern];
Results1[2] = "0" + sep + "000000e+000";
Results1[3] = "0" + sep + decimals;
Results1[5] = "0" + sep + decimals;
Results1[6] = perPattern.Replace ("n","0" + sep + "00");
Results2[2] = "2" + sep + "55000e+002";
Results2[3] = "255" + sep + "00000";
Results2[3] = "255" + sep + "00000";
Results2[5] = "255" + sep + "00000";
string gsep = NumberFormatInfo.CurrentInfo.NumberGroupSeparator;
Results2[6] = perPattern.Replace ("n","25" + gsep + "500" + sep + "00000");
}
[TearDown]
public void TearDown ()
{
Thread.CurrentThread.CurrentCulture = old_culture;
}
[Test]
public void TestMinMax()
{
Assert.AreEqual(Byte.MinValue, MyByte2);
Assert.AreEqual(Byte.MaxValue, MyByte3);
}
[Test]
public void TestCompareTo()
{
Assert.AreEqual (255, MyByte3.CompareTo(MyByte2), "#1");
Assert.AreEqual (0, MyByte2.CompareTo(MyByte2), "#2");
Assert.AreEqual (0, MyByte1.CompareTo((object)(Byte)42), "#3");
Assert.AreEqual (-255, MyByte2.CompareTo(MyByte3), "#4");
try {
MyByte2.CompareTo((object)100);
Assert.Fail ("Should raise a System.ArgumentException");
} catch (ArgumentException e) {
}
}
[Test]
public void TestEquals()
{
Assert.IsTrue (MyByte1.Equals(MyByte1));
Assert.IsTrue (MyByte1.Equals((object)(Byte)42));
Assert.IsTrue (MyByte1.Equals((object)(Int16)42) == false);
Assert.IsTrue (MyByte1.Equals(MyByte2) == false);
}
[Test]
public void TestGetHashCode()
{
try {
MyByte1.GetHashCode();
MyByte2.GetHashCode();
MyByte3.GetHashCode();
}
catch {
Assert.Fail ("GetHashCode should not raise an exception here");
}
}
[Test]
public void TestParse()
{
//test Parse(string s)
Assert.IsTrue (MyByte1 == Byte.Parse(MyString1), "MyByte1="+MyByte1+", MyString1="+MyString1+", Parse="+Byte.Parse(MyString1));
Assert.IsTrue(MyByte2 == Byte.Parse(MyString2), "MyByte2");
Assert.IsTrue(MyByte3 == Byte.Parse(MyString3), "MyByte3");
try {
Byte.Parse(null);
Assert.Fail ("Should raise a System.ArgumentNullException");
}
catch (Exception e) {
Assert.IsTrue(typeof(ArgumentNullException) == e.GetType(), "Should get ArgumentNullException");
}
try {
Byte.Parse("not-a-number");
Assert.Fail ("Should raise a System.FormatException");
}
catch (Exception e) {
Assert.IsTrue(typeof(FormatException) == e.GetType(), "not-a-number");
}
//test Parse(string s, NumberStyles style)
Assert.AreEqual((byte)42, Byte.Parse(" "+NumberFormatInfo.CurrentInfo.CurrencySymbol+"42 ", NumberStyles.Currency),
" "+NumberFormatInfo.CurrentInfo.CurrencySymbol+"42 ");
try {
Byte.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer);
Assert.Fail ("Should raise a System.FormatException");
}
catch (Exception e) {
Assert.IsTrue (typeof(FormatException) == e.GetType(), NumberFormatInfo.CurrentInfo.CurrencySymbol+"42 and NumberStyles.Integer");
}
//test Parse(string s, IFormatProvider provider)
Assert.IsTrue(42 == Byte.Parse(" 42 ", Nfi), " 42 and Nfi");
try {
Byte.Parse("%42", Nfi);
Assert.Fail ("Should raise a System.FormatException");
}
catch (Exception e) {
Assert.IsTrue(typeof(FormatException) == e.GetType(), "%42 and Nfi");
}
//test Parse(string s, NumberStyles style, IFormatProvider provider)
Assert.IsTrue(16 == Byte.Parse(" 10 ", NumberStyles.HexNumber, Nfi), "NumberStyles.HexNumber");
try {
Byte.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer, Nfi);
Assert.Fail ("Should raise a System.FormatException");
}
catch (Exception e) {
Assert.IsTrue (typeof(FormatException) == e.GetType(), NumberFormatInfo.CurrentInfo.CurrencySymbol+"42, NumberStyles.Integer, Nfi");
}
Assert.AreEqual (734, Int64.Parse ("734\0"), "#1");
Assert.AreEqual (734, Int64.Parse ("734\0\0\0 \0"), "#2");
Assert.AreEqual (734, Int64.Parse ("734\0\0\0 "), "#3");
Assert.AreEqual (734, Int64.Parse ("734\0\0\0"), "#4");
}
[Test]
[ExpectedException (typeof(OverflowException))]
public void ParseOverflow()
{
int OverInt = Byte.MaxValue + 1;
Byte.Parse(OverInt.ToString());
}
[Test]
public void TestToString()
{
//test ToString()
Assert.AreEqual(MyString1, MyByte1.ToString(), "Compare failed for MyString1 and MyByte1");
Assert.AreEqual(MyString2, MyByte2.ToString(), "Compare failed for MyString2 and MyByte2");
Assert.AreEqual(MyString3, MyByte3.ToString(), "Compare failed for MyString3 and MyByte3");
//test ToString(string format)
for (int i=0; i < Formats1.Length; i++) {
Assert.AreEqual(Results1[i], MyByte2.ToString(Formats1[i]), "Compare failed for Formats1["+i.ToString()+"]");
Assert.AreEqual(Results2[i], MyByte3.ToString(Formats2[i]), "Compare failed for Formats2["+i.ToString()+"]");
}
//test ToString(string format, IFormatProvider provider);
for (int i=0; i < Formats1.Length; i++) {
Assert.AreEqual(Results1_Nfi[i], MyByte2.ToString(Formats1[i], Nfi), "Compare failed for Formats1["+i.ToString()+"] with Nfi");
Assert.AreEqual(Results2_Nfi[i], MyByte3.ToString(Formats2[i], Nfi), "Compare failed for Formats2["+i.ToString()+"] with Nfi");
}
try {
MyByte1.ToString("z");
Assert.Fail ("Should raise a System.FormatException");
}
catch (Exception e) {
Assert.AreEqual(typeof(FormatException), e.GetType(), "Exception is the wrong type");
}
}
[Test]
public void ToString_Defaults ()
{
byte i = 254;
// everything defaults to "G"
string def = i.ToString ("G");
Assert.AreEqual (def, i.ToString (), "ToString()");
Assert.AreEqual (def, i.ToString ((IFormatProvider)null), "ToString((IFormatProvider)null)");
Assert.AreEqual (def, i.ToString ((string)null), "ToString((string)null)");
Assert.AreEqual (def, i.ToString (String.Empty), "ToString(empty)");
Assert.AreEqual (def, i.ToString (null, null), "ToString(null,null)");
Assert.AreEqual (def, i.ToString (String.Empty, null), "ToString(empty,null)");
Assert.AreEqual ("254", def, "ToString(G)");
}
}
}

Some files were not shown because too many files have changed in this diff Show More