[Mono-dev] Compiling Mono Runtime in VS2010

Guy Sherman guy at guysherman.com
Sun Jun 27 20:27:36 EDT 2010


Hi All,

I managed to compile a 64-bit version of the mono runtime, using Visual
Studio 2008, and I am having a great time working out how to embed mono.
However, I am using Visual Studio 2010 for my solution, and whenever I call
free on a pointer allocated by the runtime (like a MonoClass*), I get a
failed debug assertion which has something to do with heap corruption, and
something to do with code within the same process being from different
versions of the C runtime (2008 vs 2010 I guess).

So, my question is this: has anyone managed to compile the mono runtime in
Visual Studio 2010 yet? I tried a couple of weeks ago but couldn't, there
was some phantom syntax error, which didn't appear in Visual Studio 2008.

As an aside, when trying to call g_free, I get an unresolved externals
error despite the fact that the path to glib-2.0.lib is definitely in my
project settings. Could this be because the glib libs that ship with mono
for windows a 32-bit, and I'm trying to compile 64-bit?

Thanks very much in advance,

Guy Sherman.

On Sun, 27 Jun 2010 08:25:01 -0400,
mono-devel-list-request at lists.ximian.com wrote:
> Send Mono-devel-list mailing list submissions to
> 	mono-devel-list at lists.ximian.com
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.ximian.com/mailman/listinfo/mono-devel-list
> or, via email, send a message with subject or body 'help' to
> 	mono-devel-list-request at lists.ximian.com
> 
> You can reach the person managing the list at
> 	mono-devel-list-owner at lists.ximian.com
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Mono-devel-list digest..."
> 
> 
> Today's Topics:
> 
>    1. Re:  Proposed Patch - Google Native Client (Rafael Teixeira)
>    2. Re:  [PATCH] mono_debugger_agent_thread_interrupt	signature
>       mismatch (Zoltan Varga)
>    3.  svn trunk build fails, 'SIGPWR' undeclared (KISHIMOTO, Makoto)
>    4. Re:  Patch 2/2 - Tests for System.Diagnostics.Contracts in
>       corlib (Chris Bacon)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Fri, 25 Jun 2010 12:31:55 -0300
> From: Rafael Teixeira <monoman at gmail.com>
> Subject: Re: [Mono-dev] Proposed Patch - Google Native Client
> To: Elijah Taylor <elijahtaylor at google.com>
> Cc: mono-devel-list at lists.ximian.com
> Message-ID:
> 	<AANLkTimd6AxafFDFxmY4w88kgWr6_aRcykkXkd2jzKUi at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Looks promising, thanks for the effort, and specially the stricter
checks
> result summary.
> 
> Rafael "Monoman" Teixeira
> ---------------------------------------
> "To be creative means to be in love with life. You can be creative only
if
> you love life enough that you want to enhance its beauty, you want to
bring
> a little more music to it, a little more poetry to it, a little more
dance
> to it."
> Osho
> 
> 
> On Tue, Jun 22, 2010 at 2:29 PM, Elijah Taylor
> <elijahtaylor at google.com>wrote:
> 
>> Greetings Mono Developers,
>>
>> Attached is a patch to support 32-bit x86 code generation for Google
>> Native
>> Client (http://code.google.com/p/nativeclient/).  I encourage you to
>> browse our project for more information if you're curious.  I apologize
>> for
>> the large diff, let me try to explain the highlights to make it easier
to
>> digest.
>>
>> There is a code generation component (define:
__native_client_codegen__)
>> which affects the Mono bytecode -> native code generation for x86-32. 
>> There
>> are a set of alignment restrictions, illegal instructions, and
>> replacement
>> instructions we use for Native Client to ensure proper control-flow
>> sandboxing.  Please see
>>
http://nativeclient.googlecode.com/svn/data/docs_tarball/nacl/googleclient/native_client/documentation/nacl_paper.pdffor
>> more details.
>>
>> There is also a runtime component (define: __native_client__) which
>> modifies or disables some functionality to be compatible with the
Native
>> Client runtime.
>>
>> We also had to modify some code that doesn't fall under either of the
>> above
>> defines.  Most of these changes revolved around type safety.  The
>> modified
>> version of gcc we use to compile Native Client modules is more strict
>> about
>> types, and it caught what look like legitimate issues with the Mono
>> codebase.  The largest issue in terms of number of errors was the use
of
>> mono_bool and gboolean interchangeably between declaration and
>> definition of
>> many functions.  gboolean is defined as an "int" but mono_bool is
>> defined as
>> int32_t.  Other type issues are listed directly below.  Feedback is
>> appreciated on these changes because of our unfamiliarity with this
code,
>> but I modified these in the way that seemed most "right" at the time.
>>
>> mono/metadata/decimal.h:47 mono_decimal2string int -> gint32
>> mono/metadata/filewatcher.h:28 gboolean -> int
>> mono/metadata/filewatcher.c:158 int32 -> gint32
>> mono/metadata/threads-type.h:64 int -> gint32
>>
>> mono/mini/mini.h:1546  gboolean sort_end -> int sort_type
>> mono/mini/mini.h:1733  gboolean fp -> int bank
>>
>> The last bit of modification is to genmdesc and the Makefiles in
general.
>> We added a new flag to genmdesc called "nacl" which overrides the given
>> max
>> length of an instruction.  Native Client code tends to be larger
because
>> of
>> some of the instruction requirements we have, so some of the
>> instructions in
>> cpu-x86.md had to be modified.  This is all tied to a new configure
flag
>> called "--enable-nacl-codegen", which enables the codegen define, and
>> sets
>> up calls to genmdesc with a --nacl flag.  It also modifies the
>> mono-wrapper
>> script so one aspect of our code generation rules (masking jump targets
>> to
>> 32-byte boundaries) is turned off while compiling and testing mono from
>> the
>> Makefiles, which is required when testing outside of the Native Client
>> environment.  We're also including a standalone check "fsacheck" which
>> tests
>> mono code generation as full AOT and a the library linked into a fully
>> static executable.
>>
>>
>> I look forward to your comments, questions, and suggestions.
>>
>>
>> -Elijah Taylor
>> Google Native Client Team
>>
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
>
http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100625/d8b3eee7/attachment-0001.html
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Fri, 25 Jun 2010 21:17:43 +0200
> From: Zoltan Varga <vargaz at gmail.com>
> Subject: Re: [Mono-dev] [PATCH] mono_debugger_agent_thread_interrupt
> 	signature mismatch
> To: Angus <wangdongming at hipihi.com>
> Cc: mono-devel-list at lists.ximian.com
> Message-ID:
> 	<AANLkTikvPoA6VQwJPRhL3ELDx4--A5BjKoL3Eb_jLQMI at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> No idea, probably the same as on linux.
> 
>             Zoltan
> 
> On Thu, Apr 15, 2010 at 3:50 AM, Angus <wangdongming at hipihi.com> wrote:
> 
>>
>> HI,I'm so sorry to bother you .
>> Could you tell me how to use the --debugger-agent command in windows?
>> Thanks.
>> --
>> View this message in context:
>>
http://n4.nabble.com/PATCH-mono-debugger-agent-thread-interrupt-signature-mismatch-tp1523348p1840703.html
>> Sent from the Mono - Dev mailing list archive at Nabble.com.
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
>
http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100625/7fa587a4/attachment-0001.html
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sat, 26 Jun 2010 11:36:17 +0900
> From: "KISHIMOTO, Makoto" <ksmakoto at dd.iij4u.or.jp>
> Subject: [Mono-dev] svn trunk build fails, 'SIGPWR' undeclared
> To: mono-devel-list at lists.ximian.com
> Message-ID: <20100626113617.be122cd2.ksmakoto at dd.iij4u.or.jp>
> Content-Type: text/plain; charset=US-ASCII
> 
> Hello,
> 
> In my FreeBSD box, mono SVN trunk build fails. FreeBSD has no SIGPWR .
> Signal 29 of FreeBSD is SIGINFO .
> 
> ../../doltlibtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.
> -I../../../mono/mono/metadata -I../.. -I../../../mono
-I../../../mono/mono
> -I../../../mono/libgc/include -I../../../mono/eglib/src
-I../../eglib/src
> -DMONO_BINDIR=\"/usr/local/bin/\" -DMONO_ASSEMBLIES=\"/usr/local/lib\"
> -DMONO_CFG_DIR=\"/usr/local/etc\"  -DGC_FREEBSD_THREADS -DPLATFORM_BSD 
> -DHAVE_SGEN_GC -DHAVE_MOVING_COLLECTOR -DHAVE_WRITE_BARRIERS -g -O2
> -fno-strict-aliasing -Wdeclaration-after-statement -g -Wall -Wunused
> -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes 
> -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual
> -Wwrite-strings -mno-tls-direct-seg-refs -MT
> libmonoruntimesgen_la-sgen-os-posix.lo -MD -MP -MF
> .deps/libmonoruntimesgen_la-sgen-os-posix.Tpo -c -o
> libmonoruntimesgen_la-sgen-os-posix.lo `test -f 'sgen-os-posix.c' ||
echo
> '../../../mono/mono/metadata/'`sgen-os-posix.c
> In file included from ../../../mono/mono/metadata/sgen-os-posix.c:35:
> ../../../mono/mono/metadata/sgen-gc.h:93: error: 'SIGPWR' undeclared
here
> (not in a function)
> gmake[3]: *** [libmonoruntimesgen_la-sgen-os-posix.lo] Error 1
> gmake[3]: Leaving directory
> `/export/home/ksmakoto/Mono/BUILD/mono/metadata'
> gmake[2]: *** [all-recursive] Error 1
> gmake[2]: Leaving directory `/export/home/ksmakoto/Mono/BUILD/mono'
> gmake[1]: *** [all-recursive] Error 1
> gmake[1]: Leaving directory `/export/home/ksmakoto/Mono/BUILD'
> gmake: *** [all] Error 2
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Sun, 27 Jun 2010 13:24:48 +0100
> From: Chris Bacon <chris at dunelm.org.uk>
> Subject: Re: [Mono-dev] Patch 2/2 - Tests for
> 	System.Diagnostics.Contracts in corlib
> To: Miguel de Icaza <miguel at novell.com>
> Cc: Marek Safar <marek.safar at seznam.cz>,
> 	mono-devel-list at lists.ximian.com,	miguel.novell at gmail.com
> Message-ID: <4C274310.40900 at dunelm.org.uk>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi,
> 
> Last Thursday, 24th, I followed these instructions and sent my public 
> SSH key to miguel at ximian.com.
> Should I expect to hear something back?
> 
> Thanks
> Chris
> 
> Miguel de Icaza wrote:
>> Hey Chris,
>>
>>     Could you get these commited yourself?
>>
>>     For this you will need an SVN key, follow the steps here:
>>
>> 	www.mono-project.com/SVN
>>
>>   
>>> Hi,
>>>
>>> Updated patch attached. I've checked that all tests still pass.
>>>
>>> The delegate has been removed, and #if NET_4_0 now surrounds the whole

>>> of each file.
>>>
>>> However, the #defines are not un-defined at the end of each file, as I

>>> don't think this is possible in C#, as all #define and #undef
>>> statements
>>> have to be before any code. Please let me know if there is a way of 
>>> #undef-ing another way.
>>>
>>> Thanks
>>> Chris
>>>
>>> Marek Safar wrote:
>>>     
>>>> Hello Chris,
>>>>
>>>> Only a few small issues
>>>>
>>>> +#define CONTRACTS_FULL
>>>> +#define DEBUG
>>>> +
>>>>
>>>> Undefined these at the end of each file. They perhaps should be
inside 
>>>> #if NET_4_0 too.
>>>>
>>>> +        // Required when compiling/running under .NET3.5
>>>> +        delegate void Action<T1, T2, T3, T4, T5> (T1 arg1, T2 arg2, 
>>>> T3 arg3, T4 arg4, T5 arg5);
>>>> +
>>>>
>>>> Why is it needed when NET_4_0 is used for whole file ?
>>>>
>>>> When fixed please commit. Thanks!
>>>>
>>>> Marek
>>>>
>>>>       
>>>>> Hi,
>>>>> I've attached a new patch with slightly better formatting - it uses 
>>>>> tabs rather than spaces.
>>>>> Kind regards
>>>>> Chris
>>>>>
>>>>> Chris Bacon wrote:
>>>>>         
>>>>>> Hi,
>>>>>>
>>>>>> Here are the tests to add to corlib for
System.Diagnostics.Contracts.
>>>>>>
>>>>>> Please let me know what changes are required.
>>>>>>
>>>>>> Kind regards
>>>>>> Chris
>>>>>>
------------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Mono-devel-list mailing list
>>>>>> Mono-devel-list at lists.ximian.com
>>>>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>>>>           
>>>>>
------------------------------------------------------------------------
>>>>>
>>>>> _______________________________________________
>>>>> Mono-devel-list mailing list
>>>>> Mono-devel-list at lists.ximian.com
>>>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>>>         
>>> plain text document attachment (CodeContractsTest.patch)
>>> Index: corlib_test.dll.sources
>>> ===================================================================
>>> --- corlib_test.dll.sources	(revision 159418)
>>> +++ corlib_test.dll.sources	(working copy)
>>> @@ -60,6 +60,14 @@
>>>  System.Diagnostics/StackFrameTest.cs
>>>  System.Diagnostics/StackTraceTest.cs
>>>  System.Diagnostics/TextWriterTraceListenerTest.cs
>>> +System.Diagnostics.Contracts/ContractAssertTest.cs
>>> +System.Diagnostics.Contracts/ContractAssumeTest.cs
>>> +System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs
>>> +System.Diagnostics.Contracts/ContractHelperTest.cs
>>> +System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs
>>> +System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs
>>> +System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs
>>> +System.Diagnostics.Contracts/Helpers/TestContractBase.cs
>>>  System/DoubleFormatterTest.cs
>>>  System/DoubleTest.cs
>>>  System/EnumTest.cs
>>> Index: Test/System.Diagnostics.Contracts/ContractAssumeTest.cs
>>> ===================================================================
>>> --- Test/System.Diagnostics.Contracts/ContractAssumeTest.cs	(revision
0)
>>> +++ Test/System.Diagnostics.Contracts/ContractAssumeTest.cs	(revision
0)
>>> @@ -0,0 +1,47 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractAssumeTest : TestContractBase {
>>> +
>>> +		/// <summary>
>>> +		/// At runtime Contract.Assume() acts just like a
Contract.Assert(),
>>> except the exact message in the assert
>>> +		/// or exception is slightly different.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestAssumeMessage ()
>>> +		{
>>> +			try {
>>> +				Contract.Assume (false);
>>> +				Assert.Fail ("TestAssumeMessage() exception not thrown #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof(NotImplementedException), ex,
>>> "TestAssumeMessage() wrong exception type #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.Assume (false, "Message");
>>> +				Assert.Fail ("TestAssumeMessage() exception not thrown #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof(NotImplementedException), ex,
>>> "TestAssumeMessage() wrong exception type #1");
>>> +			}
>>> +		}
>>> +
>>> +		// Identical to Contract.Assert, so no more testing required.
>>> +
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractAssumeTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index:
>>> Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs
>>> ===================================================================
>>> ---
>>>
Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs	(revision
>>> 0)
>>> +++
>>>
Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs	(revision
>>> 0)
>>> @@ -0,0 +1,129 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +using System.Diagnostics.Contracts;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractCollectionMethodsTest {
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Exists() determines that at least one element in the
>>> collection satisfies the predicate.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestExistsInt ()
>>> +		{
>>> +			try {
>>> +				Contract.Exists (0, 10, null);
>>> +				Assert.Fail ("TestExistsInt() no exception #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestExistsInt() wrong exception #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.Exists (10, 0, i => false);
>>> +				Assert.Fail ("TestExistsInt() no exception #2");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentException), ex,
>>> "TestExistsInt() wrong exception #2");
>>> +			}
>>> +
>>> +			Assert.IsTrue (Contract.Exists (0, 10, i => i <= 0),
>>> "TestExistsInt() #1");
>>> +			Assert.IsTrue (Contract.Exists (0, 10, i => i >= 9),
>>> "TestExistsInt() #2");
>>> +			Assert.IsFalse (Contract.Exists (0, 10, i => i < 0),
>>> "TestExistsInt() #3");
>>> +			Assert.IsFalse (Contract.Exists (0, 10, i => i > 9),
>>> "TestExistsInt() #4");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Exists() determines that at least one element in the
>>> collection satisfies the predicate.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestExistsEnumeration ()
>>> +		{
>>> +			try {
>>> +				Contract.Exists (Enumerable.Range (0, 10), null);
>>> +				Assert.Fail ("TestExistsEnumeration() no exception #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestExistsEnumeration() wrong exception #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.Exists<int> (null, x => false);
>>> +				Assert.Fail ("TestExistsEnumeration() no exception #2");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestExistsEnumeration() wrong exception #2");
>>> +			}
>>> +
>>> +			var en = Enumerable.Range (0, 10);
>>> +			Assert.IsTrue (Contract.Exists (en, i => i <= 0),
>>> "TestExistsEnumeration() #1");
>>> +			Assert.IsTrue (Contract.Exists (en, i => i >= 9),
>>> "TestExistsEnumeration() #2");
>>> +			Assert.IsFalse (Contract.Exists (en, i => i < 0),
>>> "TestExistsEnumeration() #3");
>>> +			Assert.IsFalse (Contract.Exists (en, i => i > 9),
>>> "TestExistsEnumeration() #4");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.ForAll() determines if all elements in the collection
>>> satisfy the predicate.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestForAllInt ()
>>> +		{
>>> +			try {
>>> +				Contract.ForAll (0, 10, null);
>>> +				Assert.Fail ("TestForAllInt() no exception #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestForAllInt() wrong exception #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.ForAll (10, 0, i => false);
>>> +				Assert.Fail ("TestForAllInt() no exception #2");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentException), ex,
>>> "TestForAllInt() wrong exception #2");
>>> +			}
>>> +
>>> +			Assert.IsTrue (Contract.ForAll (0, 10, i => i <= 9),
>>> "TestForAllInt() #1");
>>> +			Assert.IsTrue (Contract.ForAll (0, 10, i => i >= 0),
>>> "TestForAllInt() #2");
>>> +			Assert.IsFalse (Contract.ForAll (0, 10, i => i < 9),
>>> "TestForAllInt() #3");
>>> +			Assert.IsFalse (Contract.ForAll (0, 10, i => i > 0),
>>> "TestForAllInt() #4");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.ForAll() determines if all elements in the collection
>>> satisfy the predicate.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestForAllEnumeration ()
>>> +		{
>>> +			try {
>>> +				Contract.ForAll (Enumerable.Range (0, 10), null);
>>> +				Assert.Fail ("TestForAllEnumeration() no exception #1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestForAllEnumeration() wrong exception #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.ForAll<int> (null, x => false);
>>> +				Assert.Fail ("TestForAllEnumeration() no exception #2");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException), ex,
>>> "TestForAllEnumeration() wrong exception #2");
>>> +			}
>>> +
>>> +			var en = Enumerable.Range (0, 10);
>>> +			Assert.IsTrue (Contract.ForAll (en, i => i <= 9),
>>> "TestForAllEnumeration() #1");
>>> +			Assert.IsTrue (Contract.ForAll (en, i => i >= 0),
>>> "TestForAllEnumeration() #2");
>>> +			Assert.IsFalse (Contract.ForAll (en, i => i < 9),
>>> "TestForAllEnumeration() #3");
>>> +			Assert.IsFalse (Contract.ForAll (en, i => i > 0),
>>> "TestForAllEnumeration() #4");
>>> +		}
>>> +
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index: Test/System.Diagnostics.Contracts/ContractHelperTest.cs
>>> ===================================================================
>>> --- Test/System.Diagnostics.Contracts/ContractHelperTest.cs	(revision
0)
>>> +++ Test/System.Diagnostics.Contracts/ContractHelperTest.cs	(revision
0)
>>> @@ -0,0 +1,258 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts.Internal;
>>> +using System.Diagnostics.Contracts;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +using NUnit.Framework.Constraints;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractHelperTest : TestContractBase {
>>> +
>>> +		private void CheckAllMessages (ContractFailureKind kind, string
>>> messageStart, Action<string, Exception, string, ContractFailureKind,
>>> Func<string>> fnAssert)
>>> +		{
>>> +
>>> +			foreach (Exception ex in new [] { null, new ArgumentNullException
>>> () }) {
>>> +				fnAssert (messageStart + ".", ex, null, kind, () => {
>>> +					return ContractHelper.RaiseContractFailedEvent (kind, null,
null,
>>> ex);
>>> +				});
>>> +
>>> +				fnAssert (messageStart + ".  Message", ex, null, kind, () => {
>>> +					return ContractHelper.RaiseContractFailedEvent (kind, "Message",
>>> null, ex);
>>> +				});
>>> +
>>> +				fnAssert (messageStart + ": Condition", ex, "Condition", kind, ()
>>> => {
>>> +					return ContractHelper.RaiseContractFailedEvent (kind, null,
>>> "Condition", ex);
>>> +				});
>>> +
>>> +				fnAssert (messageStart + ": Condition  Message", ex, "Condition",
>>> kind, () => {
>>> +					return ContractHelper.RaiseContractFailedEvent (kind, "Message",
>>> "Condition", ex);
>>> +				});
>>> +			}
>>> +
>>> +		}
>>> +
>>> +		private void CheckAllKinds (Action<string, Exception, string,
>>> ContractFailureKind, Func<string>> fnAssert)
>>> +		{
>>> +			this.CheckAllMessages (ContractFailureKind.Assert, "Assertion
>>> failed", fnAssert);
>>> +			this.CheckAllMessages (ContractFailureKind.Assume, "Assumption
>>> failed", fnAssert);
>>> +			this.CheckAllMessages (ContractFailureKind.Invariant, "Invariant
>>> failed", fnAssert);
>>> +			this.CheckAllMessages (ContractFailureKind.Postcondition,
>>> "Postcondition failed", fnAssert);
>>> +			this.CheckAllMessages
>>> (ContractFailureKind.PostconditionOnException, "Postcondition failed
>>> after throwing an exception", fnAssert);
>>> +			this.CheckAllMessages (ContractFailureKind.Precondition,
>>> "Precondition failed", fnAssert);
>>> +		}
>>> +
>>> +		private void CheckAllKinds (Action<string, Exception, Func<string>>
>>> fnAssert)
>>> +		{
>>> +			this.CheckAllKinds ((expected, ex, condition, kind, fnTest) =>
>>> fnAssert (expected, ex, fnTest));
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// If no event handler is present, then the string returned
>>> describes the condition failure.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractFailedEventNoHandler ()
>>> +		{
>>> +			this.CheckAllKinds ((expected, ex, fnTest) => {
>>> +				string msg = fnTest ();
>>> +				Assert.AreEqual (expected, msg,
>>> "TestRaiseContractFailedEventNoHandler() incorrect message");
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// When SetHandled() is called, null is returned.
>>> +		/// The event args are also checked.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractFailedEventHandled ()
>>> +		{
>>> +			string expectedMsg = null;
>>> +			Exception originalException = null;
>>> +			string expectedCondition = null;
>>> +			ContractFailureKind expectedKind = ContractFailureKind.Assert;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				Assert.AreEqual (expectedMsg, e.Message,
>>> "TestRaiseContractFailedEventHandled() event message wrong");
>>> +				Assert.AreSame (originalException, e.OriginalException,
>>> "TestRaiseContractFailedEventHandled() event exception wrong");
>>> +				Assert.AreEqual (expectedCondition, e.Condition,
>>> "TestRaiseContractFailedEventHandled() event condition wrong");
>>> +				Assert.AreEqual (expectedKind, e.FailureKind,
>>> "TestRaiseContractFailedEventHandled() event failure kind wrong");
>>> +				e.SetHandled ();
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, ex, condition, kind, fnTest) => {
>>> +				expectedMsg = expected;
>>> +				originalException = ex;
>>> +				expectedCondition = condition;
>>> +				expectedKind = kind;
>>> +				string msg = fnTest ();
>>> +				Assert.IsNull (msg, "TestRaiseContractFailedEventHandled()
>>> expected null message");
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// When SetUnwind() is called, a ContractException is thrown. If
an
>>> innerException is passed, then
>>> +		/// it is put in the InnerException of the ContractException.
>>> Otherwise, the InnerException is set to null.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractFailedEventUnwind ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				e.SetUnwind ();
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, expectedEx, fnTest) => {
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("TestRaiseContractFailedEventUnwind() exception not
>>> thrown");
>>> +				} catch (Exception ex) {
>>> +					Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestRaiseContractFailedEventUnwind() wrong exception type");
>>> +					if (expectedEx == null) {
>>> +						Assert.IsNull (ex.InnerException,
>>> "TestRaiseContractFailedEventUnwind() inner exception should be
null");
>>> +					} else {
>>> +						Assert.AreSame (expectedEx, ex.InnerException,
>>> "TestRaiseContractFailedEventUnwind() wrong inner exception type");
>>> +					}
>>> +				}
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// When the ContractFailed event throws an exception, then it
>>> becomes the inner exception of the
>>> +		/// ContractException. Except if an exception is passed in to the
>>> call, then that exception is put
>>> +		/// in the InnerException.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractFailedEventThrows ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				throw new InvalidOperationException ();
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, expectedEx, fnTest) => {
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("TestRaiseContractFailedEventThrows() exception not
>>> thrown");
>>> +				} catch (Exception ex) {
>>> +					Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestRaiseContractFailedEventThrows() wrong exception type");
>>> +					Type expectedInnerExceptionType = expectedEx == null ? typeof
>>> (InvalidOperationException) : expectedEx.GetType ();
>>> +					Assert.IsInstanceOfType (expectedInnerExceptionType,
>>> ex.InnerException, "TestRaiseContractFailedEventThrows() wrong inner
>>> exception type");
>>> +				}
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Both event handlers should be called, constraint is not
handled.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractMultipleHandlers1 ()
>>> +		{
>>> +			bool visited1, visited2;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited1 = true;
>>> +			};
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited2 = true;
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, ex, fnTest) => {
>>> +				visited1 = visited2 = false;
>>> +				string msg = fnTest ();
>>> +				Assert.AreEqual (expected, msg,
>>> "TestRaiseContractMultipleHandlers1() msg not as expected");
>>> +				Assert.IsTrue (visited1, "TestRaiseContractMultipleHandlers1()
>>> handler 1 not visited");
>>> +				Assert.IsTrue (visited2, "TestRaiseContractMultipleHandlers1()
>>> handler 2 not visited");
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Both event handlers should be called. SetUnwind() takes
>>> precedent over SetHandled().
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractMultipleHandlers2 ()
>>> +		{
>>> +			bool visited1, visited2;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited1 = true;
>>> +				e.SetHandled ();
>>> +			};
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited2 = true;
>>> +				e.SetUnwind ();
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, expectedEx, fnTest) => {
>>> +				visited1 = visited2 = false;
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("TestRaiseContractMultipleHandlers2() exception not
>>> thrown");
>>> +				} catch (Exception ex) {
>>> +					Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestRaiseContractMultipleHandlers2() wrong exception type");
>>> +					if (expectedEx == null) {
>>> +						Assert.IsNull (ex.InnerException,
>>> "TestRaiseContractMultipleHandlers2() inner exception not null");
>>> +					} else {
>>> +						Assert.AreSame (expectedEx, ex.InnerException,
>>> "TestRaiseContractMultipleHandlers2() wrong inner exception");
>>> +					}
>>> +					Assert.IsTrue (visited1, "TestRaiseContractMultipleHandlers2()
>>> handler 1 not visited");
>>> +					Assert.IsTrue (visited2, "TestRaiseContractMultipleHandlers2()
>>> handler 2 not visited");
>>> +				}
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Both event handlers should be called. The exceptions are
treated
>>> as calls to SetUnwind(), with
>>> +		/// the exception being put in the InnerException.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestRaiseContractMultipleHandlers3 ()
>>> +		{
>>> +			bool visited1, visited2;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited1 = true;
>>> +				throw new InvalidOperationException ();
>>> +			};
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited2 = true;
>>> +				throw new InvalidOperationException ();
>>> +			};
>>> +
>>> +			this.CheckAllKinds ((expected, expectedEx, fnTest) => {
>>> +				visited1 = visited2 = false;
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("TestRaiseContractMultipleHandlers3() failed to
>>> throw exception");
>>> +				} catch (Exception ex) {
>>> +					Type expectedInnerExceptionType = expectedEx == null ? typeof
>>> (InvalidOperationException) : expectedEx.GetType ();
>>> +					Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestRaiseContractMultipleHandlers3() wrong exception type");
>>> +					Assert.IsInstanceOfType (expectedInnerExceptionType,
>>> ex.InnerException, "TestRaiseContractMultipleHandlers3() wrong inner
>>> exception type");
>>> +					Assert.IsTrue (visited1, "TestRaiseContractMultipleHandlers3()
>>> handler 1 not visited");
>>> +					Assert.IsTrue (visited2, "TestRaiseContractMultipleHandlers3()
>>> handler 2 not visited");
>>> +				}
>>> +			});
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.TriggerFailure() triggers the assert. Check that the
>>> assert is triggered, with the correct text.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestTriggerFailure ()
>>> +		{
>>> +			try {
>>> +				ContractHelper.TriggerFailure (ContractFailureKind.Assert,
>>> "Display", null, "Condition", null);
>>> +				Assert.Fail ("TestTriggerFailure() failed to throw exception");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType(typeof(NotImplementedException), ex,
>>> "TestTriggerFailure() wrong exception type");
>>> +				//Assert.AreEqual ("Expression: Condition" + Environment.NewLine
+
>>> "Description: Display", ex.Message, "TestTriggerFailure() wrong
>>> message");
>>> +			}
>>> +		}
>>> +
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractHelperTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index:
>>>
Test/System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs
>>> ===================================================================
>>> ---
>>>
Test/System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs	(revision
>>> 0)
>>> +++
>>>
Test/System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs	(revision
>>> 0)
>>> @@ -0,0 +1,18 @@
>>> +#if NET_4_0
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts.Helpers {
>>> +
>>> +	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
>>> +	class RunAgainstReferenceAttribute : CategoryAttribute
>>> +	{
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>>
Test/System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index: Test/System.Diagnostics.Contracts/Helpers/TestContractBase.cs
>>> ===================================================================
>>> ---
>>>
Test/System.Diagnostics.Contracts/Helpers/TestContractBase.cs	(revision
>>> 0)
>>> +++
>>>
Test/System.Diagnostics.Contracts/Helpers/TestContractBase.cs	(revision
>>> 0)
>>> @@ -0,0 +1,48 @@
>>> +#if NET_4_0
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts;
>>> +using System.Diagnostics;
>>> +using System.Reflection;
>>> +using System.Diagnostics.Contracts.Internal;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts.Helpers {
>>> +
>>> +	public class TestContractBase {
>>> +
>>> +		protected TestContractBase() {
>>> +			// Get the type of System.Diagnostics.Contracts.ContractException
>>> +			// Have to do this differently depending on how the test is being
>>> run.
>>> +			this.ContractExceptionType =
>>> Type.GetType("System.Diagnostics.Contracts.ContractException");
>>> +			if (this.ContractExceptionType == null) {
>>> +				// Special code for when Contracts namespace is not in CorLib
>>> +				var mGetContractExceptionType = typeof (Contract).GetMethod
>>> ("GetContractExceptionType", BindingFlags.NonPublic |
>>> BindingFlags.Static);
>>> +				this.ContractExceptionType = (Type)
>>> mGetContractExceptionType.Invoke (null, null);
>>> +			}
>>> +		}
>>> +
>>> +		[SetUp]
>>> +		public void Setup() {
>>> +			// Remove all event handlers from Contract.ContractFailed
>>> +			var eventField = typeof(Contract).GetField("ContractFailed",
>>> BindingFlags.Static | BindingFlags.NonPublic);
>>> +			if (eventField == null) {
>>> +				// But in MS.NET it's done this way.
>>> +				eventField =
>>> typeof(ContractHelper).GetField("contractFailedEvent",
>>> BindingFlags.Static | BindingFlags.NonPublic);
>>> +			}
>>> +			eventField.SetValue(null, null);
>>> +		}
>>> +
>>> +		[TearDown]
>>> +		public void TearDown() {
>>> +		}
>>> +
>>> +		protected Type ContractExceptionType { get; private set; }
>>> +
>>> +	}
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/Helpers/TestContractBase.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index: Test/System.Diagnostics.Contracts/ContractAssertTest.cs
>>> ===================================================================
>>> --- Test/System.Diagnostics.Contracts/ContractAssertTest.cs	(revision
0)
>>> +++ Test/System.Diagnostics.Contracts/ContractAssertTest.cs	(revision
0)
>>> @@ -0,0 +1,175 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts;
>>> +using System.Diagnostics;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractAssertTest : TestContractBase {
>>> +
>>> +		/// <summary>
>>> +		/// Ensures that Assert(true) allows execution to continue.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertTrue ()
>>> +		{
>>> +			Contract.Assert (true);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Assert(false) will cause an assert to be triggered
with
>>> the correct message.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestAssertNoEventHandler ()
>>> +		{
>>> +			try {
>>> +				Contract.Assert (false);
>>> +				Assert.Fail ("TestAssertNoEventHandler() exception not thrown
#1");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (NotImplementedException), ex,
>>> "TestAssertNoEventHandler() wrong exception type #1");
>>> +			}
>>> +
>>> +			try {
>>> +				Contract.Assert (false, "Message");
>>> +				Assert.Fail ("TestAssertNoEventHandler() exception not thrown
#2");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (NotImplementedException), ex,
>>> "TestAssertNoEventHandler() wrong exception type #2");
>>> +			}
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Assert(true) will not call the ContractFailed event
>>> handler.
>>> +		/// Contract.Assert(false) will call the ContractFailed event
>>> handler.
>>> +		/// Because nothing is done in the event handler, an assert should
>>> be triggered.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestAssertEventHandlerNoAction ()
>>> +		{
>>> +			bool visitedEventHandler = false;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visitedEventHandler = true;
>>> +			};
>>> +
>>> +			Contract.Assert (true);
>>> +
>>> +			Assert.IsFalse (visitedEventHandler,
>>> "TestAssertEventHandlerNoAction() handler visited");
>>> +
>>> +			try {
>>> +				Contract.Assert (false);
>>> +				Assert.Fail ("TestAssertEventHandlerNoAction() exception not
>>> thrown");
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (typeof (NotImplementedException), ex,
>>> "TestAssertEventHandlerNoAction() wrong exception type");
>>> +			}
>>> +
>>> +			Assert.IsTrue (visitedEventHandler,
>>> "TestAssertEventHandlerNoAction() handler not visited");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Event handler calls SetHandled(), so no assert should be
>>> triggered.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertEventHandlerSetHandled ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				e.SetHandled ();
>>> +			};
>>> +
>>> +			Contract.Assert (false);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Event handler calls SetUnwind(), so exception of type
>>> ContractException should be thrown.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertEventHandlerSetUnwind ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				e.SetUnwind ();
>>> +			};
>>> +
>>> +			try {
>>> +				Contract.Assert (false);
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestAssertEventHandlerSetUnwind() wrong exception type");
>>> +				Assert.IsNull (ex.InnerException,
>>> "TestAssertEventHandlerSetUnwind() inner exception not null");
>>> +			}
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Event handler calls SetHandled() and SetUnwind(), so exception
>>> of type ContractException should be thrown,
>>> +		/// as SetUnwind overrides SetHandled.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertEventHandlerSetUnwindHandled ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				e.SetHandled ();
>>> +				e.SetUnwind ();
>>> +			};
>>> +
>>> +			try {
>>> +				Contract.Assert (false);
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestAssertEventHandlerSetUnwindHandled() wrong exception type");
>>> +				Assert.IsNull (ex.InnerException,
>>> "TestAssertEventHandlerSetUnwindHandled() inner exception not null");
>>> +			}
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Event handler throws exception.
>>> +		/// ContractException is thrown by Contract.Assert(), with
>>> InnerException set to the thrown exception.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertEventHandlerThrows ()
>>> +		{
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				throw new ArgumentNullException ();
>>> +			};
>>> +
>>> +			try {
>>> +				Contract.Assert (false);
>>> +			} catch (Exception ex) {
>>> +				Assert.IsInstanceOfType (base.ContractExceptionType, ex,
>>> "TestAssertEventHandlerSetUnwindHandled() wrong exception type");
>>> +				Assert.IsInstanceOfType (typeof (ArgumentNullException),
>>> ex.InnerException, "TestAssertEventHandlerSetUnwindHandled() wrong
inner
>>> exception type");
>>> +			}
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Multiple event handlers are registered. Check that both are
>>> called, and that the SetHandled()
>>> +		/// call in one of them is handled correctly.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestAssertMultipleHandlers ()
>>> +		{
>>> +			bool visited1 = false, visited2 = false;
>>> +
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited1 = true;
>>> +				Assert.IsFalse (e.Handled, "TestAssertMultipleHandlers() Handled
>>> incorrect #1");
>>> +				e.SetHandled ();
>>> +			};
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				visited2 = true;
>>> +				Assert.IsTrue (e.Handled, "TestAssertMultipleHandlers() Handled
>>> incorrect #2");
>>> +			};
>>> +
>>> +			Contract.Assert (false);
>>> +
>>> +			Assert.IsTrue (visited1, "TestAssertMultipleHandlers() visited1
>>> incorrect");
>>> +			Assert.IsTrue (visited2, "TestAssertMultipleHandlers() visited2
>>> incorrect");
>>> +		}
>>> +
>>> +	}
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractAssertTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index: Test/System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs
>>> ===================================================================
>>> ---
>>>
Test/System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs	(revision
>>> 0)
>>> +++
>>>
Test/System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs	(revision
>>> 0)
>>> @@ -0,0 +1,76 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractMarkerMethodsTest : TestContractBase {
>>> +
>>> +		/// <summary>
>>> +		/// Contract.EndContractBlock() has no effects.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestEndContractBlock ()
>>> +		{
>>> +			Contract.EndContractBlock ();
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.OldValue() has no effect, and always returns the
>>> default value for the type.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestOldValue ()
>>> +		{
>>> +			int i = Contract.OldValue<int> (8);
>>> +			object o = Contract.OldValue<object> (new object ());
>>> +
>>> +			Assert.AreEqual (0, i, "TestOldValue() int value wrong");
>>> +			Assert.IsNull (o, "TestOldValue() object value wrong");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Result() has no effect, and always returns the default
>>> value for the type.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestResult ()
>>> +		{
>>> +			int i = Contract.Result<int> ();
>>> +			object o = Contract.Result<object> ();
>>> +
>>> +			Assert.AreEqual (0, i, "TestResult() int value wrong");
>>> +			Assert.IsNull (o, "TestResult() object value wrong");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.ValueAtReturn() has no effect, and always returns the
>>> default value for the type.
>>> +		/// </summary>
>>> +		[Test, RunAgainstReference]
>>> +		public void TestValueAtReturn ()
>>> +		{
>>> +			int iOut, i;
>>> +			object oOut, o;
>>> +
>>> +			i = Contract.ValueAtReturn (out iOut);
>>> +			o = Contract.ValueAtReturn (out oOut);
>>> +
>>> +			Assert.AreEqual (0, i, "TestValueAtReturn() int return value
>>> wrong");
>>> +			Assert.IsNull (o, "TestValueAtReturn() object return value
wrong");
>>> +			Assert.AreEqual (0, iOut, "TestValueAtReturn() int out value
>>> wrong");
>>> +			Assert.IsNull (oOut, "TestValueAtReturn() object out value
wrong");
>>> +		}
>>> +
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index: Test/System.Diagnostics.Contracts/ChangeLog
>>> ===================================================================
>>> --- Test/System.Diagnostics.Contracts/ChangeLog	(revision 0)
>>> +++ Test/System.Diagnostics.Contracts/ChangeLog	(revision 0)
>>> @@ -0,0 +1,4 @@
>>> +2010-06-23  Chris Bacon <chrisbacon76 at gmail.com>
>>> +
>>> +	* Added all files
>>> +
>>>
>>> Property changes on: Test/System.Diagnostics.Contracts/ChangeLog
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> Index:
Test/System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs
>>> ===================================================================
>>> ---
>>>
Test/System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs	(revision
>>> 0)
>>> +++
>>>
Test/System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs	(revision
>>> 0)
>>> @@ -0,0 +1,121 @@
>>> +#if NET_4_0
>>> +
>>> +#define CONTRACTS_FULL
>>> +#define DEBUG
>>> +
>>> +using System;
>>> +using System.Collections.Generic;
>>> +using System.Linq;
>>> +using System.Text;
>>> +using NUnit.Framework;
>>> +using System.Diagnostics.Contracts;
>>> +using MonoTests.System.Diagnostics.Contracts.Helpers;
>>> +
>>> +namespace MonoTests.System.Diagnostics.Contracts {
>>> +
>>> +	[TestFixture]
>>> +	public class ContractMustUseRewriterTest : TestContractBase {
>>> +
>>> +		private void CheckMustUseRewriter (string expectedMsg, params
>>> Action[] fnTests)
>>> +		{
>>> +			foreach (var fnTest in fnTests) {
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("CheckMustUseRewriter() exception not thrown");
>>> +				} catch (Exception ex) {
>>> +					Assert.IsInstanceOfType (typeof (NotImplementedException), ex,
>>> "CheckMustUseRewriter() wrong exception thrown");
>>> +				}
>>> +			}
>>> +
>>> +			bool handlerVisited = false;
>>> +			Contract.ContractFailed += (sender, e) => {
>>> +				handlerVisited = true;
>>> +			};
>>> +
>>> +			foreach (var fnTest in fnTests) {
>>> +				try {
>>> +					fnTest ();
>>> +					Assert.Fail ("CheckMustUseRewriter() exception not thrown");
>>> +				} catch (Exception ex) {
>>> +					Assert.IsInstanceOfType (typeof (NotImplementedException), ex,
>>> "CheckMustUseRewriter() wrong exception thrown");
>>> +				}
>>> +			}
>>> +
>>> +			Assert.IsFalse (handlerVisited, "CheckMustUseRewriter() handled
>>> visited");
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Requires() ALWAYS triggers an assert, regardless of
any
>>> other factors.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestRequires ()
>>> +		{
>>> +			CheckMustUseRewriter ("Description: Must use the rewriter when
>>> using Contract.Requires",
>>> +				() => Contract.Requires (true),
>>> +				() => Contract.Requires (false),
>>> +				() => Contract.Requires (true, "Message"),
>>> +				() => Contract.Requires (false, "Message")
>>> +			);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Requires() ALWAYS triggers an assert, regardless of
any
>>> other factors.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestRequiresTException ()
>>> +		{
>>> +			CheckMustUseRewriter ("Description: Must use the rewriter when
>>> using Contract.Requires<TException>",
>>> +				() => Contract.Requires<Exception> (true),
>>> +				() => Contract.Requires<Exception> (false),
>>> +				() => Contract.Requires<Exception> (true, "Message"),
>>> +				() => Contract.Requires<Exception> (false, "Message")
>>> +			);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Ensures() ALWAYS triggers an assert, regardless of any
>>> other factors.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestEnsures ()
>>> +		{
>>> +			CheckMustUseRewriter ("Description: Must use the rewriter when
>>> using Contract.Ensures",
>>> +				() => Contract.Ensures (true),
>>> +				() => Contract.Ensures (false),
>>> +				() => Contract.Ensures (true, "Message"),
>>> +				() => Contract.Ensures (false, "Message")
>>> +			);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Ensures() ALWAYS triggers an assert, regardless of any
>>> other factors.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestEnsuresOnThrow ()
>>> +		{
>>> +			CheckMustUseRewriter ("Description: Must use the rewriter when
>>> using Contract.EnsuresOnThrow",
>>> +				() => Contract.EnsuresOnThrow<Exception> (true),
>>> +				() => Contract.EnsuresOnThrow<Exception> (false),
>>> +				() => Contract.EnsuresOnThrow<Exception> (true, "Message"),
>>> +				() => Contract.EnsuresOnThrow<Exception> (false, "Message")
>>> +			);
>>> +		}
>>> +
>>> +		/// <summary>
>>> +		/// Contract.Ensures() ALWAYS triggers an assert, regardless of any
>>> other factors.
>>> +		/// </summary>
>>> +		[Test]
>>> +		public void TestInvariant ()
>>> +		{
>>> +			CheckMustUseRewriter ("Description: Must use the rewriter when
>>> using Contract.Invariant",
>>> +				() => Contract.Invariant (true),
>>> +				() => Contract.Invariant (false),
>>> +				() => Contract.Invariant (true, "Message"),
>>> +				() => Contract.Invariant (false, "Message")
>>> +			);
>>> +		}
>>> +
>>> +	}
>>> +
>>> +}
>>> +
>>> +#endif
>>>
>>> Property changes on:
>>> Test/System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs
>>> ___________________________________________________________________
>>> Added: svn:eol-style
>>>    + native
>>>
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>     
>>
>>
>>   
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
>
http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100627/1ef5e801/attachment.html
> 
> 
> ------------------------------
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 
> 
> End of Mono-devel-list Digest, Vol 62, Issue 35
> ***********************************************

-- 
GUY SHERMAN
web: www.guysherman.com
phone: +64 21 355 190
email guy at guysherman.com


More information about the Mono-devel-list mailing list