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,101 @@
2009-06-30 Zoltan Varga <vargaz@gmail.com>
* DebugTest.cs TextWriterTraceListenerTest.cs: Convert all tests to
new-style nunit classes/methods.
2009-06-25 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2007-05-11 Gert Driesen <drieseng@users.sourceforge.net>
* DebuggerDisplayAttributeTest.cs: Make test forward compatible.
Replaced Assert.AreEqual null comparison with Assert.IsNull. Replaced
"" with string.Empty.
2007-05-11 Rolf Bjarne Kvinge <RKvinge@novell.com>
* DebuggerDisplayAttributeTest.cs: Added.
2006-07-24 Gert Driesen <drieseng@users.sourceforge.net>
* StackFrameTest.cs: Spaces to tabs. Marked tests that fail on Mono
as NotWorking instead of Ignore. Enabled StackFrameTest2.GetFileName2
and StackFrameTest3.GetFileName as tests pass on both Mono and .NET.
2005-06-12 Gert Driesen <drieseng@users.sourceforge.net>
* StackTraceTest.cs: Mono does not support StraceTrace for
thread. Test passes on MS.NET 2.x.
2005-03-14 Sebastien Pouliot <sebastien@ximian.com>
* StackFrameCas.cs: Fixed failures under MS for NET_1_1.
* StackTraceCas.cs: Fixed failures under MS for NET_1_1.
2005-01-28 Sebastien Pouliot <sebastien@ximian.com>
* StackFrameCas.cs: New. Permission tests for StackFrame.
* StackTraceCas.cs: New. Permission tests for StackTrace.
2004-08-30 Nick Drochak <ndrochak@ieee.com>
* StackTraceTest.cs: Fix warning.
2004-08-29 Nick Drochak <ndrochak@ieee.com>
* StackFrameTest.cs : Ignore tests that fail on MS.NET.
2004-08-05 Sebastien Pouliot <sebastien@ximian.com>
* StackFrameTest.cs: Added new unit tests to validate exceptions.
Converted existing unit tests to NUnit 2.2.
2004-05-30 David Sheldon <dave-mono@earth.li>
* StackFrameTest.cs: Mark the failures that have been failing
for months due to bug 45730 as ignored as it doesn't look like
it will be fixed soon.
2003-10-07 Nick Drochak <ndrochak@gol.com>
* StackFrameTest.cs: Get tests to pass on .NET 1.1.
2003-08-19 Nick Drochak <ndrochak@gol.com>
* StackFrameTest.cs: Isolate test failure by making tests finer
grained.
2003-07-01 Zoltan Varga <vargaz@freemail.hu>
* StackFrameTest.cs (TestGetMethod): Remove test for method name, since
it is not guaranteed to be 'InternalInvoke'.
2003-06-10 Nick Drochak <ndrochak@gol.com>
* StackFrameTest.cs: More cleanups. Now *all* tests pass.
2003-06-10 Nick Drochak <ndrochak@gol.com>
* StackFrameTest.cs: Cleanups. Now tests pass.
2003-04-17 Nick Drochak <ndrochak@gol.com>
* StackFrameTest.cs: Use nunit version 2 style.
2003-01-27 Zoltan Varga <vargaz@freemail.hu>
* StackTraceTest.cs: Added test for unthrown exceptions.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-06-19 Nick Drochak <ndrochak@gol.com>
* AllTests.cs: Add missing test: DebugTest
2002-02-10 Nick Drochak <ndrochak@gol.com>
* DebugTest.cs: Put in correct namespace.
* TextWriterTraceListenerTest.cs: Put in correct namespace.

View File

