⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsystemexceptions.cs

📁 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的
💻 CS
📖 第 1 页 / 共 2 页
字号:
/* * TestSystemExceptions.cs - Tests for exception classes in "System". * * Copyright (C) 2003  Southern Storm Software, Pty Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */using CSUnit;using System;using System.Runtime.Serialization;public class TestSystemExceptions : TestCase{	// Constructor.	public TestSystemExceptions(String name)			: base(name)			{				// Nothing to do here.			}	// Set up for the tests.	protected override void Setup()			{				// Nothing to do here.			}	// Clean up after the tests.	protected override void Cleanup()			{				// Nothing to do here.			}#if !ECMA_COMPAT	// Test the AppDomainUnloadedException class.	public void TestAppDomainUnloadedException()			{				ExceptionTester.CheckMain(typeof(AppDomainUnloadedException),										  unchecked((int)0x80131014));			}#endif	// Test the ApplicationException class.	public void TestApplicationException()			{				ExceptionTester.CheckMain(typeof(ApplicationException),										  unchecked((int)0x80131600));			}	// Test the ArgumentException class.	public void TestArgumentException()			{				ArgumentException e;				ExceptionTester.CheckMain(typeof(ArgumentException),										  unchecked((int)0x80070057));				e = new ArgumentException();				AssertNull("ArgumentException (1)", e.ParamName);				e = new ArgumentException("msg");				AssertNull("ArgumentException (2)", e.ParamName);				e = new ArgumentException("msg", "p");				AssertEquals("ArgumentException (3)", "p", e.ParamName);				e = new ArgumentException("msg", "p", e);				AssertEquals("ArgumentException (4)", "p", e.ParamName);			}	// Test the ArgumentNullException class.	public void TestArgumentNullException()			{				ArgumentNullException e;				e = new ArgumentNullException();				AssertNull("ArgumentNullException (1)", e.ParamName);				AssertNotNull("ArgumentNullException (2)", e.Message);				ExceptionTester.CheckHResult						("ArgumentNullException (3)", e,						 unchecked((int)0x80004003));				e = new ArgumentNullException("p");				AssertEquals("ArgumentNullException (4)", "p", e.ParamName);				AssertNotNull("ArgumentNullException (5)", e.Message);				ExceptionTester.CheckHResult						("ArgumentNullException (6)", e,						 unchecked((int)0x80004003));				e = new ArgumentNullException("p", "msg");				AssertEquals("ArgumentNullException (7)", "p", e.ParamName);				AssertEquals("ArgumentNullException (8)", "msg", e.Message);				ExceptionTester.CheckHResult						("ArgumentNullException (9)", e,						 unchecked((int)0x80004003));			}	// Test the ArgumentOutOfRangeException class.	public void TestArgumentOutOfRangeException()			{				ArgumentOutOfRangeException e;				e = new ArgumentOutOfRangeException();				AssertNull("ArgumentOutOfRangeException (1)", e.ParamName);				AssertNotNull("ArgumentOutOfRangeException (2)", e.Message);				AssertNull("ArgumentOutOfRangeException (3)", e.ActualValue);				ExceptionTester.CheckHResult						("ArgumentOutOfRangeException (4)", e,						 unchecked((int)0x80131502));				e = new ArgumentOutOfRangeException("p");				AssertEquals("ArgumentOutOfRangeException (5)",							 "p", e.ParamName);				AssertNotNull("ArgumentOutOfRangeException (6)", e.Message);				AssertNull("ArgumentOutOfRangeException (7)", e.ActualValue);				ExceptionTester.CheckHResult						("ArgumentOutOfRangeException (8)", e,						 unchecked((int)0x80131502));				e = new ArgumentOutOfRangeException("p", "msg");				AssertEquals("ArgumentOutOfRangeException (9)",							 "p", e.ParamName);				AssertEquals("ArgumentOutOfRangeException (10)",							 "msg", e.Message);				AssertNull("ArgumentOutOfRangeException (11)", e.ActualValue);				ExceptionTester.CheckHResult						("ArgumentOutOfRangeException (12)", e,						 unchecked((int)0x80131502));				e = new ArgumentOutOfRangeException("p", 3, "msg");				AssertEquals("ArgumentOutOfRangeException (13)",							 "p", e.ParamName);				Assert("ArgumentOutOfRangeException (14)",					   e.Message.StartsWith("msg"));				AssertEquals("ArgumentOutOfRangeException (15)",							 3, e.ActualValue);				ExceptionTester.CheckHResult						("ArgumentOutOfRangeException (16)", e,						 unchecked((int)0x80131502));			}	// Test the ArithmeticException class.	public void TestArithmeticException()			{				ExceptionTester.CheckMain(typeof(ArithmeticException),										  unchecked((int)0x80070216));			}	// Test the ArrayTypeMismatchException class.	public void TestArrayTypeMismatchException()			{				ExceptionTester.CheckMain(typeof(ArrayTypeMismatchException),										  unchecked((int)0x80131503));			}	// Test the BadImageFormatException class.	public void TestBadImageFormatException()			{				BadImageFormatException e;				ExceptionTester.CheckMain(typeof(BadImageFormatException),										  unchecked((int)0x8007000b));				e = new BadImageFormatException();				AssertNull("BadImageFormatException (1)", e.FileName);				e = new BadImageFormatException("msg");				AssertNull("BadImageFormatException (2)", e.FileName);				e = new BadImageFormatException("msg", "file");				AssertEquals("BadImageFormatException (3)", "file", e.FileName);				e = new BadImageFormatException("msg", "file", e);				AssertEquals("BadImageFormatException (4)", "file", e.FileName);			}	// Test the CannotUnloadAppDomainException class.	public void TestCannotUnloadAppDomainException()			{				ExceptionTester.CheckMain						(typeof(CannotUnloadAppDomainException),						 unchecked((int)0x80131015));			}#if CONFIG_REMOTING	// Test the ContextMarshalException class.	public void TestContextMarshalException()			{				ExceptionTester.CheckMain(typeof(ContextMarshalException),										  unchecked((int)0x80131504));			}#endif	// Test the DivideByZeroException class.	public void TestDivideByZeroException()			{				ExceptionTester.CheckMain(typeof(DivideByZeroException),										  unchecked((int)0x80020012));			}	// Test the DllNotFoundException class.	public void TestDllNotFoundException()			{				ExceptionTester.CheckMain(typeof(DllNotFoundException),										  unchecked((int)0x80131524));			}	// Test the DuplicateWaitObjectException class.	public void TestDuplicateWaitObjectException()			{				DuplicateWaitObjectException e;				e = new DuplicateWaitObjectException();				AssertNull("DuplicateWaitObjectException (1)", e.ParamName);				AssertNotNull("DuplicateWaitObjectException (2)", e.Message);				ExceptionTester.CheckHResult						("DuplicateWaitObjectException (3)", e,						 unchecked((int)0x80131529));				e = new DuplicateWaitObjectException("p");				AssertEquals("DuplicateWaitObjectException (4)",							 "p", e.ParamName);				AssertNotNull("DuplicateWaitObjectException (5)", e.Message);				ExceptionTester.CheckHResult						("DuplicateWaitObjectException (6)", e,						 unchecked((int)0x80131529));				e = new DuplicateWaitObjectException("p", "msg");				AssertEquals("DuplicateWaitObjectException (7)",							 "p", e.ParamName);				AssertEquals("DuplicateWaitObjectException (8)",							 "msg", e.Message);				ExceptionTester.CheckHResult						("DuplicateWaitObjectException (9)", e,						 unchecked((int)0x80131529));			}	// Test the EntryPointNotFoundException class.	public void TestEntryPointNotFoundException()			{				ExceptionTester.CheckMain(typeof(EntryPointNotFoundException),										  unchecked((int)0x80131523));			}	// Test the Exception class.	public void TestException()			{				ExceptionTester.CheckMain(typeof(Exception),										  unchecked((int)0x80131500));			#if !ECMA_COMPAT				// Test the properties of a non-thrown exception.				Exception e = new Exception();				AssertNull("TestException (1)", e.HelpLink);				e.HelpLink = "foo";				AssertEquals("TestException (2)", "foo", e.HelpLink);				e.HelpLink = "bar";				AssertEquals("TestException (3)", "bar", e.HelpLink);				AssertNull("TestException (4)", e.Source);				AssertNull("TestException (5)", e.TargetSite);				AssertEquals("TestException (6)",							 String.Empty, e.StackTrace);				e.Source = "src";				AssertEquals("TestException (7)", "src", e.Source);				// Test the properties of a thrown exception.				Exception e2 = null;				try				{					throw new Exception();				}				catch(Exception e3)				{					e2 = e3;				}				AssertNotNull("TestException (8)", e2);				AssertNotNull("TestException (9)", e2.Source);				Assert("TestException (10)",					   e2.Source.StartsWith("Testruntime, Version="));				AssertNotNull("TestException (11)", e2.TargetSite);				AssertEquals("TestException (12)",							 "Void TestException()", e2.TargetSite.ToString());				Assert("TestException (13)",					   e2.StackTrace != String.Empty);			#endif			}	// Test the ExecutionEngineException class.	public void TestExecutionEngineException()			{				ExceptionTester.CheckMain(typeof(ExecutionEngineException),										  unchecked((int)0x80131506));			}	// Test the FieldAccessException class.	public void TestFieldAccessException()			{				ExceptionTester.CheckMain(typeof(FieldAccessException),										  unchecked((int)0x80131507));			}	// Test the FormatException class.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -