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,29 @@
2009-06-06 Gert Driesen <drieseng@users.sourceforge.net>
* ContextStackTest.cs: Added unit tests for indexers, and argument
(null) checks.
2007-08-20 Gert Driesen <drieseng@users.sourceforge.net>
* ContextStackTest.cs: Fix build of unit tests on 1.0 profile.
2007-08-19 Ivan N. Zlatev <contact@i-nz.net>
* ContextStackTest.cs: New unit tests for ContextStack.
2007-07-21 Gert Driesen <drieseng@users.sourceforge.net>
* InstanceDescriptorTest.cs: Improved ctor tests. Added tests for
properties and fields.
2005-10-18 Sebastien Pouliot <sebastien@ximian.com>
* InstanceDescriptorCas.cs: Added more tests for LinkDemand as it just
occured to me that it looked like the LinkDemand was on the class (and
not only on the ctor).
2005-10-18 Sebastien Pouliot <sebastien@ximian.com>
* InstanceDescriptorCas.cs: New. CAS unit tests.
* InstanceDescriptorTest.cs: New. Unit tests for InstanceDescriptor
when using a ContructorInfo.

View File

@@ -0,0 +1,212 @@
//
// ContextStackTest.cs - Unit tests for
// System.ComponentModel.Design.Serialization.ContextStack
//
// Author:
// Ivan N. Zlatev <contact@i-nz.net>
//
// Copyright (C) 2007 Ivan N. Zlatev <contact@i-nz.net>
//
// 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 !MOBILE
using System;
using System.ComponentModel.Design.Serialization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel.Design.Serialization
{
[TestFixture]
public class ContextStackTest
{
[Test]
public void IntegrityTest ()
{
ContextStack stack = new ContextStack ();
string one = "one";
string two = "two";
stack.Push (two);
stack.Push (one);
Assert.AreSame (one, stack [typeof (string)], "#1");
Assert.AreSame (one, stack [0], "#2");
Assert.AreSame (one, stack.Current, "#3");
Assert.AreSame (one, stack.Pop (), "#4");
Assert.AreSame (two, stack [typeof (string)], "#5");
Assert.AreSame (two, stack [0], "#6");
Assert.AreSame (two, stack.Current, "#7");
#if NET_2_0
string three = "three";
stack.Append (three);
Assert.AreSame (two, stack[typeof (string)], "#8");
Assert.AreSame (two, stack[0], "#9");
Assert.AreSame (two, stack.Current, "#10");
Assert.AreSame (two, stack.Pop (), "#11");
Assert.AreSame (three, stack[typeof (string)], "#12");
Assert.AreSame (three, stack[0], "#13");
Assert.AreSame (three, stack.Current, "#14");
Assert.AreSame (three, stack.Pop (), "#15");
#else
Assert.AreSame (two, stack.Pop (), "#15");
#endif
Assert.IsNull (stack.Pop (), "#16");
Assert.IsNull (stack.Current, "#17");
}
#if NET_2_0
[Test]
public void Append_Context_Null ()
{
ContextStack stack = new ContextStack ();
try {
stack.Append (null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("context", ex.ParamName, "#5");
}
}
#endif
[Test] // Item (Int32)
public void Indexer1 ()
{
ContextStack stack = new ContextStack ();
string one = "one";
string two = "two";
stack.Push (one);
stack.Push (two);
Assert.AreSame (two, stack [0], "#1");
Assert.AreSame (one, stack [1], "#2");
Assert.IsNull (stack [2], "#3");
Assert.AreSame (two, stack.Pop (), "#4");
Assert.AreSame (one, stack [0], "#5");
Assert.IsNull (stack [1], "#6");
Assert.AreSame (one, stack.Pop (), "#7");
Assert.IsNull (stack [0], "#8");
Assert.IsNull (stack [1], "#9");
}
[Test] // Item (Int32)
public void Indexer1_Level_Negative ()
{
ContextStack stack = new ContextStack ();
stack.Push (new Foo ());
try {
object context = stack [-1];
Assert.Fail ("#A1:" + context);
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#A4");
Assert.AreEqual ("level", ex.ParamName, "#A5");
}
try {
object context = stack [-5];
Assert.Fail ("#B1:" + context);
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#B4");
Assert.AreEqual ("level", ex.ParamName, "#B5");
}
}
[Test] // Item (Type)
public void Indexer2 ()
{
ContextStack stack = new ContextStack ();
Foo foo = new Foo ();
FooBar foobar = new FooBar ();
stack.Push (foobar);
stack.Push (foo);
Assert.AreSame (foo, stack [typeof (Foo)], "#1");
Assert.AreSame (foo, stack [typeof (IFoo)], "#2");
Assert.AreSame (foo, stack.Pop (), "#3");
Assert.AreSame (foobar, stack [typeof (Foo)], "#4");
Assert.AreSame (foobar, stack [typeof (FooBar)], "#5");
Assert.AreSame (foobar, stack [typeof (IFoo)], "#6");
Assert.IsNull (stack [typeof (string)], "#7");
}
[Test] // Item (Type)
public void Indexer2_Type_Null ()
{
ContextStack stack = new ContextStack ();
stack.Push (new Foo ());
try {
object context = stack [(Type) null];
Assert.Fail ("#1:" + context);
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("type", ex.ParamName, "#5");
}
}
[Test]
public void Push_Context_Null ()
{
ContextStack stack = new ContextStack ();
try {
stack.Push (null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("context", ex.ParamName, "#5");
}
}
public interface IFoo
{
}
public class Foo : IFoo
{
}
public class FooBar : Foo
{
}
}
}
#endif

View File

@@ -0,0 +1,136 @@
//
// InstanceDescriptorCas.cs - CAS unit tests for
// System.ComponentModel.Design.Serialization.InstanceDescriptor
//
// 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.Collections;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.ComponentModel.Design.Serialization;
namespace MonoCasTests.System.ComponentModel.Design.Serialization {
[TestFixture]
[Category ("CAS")]
public class InstanceDescriptorCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UnitTestReuse ()
{
InstanceDescriptorTest unit = new InstanceDescriptorTest ();
unit.FixtureSetUp ();
unit.Constructor_Null_ICollection ();
unit.Constructor_MemberInfo_ICollection ();
unit.Constructor_Null_ICollection_Boolean ();
unit.Constructor_MemberInfo_ICollection_Boolean ();
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void Ctor2_LinkDemand_Deny_Anything ()
{
// denying anything -> not unrestricted
Type[] types = new Type[2] { typeof (MemberInfo), typeof (ICollection) };
ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection)");
Assert.IsNotNull (ci.Invoke (new object[2] { null, new object[] { } }), "invoke");
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void Ctor2_LinkDemand_PermitOnly_Unrestricted ()
{
Type[] types = new Type[2] { typeof (MemberInfo), typeof (ICollection) };
ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection)");
Assert.IsNotNull (ci.Invoke (new object[2] { null, new object[] { } }), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void Ctor3_LinkDemand_Deny_Anything ()
{
// denying anything -> not unrestricted
Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection,bool)");
Assert.IsNotNull (ci.Invoke (new object[3] { null, new object[] { }, false }), "invoke");
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void Ctor3_LinkDemand_PermitOnly_Unrestricted ()
{
Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection,bool)");
Assert.IsNotNull (ci.Invoke (new object[3] { null, new object[] { }, false }), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void Property_LinkDemand_Deny_Anything ()
{
InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
// denying anything -> not unrestricted
Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
MethodInfo mi = typeof (InstanceDescriptor).GetProperty ("IsComplete").GetGetMethod ();
Assert.IsNotNull (mi, "IsComplete)");
Assert.IsTrue ((bool)mi.Invoke (id, null), "invoke");
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void Property_LinkDemand_PermitOnly_Unrestricted ()
{
InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
// denying anything -> not unrestricted
Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
MethodInfo mi = typeof (InstanceDescriptor).GetProperty ("IsComplete").GetGetMethod ();
Assert.IsNotNull (mi, "IsComplete)");
Assert.IsTrue ((bool) mi.Invoke (id, null), "invoke");
}
}
}

View File

@@ -0,0 +1,285 @@
//
// InstanceDescriptorTest.cs - Unit tests for
// System.ComponentModel.Design.Serialization.InstanceDescriptor
//
// 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.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
using System.Threading;
namespace MonoTests.System.ComponentModel.Design.Serialization {
[TestFixture]
public class InstanceDescriptorTest {
private const string url = "http://www.mono-project.com/";
private ConstructorInfo ci;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
ci = typeof (Uri).GetConstructor (new Type[1] { typeof (string) });
}
[Test]
public void Constructor0_Arguments_Mismatch ()
{
try {
new InstanceDescriptor (ci, null);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Length mismatch
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsNull (ex.ParamName, "#B5");
}
}
[Test]
public void Constructor0_MemberInfo_Type ()
{
Type type = typeof (Uri);
InstanceDescriptor id = new InstanceDescriptor (type,
new object [] { url });
Assert.AreEqual (1, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.AreSame (type, id.MemberInfo, "#3");
Assert.IsNull (id.Invoke (), "#4");
}
[Test]
public void Constructor_Null_ICollection ()
{
InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
Assert.AreEqual (0, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.IsNull (id.MemberInfo, "#3");
Assert.IsNull (id.Invoke (), "#4");
}
[Test]
public void Constructor_MemberInfo_ICollection ()
{
InstanceDescriptor id = new InstanceDescriptor (ci, new object[] { url });
Assert.AreEqual (1, id.Arguments.Count, "Arguments");
Assert.IsTrue (id.IsComplete, "IsComplete");
Assert.AreSame (ci, id.MemberInfo, "MemberInfo");
Uri uri = (Uri) id.Invoke ();
Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
}
[Test]
public void Constructor_Null_ICollection_Boolean ()
{
InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }, true);
Assert.AreEqual (0, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.IsNull (id.MemberInfo, "#3");
Assert.IsNull (id.Invoke (), "#4");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Constructor_MemberInfo_Null_Boolean ()
{
new InstanceDescriptor (ci, null, false);
// mismatch for required parameters
}
[Test]
public void Constructor_MemberInfo_ICollection_Boolean ()
{
InstanceDescriptor id = new InstanceDescriptor (ci, new object[] { url }, false);
Assert.AreEqual (1, id.Arguments.Count, "Arguments");
Assert.IsFalse (id.IsComplete, "IsComplete");
Assert.AreSame (ci, id.MemberInfo, "MemberInfo");
Uri uri = (Uri) id.Invoke ();
Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
}
[Test]
public void Field_Arguments_Empty ()
{
FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
InstanceDescriptor id = new InstanceDescriptor (fi, new object [0]);
Assert.AreEqual (0, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.AreSame (fi, id.MemberInfo, "#3");
Assert.IsNotNull (id.Invoke (), "#4");
}
[Test]
public void Field_Arguments_Mismatch ()
{
FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
try {
new InstanceDescriptor (fi, new object [] { url });
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Parameter must be static
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test]
public void Field_Arguments_Null ()
{
FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
InstanceDescriptor id = new InstanceDescriptor (fi, null);
Assert.AreEqual (0, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.AreSame (fi, id.MemberInfo, "#3");
Assert.IsNotNull (id.Invoke (), "#4");
}
[Test]
public void Field_MemberInfo_NonStatic ()
{
FieldInfo fi = typeof (InstanceField).GetField ("Name");
try {
new InstanceDescriptor (fi, null);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Parameter must be static
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test]
public void Property_Arguments_Mismatch ()
{
#if MOBILE
// ensure the property is not linked out of the application since it make the test fails
Assert.NotNull (Thread.CurrentPrincipal, "pre-test");
#endif
PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");
InstanceDescriptor id = new InstanceDescriptor (pi, new object [] { url });
Assert.AreEqual (1, id.Arguments.Count, "#1");
object [] arguments = new object [id.Arguments.Count];
id.Arguments.CopyTo (arguments, 0);
Assert.AreSame (url, arguments [0], "#2");
Assert.IsTrue (id.IsComplete, "#3");
Assert.AreSame (pi, id.MemberInfo, "#4");
try {
id.Invoke ();
Assert.Fail ("#5");
} catch (TargetParameterCountException) {
}
}
[Test]
public void Property_Arguments_Null ()
{
#if MOBILE
// ensure the property is not linked out of the application since it make the test fails
Assert.NotNull (Thread.CurrentPrincipal, "pre-test");
#endif
PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");
InstanceDescriptor id = new InstanceDescriptor (pi, null);
Assert.AreEqual (0, id.Arguments.Count, "#1");
Assert.IsTrue (id.IsComplete, "#2");
Assert.AreSame (pi, id.MemberInfo, "#3");
Assert.IsNotNull (id.Invoke (), "#4");
}
[Test]
public void Property_MemberInfo_NonStatic ()
{
PropertyInfo pi = typeof (Uri).GetProperty ("Host");
try {
new InstanceDescriptor (pi, null);
Assert.Fail ("#A1");
} catch (ArgumentException ex) {
// Parameter must be static
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsNull (ex.ParamName, "#A5");
}
try {
new InstanceDescriptor (pi, null, false);
Assert.Fail ("#B1");
} catch (ArgumentException ex) {
// Parameter must be static
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsNull (ex.ParamName, "#B5");
}
}
[Test]
public void Property_MemberInfo_WriteOnly ()
{
PropertyInfo pi = typeof (WriteOnlyProperty).GetProperty ("Name");
try {
new InstanceDescriptor (pi, null);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Parameter must be readable
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
class WriteOnlyProperty
{
public static string Name {
set {
}
}
}
class InstanceField
{
public string Name;
}
}
}