@@ -0,0 +1,172 @@
//
// DebuggerDisplayAttributeTest.cs
//
// Author:
// Rolf Bjarne Kvinge (RKvinge@novell.com)
//
// (C) 2007
//
using System;
using System.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
/// <summary>
/// Tests the case where StackFrame is created for specified file name and
/// location inside it.
/// </summary>
[TestFixture]
public class DebuggerDisplayAttributeTest
{
[Test]
public void ConstructorTest ()
{
DebuggerDisplayAttribute dda;
dda = new DebuggerDisplayAttribute (null);
Assert.AreEqual (string.Empty, dda.Value, "A1");
Assert.IsNull (dda.Target, "A2");
Assert.IsNull (dda.TargetTypeName, "A3");
Assert.AreEqual (string.Empty, dda.Type, "A4");
Assert.AreEqual (string.Empty, dda.Name, "A4");
dda = new DebuggerDisplayAttribute ("abc");
Assert.AreEqual ("abc", dda.Value, "B1");
Assert.IsNull (dda.Target, "B2");
Assert.IsNull (dda.TargetTypeName, "B3");
Assert.AreEqual (string.Empty, dda.Type, "B4");
Assert.AreEqual (string.Empty, dda.Name, "B4");
}
[Test]
public void TargetTest ()
{
DebuggerDisplayAttribute dda;
dda = new DebuggerDisplayAttribute (null);
Assert.AreEqual (string.Empty, dda.Value, "A1");
Assert.IsNull (dda.Target, "A2");
Assert.IsNull (dda.TargetTypeName, "A3");
Assert.AreEqual (string.Empty, dda.Type, "A4");
Assert.AreEqual (string.Empty, dda.Name, "A4");
dda.Target = typeof(string);
Assert.AreEqual (string.Empty, dda.Value, "B1");
Assert.IsNotNull (dda.Target, "B2");
Assert.AreSame (typeof(string), dda.Target, "B2-b");
Assert.AreEqual (typeof (string).AssemblyQualifiedName, dda.TargetTypeName, "B3");
Assert.AreEqual (string.Empty, dda.Type, "B4");
Assert.AreEqual (string.Empty, dda.Name, "B4");
try {
dda.Target = null;
Assert.Fail ("Excepted ArgumentNullException, got no exception.");
} catch (ArgumentNullException) {
}
}
[Test]
public void TargetTypeNameTest ()
{
DebuggerDisplayAttribute dda;
dda = new DebuggerDisplayAttribute (null);
Assert.AreEqual (string.Empty, dda.Value, "A1");
Assert.IsNull (dda.Target, "A2");
Assert.IsNull (dda.TargetTypeName, "A3");
Assert.AreEqual (string.Empty, dda.Type, "A4");
Assert.AreEqual (string.Empty, dda.Name, "A4");
dda.TargetTypeName = "System.String";
Assert.AreEqual (string.Empty, dda.Value, "B1");
Assert.IsNull (dda.Target, "B2");
Assert.AreEqual ("System.String", dda.TargetTypeName, "B3");
Assert.AreEqual (string.Empty, dda.Type, "B4");
Assert.AreEqual (string.Empty, dda.Name, "B4");
dda.TargetTypeName = null;
Assert.AreEqual (string.Empty, dda.Value, "C1");
Assert.IsNull (dda.Target, "C2");
Assert.IsNull (dda.TargetTypeName, "C3");
Assert.AreEqual (string.Empty, dda.Type, "C4");
Assert.AreEqual (string.Empty, dda.Name, "C4");
dda.TargetTypeName = string.Empty;
Assert.AreEqual (string.Empty, dda.Value, "D1");
Assert.IsNull (dda.Target, "D2");
Assert.AreEqual (string.Empty, dda.TargetTypeName, "D3");
Assert.AreEqual (string.Empty, dda.Type, "D4");
Assert.AreEqual (string.Empty, dda.Name, "D4");
}
[Test]
public void TypeTest ()
{
DebuggerDisplayAttribute dda;
dda = new DebuggerDisplayAttribute (null);
Assert.AreEqual (string.Empty, dda.Value, "A1");
Assert.IsNull (dda.Target, "A2");
Assert.IsNull (dda.TargetTypeName, "A3");
Assert.AreEqual (string.Empty, dda.Type, "A4");
Assert.AreEqual (string.Empty, dda.Name, "A4");
dda.Type = "System.String";
Assert.AreEqual (string.Empty, dda.Value, "B1");
Assert.IsNull (dda.Target, "B2");
Assert.IsNull (dda.TargetTypeName, "B3");
Assert.AreEqual ("System.String", dda.Type, "B4");
Assert.AreEqual (string.Empty, dda.Name, "B4");
dda.Type = null;
Assert.AreEqual (string.Empty, dda.Value, "C1");
Assert.IsNull (dda.Target, "C2");
Assert.IsNull (dda.TargetTypeName, "C3");
Assert.IsNull (dda.Type, "C4");
Assert.AreEqual (string.Empty, dda.Name, "C4");
dda.Type = string.Empty;
Assert.AreEqual (string.Empty, dda.Value, "D1");
Assert.IsNull (dda.Target, "D2");
Assert.IsNull (dda.TargetTypeName, "D3");
Assert.AreEqual (string.Empty, dda.Type, "D4");
Assert.AreEqual (string.Empty, dda.Name, "D4");
}
[Test]
public void NameTest ()
{
DebuggerDisplayAttribute dda;
dda = new DebuggerDisplayAttribute (null);
Assert.AreEqual (string.Empty, dda.Value, "A1");
Assert.IsNull (dda.Target, "A2");
Assert.IsNull (dda.TargetTypeName, "A3");
Assert.AreEqual (string.Empty, dda.Type, "A4");
Assert.AreEqual (string.Empty, dda.Name, "A4");
dda.Name = "who?";
Assert.AreEqual (string.Empty, dda.Value, "B1");
Assert.IsNull (dda.Target, "B2");
Assert.IsNull (dda.TargetTypeName, "B3");
Assert.AreEqual (string.Empty, dda.Type, "B4");
Assert.AreEqual ("who?", dda.Name, "B4");
dda.Name = null;
Assert.AreEqual (string.Empty, dda.Value, "C1");
Assert.IsNull (dda.Target, "C2");
Assert.IsNull (dda.TargetTypeName, "C3");
Assert.AreEqual (string.Empty, dda.Type, "C4");
Assert.IsNull (dda.Name, "C4");
dda.Name = string.Empty;
Assert.AreEqual (string.Empty, dda.Value, "D1");
Assert.IsNull (dda.Target, "D2");
Assert.IsNull (dda.TargetTypeName, "D3");
Assert.AreEqual (string.Empty, dda.Type, "D4");
Assert.AreEqual (string.Empty, dda.Name, "D4");
}
}
}

View File

@@ -0,0 +1,56 @@
//
// DecoupledTask.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright 2013 Xamarin Inc (http://www.xamarin.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.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class DebuggerTypeProxyAttributeTest
{
[Test]
public void Constructor_Type ()
{
var dtp = new DebuggerTypeProxyAttribute (typeof (string));
Assert.IsNull (dtp.Target, "#1");
Assert.AreEqual (typeof (string).AssemblyQualifiedName, dtp.ProxyTypeName, "#2");
}
[Test]
public void Constructor_Type_Invalid ()
{
try {
new DebuggerTypeProxyAttribute (null as Type);
Assert.Fail ();
} catch (ArgumentNullException) {
}
}
}
}

View File

@@ -0,0 +1,217 @@
//
// StackFrameCas.cs - CAS unit tests for System.Diagnostics.StackFrame
//
// 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.Diagnostics;
using System.Security;
using System.Security.Permissions;
using System.Threading;
namespace MonoCasTests.System.Diagnostics {
[TestFixture]
[Category ("CAS")]
public class StackFrameCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// avoid replication of tests on all constructors (this is no
// problem because the stack is already set correctly). The
// goal is to call every property and methods to see if they
// have any* security requirements (*except for LinkDemand and
// InheritanceDemand).
private void Check (StackFrame sf, bool checkFile)
{
int cn = sf.GetFileColumnNumber ();
int ln = sf.GetFileLineNumber ();
int il = sf.GetILOffset ();
int no = sf.GetNativeOffset ();
Assert.IsNotNull (sf.GetMethod (), "GetMethod");
if (checkFile) {
string fn = sf.GetFileName ();
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackFrame_DefaultConstructor ()
{
StackFrame sf = new StackFrame ();
Check (sf, true);
}
#if !RUN_ONDOTNET || NET_4_0 // Disabled because .net 2 fails to load dll with "Failure decoding embedded permission set object" due to "/" path
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
[ExpectedException (typeof (SecurityException))]
public void StackFrame_TrueConstructor_Fail ()
{
StackFrame sf = null;
try {
// ask for file informations
sf = new StackFrame (true);
Check (sf, false);
}
catch {
Assert.Fail ("Didn't ask for file information");
}
// now look at the file informations...
// note: only fails under 2.0
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
public void StackFrame_TrueConstructor_Pass ()
{
// ask file info
StackFrame sf = new StackFrame (true);
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
[ExpectedException (typeof (SecurityException))]
public void StackFrame_IntTrueConstructor_Fail ()
{
StackFrame sf = null;
try {
// ask for file informations
sf = new StackFrame (0, true);
Check (sf, false);
}
catch {
Assert.Fail ("Didn't ask for file information");
}
// now look at the file informations...
// note: only fails under 2.0
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
public void StackFrame_IntTrueConstructor_Pass ()
{
// ask file info
StackFrame sf = new StackFrame (0, true);
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
[ExpectedException (typeof (SecurityException))]
public void StackFrame_StringIntConstructor_Fail ()
{
StackFrame sf = null;
try {
// ask for file informations
sf = new StackFrame ("mono.cs", 1);
Check (sf, false);
}
catch {
Assert.Fail ("Didn't ask for file information");
}
// now look at the file informations...
// note: only fails under 2.0
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
public void StackFrame_StringIntConstructor_Pass ()
{
// supply file info
StackFrame sf = new StackFrame ("mono.cs", 1);
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
[ExpectedException (typeof (SecurityException))]
public void StackFrame_StringIntIntConstructor_Fail ()
{
StackFrame sf = null;
try {
// supply file info
sf = new StackFrame ("mono.cs", 1, 1);
Check (sf, false);
}
catch {
Assert.Fail ("Didn't ask for file information");
}
// now look at the file informations...
// note: only fails under 2.0
Check (sf, true);
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
public void StackFrame_StringIntIntConstructor_Pass ()
{
// supply file info
StackFrame sf = new StackFrame ("mono.cs", 1, 1);
Check (sf, true);
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackFrame_FalseConstructor ()
{
// DO NOT ask for file informations
StackFrame sf = new StackFrame (false);
Check (sf, true);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackFrame_IntConstructor ()
{
StackFrame sf = new StackFrame (1);
Check (sf, true);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackFrame_IntFalseConstructor ()
{
// DO NOT ask for file informations
StackFrame sf = new StackFrame (1, false);
Check (sf, true);
}
}
}

View File

@@ -0,0 +1,369 @@
//
// MonoTests.System.Diagnostics.StackFrameTest.cs
//
// Author:
// Alexander Klyubin (klyubin@aqris.com)
//
// (C) 2001
//
using System;
using System.Diagnostics;
using System.Reflection;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
/// <summary>
/// Tests the case where StackFrame is created for specified file name and
/// location inside it.
/// </summary>
[TestFixture]
public class StackFrameTest1
{
private StackFrame frame1;
private StackFrame frame2;
[SetUp]
public void SetUp ()
{
frame1 = new StackFrame ("dir/someFile", 13, 45);
frame2 = new StackFrame ("SomeFile2.cs", 24);
}
[TearDown]
public void TearDown ()
{
frame1 = null;
frame2 = null;
}
/// <summary>
/// Tests whether getting file name works.
/// </summary>
[Test]
[Category("LLVMNotWorking")]
public void TestGetFileName ()
{
Assert.AreEqual ("dir/someFile",
frame1.GetFileName (),
"File name (1)");
Assert.AreEqual ("SomeFile2.cs",
frame2.GetFileName (),
"File name (2)");
}
/// <summary>
/// Tests whether getting file line number works.
/// </summary>
[Test]
[Category("LLVMNotWorking")]
public void TestGetFileLineNumber ()
{
Assert.AreEqual (13,
frame1.GetFileLineNumber (),
"Line number (1)");
Assert.AreEqual (24,
frame2.GetFileLineNumber (),
"Line number (2)");
}
/// <summary>
/// Tests whether getting file column number works.
/// </summary>
[Test]
public void TestGetFileColumnNumber ()
{
Assert.AreEqual (45,
frame1.GetFileColumnNumber (),
"Column number (1)");
Assert.AreEqual (0,
frame2.GetFileColumnNumber (),
"Column number (2)");
}
/// <summary>
/// Tests whether getting method associated with frame works.
/// </summary>
[Test]
public void TestGetMethod ()
{
Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
Assert.AreEqual (this.GetType (),
frame1.GetMethod ().DeclaringType,
"Class declaring the method (1)");
Assert.AreEqual ("SetUp",
frame1.GetMethod ().Name,
"Method name (1)");
Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
Assert.AreEqual (this.GetType (),
frame2.GetMethod ().DeclaringType,
"Class declaring the method (2)");
Assert.AreEqual ("SetUp",
frame2.GetMethod ().Name,
"Method name (2)");
}
}
/// <summary>
/// Tests the case where StackFrame is created for current method.
/// </summary>
/// <remarks>
/// FIXME: Must be compiled with /debug switch. Otherwise some file
/// information will be incorrect for the following test cases.
/// What's the best way to do both types of tests with and without
/// debug information?
/// </remarks>
[TestFixture]
public class StackFrameTest2
{
private StackFrame frame1;
private StackFrame frame2;
private StackFrame frame3;
[SetUp]
public void SetUp ()
{
frame1 = new StackFrame ();
frame2 = new StackFrame (true);
frame3 = new StackFrame (0);
}
[TearDown]
public void TearDown ()
{
frame1 = null;
frame2 = null;
frame3 = null;
}
/// <summary>
/// Tests whether getting file name works.
/// </summary>
[Test]
public void TestGetFileName1 ()
{
Assert.IsNull (frame1.GetFileName (),
"File name (1)");
}
[Test]
[Category ("LLVMNotWorking")]
public void TestGetFileName2 ()
{
#if MOBILE && !DEBUG
Assert.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
#endif
Assert.IsNotNull (frame2.GetFileName (), "File name not null");
Assert.IsTrue (frame2.GetFileName ().Length != 0, "File name not empty");
Assert.IsTrue (frame2.GetFileName ().EndsWith ("StackFrameTest.cs"),
"File name (2) " + frame2.GetFileName () + " ends with StackFrameTest.cs");
}
/// <summary>
/// Tests whether getting file line number works.
/// </summary>
[Test]
[Category ("LLVMNotWorking")]
public void TestGetFileLineNumber ()
{
#if MOBILE && !DEBUG
Assert.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
#endif
Assert.AreEqual (0,
frame1.GetFileLineNumber (),
"Line number (1)");
Assert.AreEqual (134,
frame2.GetFileLineNumber (),
"Line number (2)");
Assert.AreEqual (0,
frame3.GetFileLineNumber (),
"Line number (3)");
}
/// <summary>
/// Tests whether getting file column number works.
/// </summary>
[Test]
[Category ("NotWorking")] // bug #45730 - Column numbers always zero
public void TestGetFileColumnNumber ()
{
Assert.AreEqual (0,
frame1.GetFileColumnNumber (),
"Column number (1)");
Assert.AreEqual (4,
frame2.GetFileColumnNumber (),
"Column number (2)");
Assert.AreEqual (0,
frame3.GetFileColumnNumber (),
"Column number (3)");
}
/// <summary>
/// Tests whether getting method associated with frame works.
/// </summary>
[Test]
public void TestGetMethod ()
{
Assert.IsNotNull (frame1.GetMethod (),
"Method not null (1)");
Assert.AreEqual (this.GetType (),
frame1.GetMethod ().DeclaringType,
"Class declaring the method (1)");
Assert.AreEqual ("SetUp",
frame1.GetMethod ().Name,
"Method name (1)");
Assert.IsNotNull (frame2.GetMethod (),
"Method not null (2)");
Assert.AreEqual (this.GetType (),
frame2.GetMethod ().DeclaringType,
"Class declaring the method (2)");
Assert.AreEqual ("SetUp",
frame2.GetMethod ().Name,
"Method name (2)");
Assert.IsNotNull (frame3.GetMethod (),
"Method not null (3)");
Assert.AreEqual (this.GetType (),
frame3.GetMethod ().DeclaringType,
"Class declaring the method (3)");
Assert.AreEqual ("SetUp",
frame3.GetMethod ().Name,
"Method name (3)");
}
}
/// <summary>
/// Tests the case where StackFrame is created for current method but
/// skipping some frames.
/// </summary>
/// <remarks>
/// FIXME: Must be compiled with /debug switch. Otherwise some file
/// information will be incorrect for the following test cases.
/// What's the best way to do both types of tests with and without
/// debug information?
/// </remarks>
[TestFixture]
public class StackFrameTest3
{
protected StackFrame frame1;
protected StackFrame frame2;
[SetUp]
public void SetUp ()
{
// In order to get better test cases with stack traces
NestedSetUp ();
}
private void NestedSetUp ()
{
frame1 = new StackFrame (2);
frame2 = new StackFrame (1, true);
// Without this access of frame2 on the RHS, none of
// the properties or methods seem to return any data ???
string s = frame2.GetFileName ();
}
[TearDown]
public void TearDown ()
{
frame1 = null;
frame2 = null;
}
/// <summary>
/// Tests whether getting file name works.
/// </summary>
[Test]
[Category ("LLVMNotWorking")]
public void TestGetFileName ()
{
#if MOBILE && !DEBUG
Assert.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
#endif
Assert.IsNull (frame1.GetFileName (),
"File name (1)");
Assert.IsNotNull (frame2.GetFileName (),
"File name (2) should not be null");
Assert.IsTrue (frame2.GetFileName ().EndsWith ("StackFrameTest.cs"),
"File name (2) " + frame2.GetFileName () + " ends with StackFrameTest.cs");
}
/// <summary>
/// Tests whether getting file line number works.
/// </summary>
[Test]
#if ONLY_1_1
[Category ("NotDotNet")] // .NET 1.1 is off by one
#endif
[Category ("LLVMNotWorking")]
public void TestGetFileLineNumber ()
{
#if MOBILE && !DEBUG
Assert.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
#endif
Assert.AreEqual (0,
frame1.GetFileLineNumber (),
"Line number (1)");
Assert.AreEqual (270,
frame2.GetFileLineNumber (),
"Line number (2)");
}
/// <summary>
/// Tests whether getting file column number works.
/// </summary>
[Test]
#if ONLY_1_1
[Category ("NotDotNet")] // .NET 1.1 is off by one
#endif
[Category ("NotWorking")] // bug #45730 - Column numbers always zero
public void TestGetFileColumnNumber ()
{
Assert.AreEqual (0,
frame1.GetFileColumnNumber (),
"Column number (1)");
Assert.AreEqual (4,
frame2.GetFileColumnNumber (),
"Column number (2)");
}
/// <summary>
/// Tests whether getting method associated with frame works.
/// </summary>
[Test]
public void TestGetMethod ()
{
Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
Assert.AreEqual (this.GetType (),
frame2.GetMethod ().DeclaringType,
"Class declaring the method (2)");
Assert.AreEqual ("SetUp",
frame2.GetMethod ().Name,
"Method name (2)");
}
}
}

View File

@@ -0,0 +1,181 @@
//
// StackTraceCas.cs - CAS unit tests for System.Diagnostics.StackTrace
//
// 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.Diagnostics;
using System.Security;
using System.Security.Permissions;
using System.Threading;
namespace MonoCasTests.System.Diagnostics {
[TestFixture]
[Category ("CAS")]
public class StackTraceCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// avoid replication of tests on all constructors (this is no
// problem because the stack is already set correctly). The
// goal is to call every property and methods to see if they
// have any* security requirements (*except for LinkDemand and
// InheritanceDemand).
private void Check (StackTrace st)
{
if (st.FrameCount > 0)
Assert.IsNotNull (st.GetFrame (0), "GetFrame");
else
Assert.IsNull (st.GetFrame (0), "GetFrame");
#if NET_2_0
if (st.FrameCount > 0)
Assert.IsNotNull (st.GetFrames (), "GetFrames");
else
Assert.IsNull (st.GetFrames (), "GetFrames");
#endif
Assert.IsNotNull (st.ToString (), "ToString");
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
public void StackTrace_DefaultConstructor ()
{
StackTrace st = new StackTrace ();
Check (st);
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
public void StackTrace_BoolConstructor ()
{
StackTrace st = new StackTrace (true);
Check (st);
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
public void StackTrace_IntConstructor ()
{
StackTrace st = new StackTrace (1);
Check (st);
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
public void StackTrace_IntBoolConstructor ()
{
StackTrace st = new StackTrace (1, true);
Check (st);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackTrace_ExceptionConstructor ()
{
StackTrace st = new StackTrace (new Exception ());
Check (st);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackTrace_ExceptionBoolConstructor ()
{
StackTrace st = new StackTrace (new Exception (), true);
Check (st);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackTrace_ExceptionIntConstructor ()
{
StackTrace st = new StackTrace (new Exception (), 1);
Check (st);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void StackTrace_ExceptionIntBoolConstructor ()
{
StackTrace st = new StackTrace (new Exception (), 1, true);
Check (st);
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
public void StackTrace_StackFrameConstructor ()
{
StackTrace st = new StackTrace (new StackFrame ());
Check (st);
}
[Test]
#if NET_2_0
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#else
[ReflectionPermission (SecurityAction.Deny, TypeInformation = true)]
[ExpectedException (typeof (SecurityException))]
#endif
[Category ("NotWorking")]
public void StackTrace_ThreadBoolConstructor ()
{
StackTrace st = new StackTrace (Thread.CurrentThread, true);
Check (st);
}
}
}

View File

@@ -0,0 +1,200 @@
//
// MonoTests.System.Diagnostics.StackTraceTest.cs
//
// Authors:
// Alexander Klyubin (klyubin@aqris.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2001
// 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.
//
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class StackTraceTest {
private StackTrace trace;
private StackFrame frame;
[SetUp]
public void SetUp ()
{
frame = new StackFrame ("dir/someFile", 13, 45);
trace = new StackTrace (frame);
}
[TearDown]
public void TearDown ()
{
trace = null;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void StackTrace_Int_Negative ()
{
new StackTrace (-1);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void StackTrace_Exception_Null ()
{
Exception e = null;
new StackTrace (e);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void StackTrace_ExceptionBool_Null ()
{
Exception e = null;
new StackTrace (e, true);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void StackTrace_ExceptionInt_Null ()
{
Exception e = null;
new StackTrace (e, 1);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void StackTrace_ExceptionInt_Negative ()
{
new StackTrace (new Exception (), -1);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void StackTrace_ExceptionIntBool_Null ()
{
Exception e = null;
new StackTrace (e, 1, true);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void StackTrace_ExceptionIntBool_Negative ()
{
new StackTrace (new Exception (), -1, true);
}
[Test]
public void StackTrace_StackFrame_Null ()
{
StackFrame sf = null;
StackTrace st = new StackTrace (sf);
// no exception
Assert.AreEqual (1, st.FrameCount, "FrameCount");
Assert.IsNull (st.GetFrame (0), "Empty Frame");
}
[Test]
[Ignore ("Not supported in Mono")]
public void StackTrace_Thread_Null ()
{
Thread t = null;
StackTrace st = new StackTrace (t, true);
// no exception
}
static void EmptyThread ()
{
Thread.Sleep (1000);
}
[Test]
#if !NET_2_0
// on MS .NET 1.x, ThreadState after Start() is Unstarted
[Category ("NotDotNet")]
#endif
[ExpectedException (typeof (ThreadStateException))]
[Ignore ("Not supported in Mono")]
public void StackTrace_Thread_NotSuspended ()
{
Thread t = new Thread (new ThreadStart (EmptyThread));
t.Start ();
new StackTrace (t, true);
}
[Test]
[Ignore ("Not supported in Mono")]
public void StackTrace_Thread_Suspended ()
{
Thread t = new Thread (new ThreadStart (EmptyThread));
t.Start ();
t.Suspend ();
new StackTrace (t, true);
}
[Test]
public void FrameCount ()
{
Assert.AreEqual (1, trace.FrameCount, "Frame count");
}
[Test]
public void GetFrame_OutOfRange ()
{
Assert.IsNull (trace.GetFrame (-1), "-1");
Assert.IsNull (trace.GetFrame (-129), "-129");
Assert.IsNull (trace.GetFrame (1), "1");
Assert.IsNull (trace.GetFrame (145), "145");
Assert.IsNull (trace.GetFrame (Int32.MinValue), "MinValue");
Assert.IsNull (trace.GetFrame (Int32.MaxValue), "MaxValue");
}
[Test]
public void GetFrame ()
{
Assert.AreEqual (frame, trace.GetFrame (0), "0");
}
#if NET_2_0
[Test]
public void GetFrames ()
{
StackTrace st = new StackTrace ();
StackFrame[] sf = st.GetFrames ();
Assert.AreEqual (st.FrameCount, sf.Length, "Count");
for (int i=0; i < sf.Length; i++) {
Assert.AreEqual (sf [i], st.GetFrame (i), i.ToString ());
}
}
#endif
[Test]
public void UnthrownException ()
{
Assert.AreEqual (0, new StackTrace (new Exception ()).FrameCount, "Unthrown exception");
}
}
}