context: //
  // Tests for System.Drawing.RectangleConverter.cs 
  //
  // Author:
  //	Ravindra (rkumar@novell.com)
  //
  
  //
  // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  // 
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  // 
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
  
  using System;
  using System.Collections;
  using System.ComponentModel;
  using System.ComponentModel.Design.Serialization;
  using System.Drawing;
  using System.Globalization;
  using System.Security.Permissions;
  using System.Threading;
  
  using NUnit.Framework;
  
  namespace MonoTests.System.Drawing
  {
  	[TestFixture]
  	[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  	public class RectangleConverterTest
  	{
  		Rectangle rect;
  		Rectangle rectneg;
  		RectangleConverter rconv;
  		String rectStrInvariant;
  		String rectnegStrInvariant;
  
  		[SetUp]
  		public void SetUp ()
  		{
  			rect = new Rectangle (10, 10, 20, 30);
  			rectStrInvariant = rect.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  			rect.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  			rect.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + 
  			rect.Height;
  
  			rectneg = new Rectangle (-10, -10, 20, 30);
  			rectnegStrInvariant = rectneg.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " 
  			+ rectneg.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + 
  			rectneg.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + rectneg.Height;
  
  			rconv = (RectangleConverter) TypeDescriptor.GetConverter (rect);
  		}
  
  		[Test]
  		public void TestCanConvertFrom ()
  		{
  			Assert.IsTrue (rconv.CanConvertFrom (typeof (String)), "CCF#1");
  			Assert.IsTrue (rconv.CanConvertFrom (null, typeof (String)), "CCF#2");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Rectangle)), "CCF#3");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (RectangleF)), "CCF#4");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Point)), "CCF#5");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (PointF)), "CCF#6");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Size)), "CCF#7");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (SizeF)), "CCF#8");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Object)), "CCF#9");
  			Assert.IsFalse (rconv.CanConvertFrom (null, typeof (int)), "CCF#10");
  			Assert.IsTrue (rconv.CanConvertFrom (null, typeof (InstanceDescriptor)), "CCF#11");
  		}
  
  		[Test]
  		public void TestCanConvertTo ()
  		{
  			Assert.IsTrue (rconv.CanConvertTo (typeof (String)), "CCT#1");
  			Assert.IsTrue (rconv.CanConvertTo (null, typeof (String)), "CCT#2");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (Rectangle)), "CCT#3");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (RectangleF)), "CCT#4");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (Point)), "CCT#5");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (PointF)), "CCT#6");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (Size)), "CCT#7");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (SizeF)), "CCT#8");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (Object)), "CCT#9");
  			Assert.IsFalse (rconv.CanConvertTo (null, typeof (int)), "CCT#10");
  		}
  
  		[Test]
  		public void TestConvertFrom ()
  		{
  			Assert.AreEqual (rect, (Rectangle) rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  								"10, 10, 20, 30"), "CF#1");
  			Assert.AreEqual (rectneg, (Rectangle) rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  								"-10, -10, 20, 30"), "CF#2");
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture, 
  						   "10, 10");
  				Assert.Fail ("CF#3: must throw ArgumentException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is ArgumentException, "CF#3");
  			}
  
  			try {
  				rconv.ConvertFrom ("10");
  				Assert.Fail ("CF#3a: must throw ArgumentException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is ArgumentException, "CF#3a");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   "1, 1, 1, 1, 1");
  				Assert.Fail ("CF#4: must throw ArgumentException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is ArgumentException, "CF#4");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   "*1, 1, 1, 1");
  				Assert.Fail ("CF#5: must throw Exception");
  			} catch (Exception ex) {
  				Assert.AreEqual (typeof (Exception), ex.GetType (), "CF#5-2");
  				Assert.IsNotNull (ex.InnerException, "CF#5-3");
  				Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "CF#5-4");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new Rectangle (10, 10, 100, 100));
  				Assert.Fail ("CF#6: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#6");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new RectangleF (10, 10, 100, 100));
  				Assert.Fail ("CF#7: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#7");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new Point (10, 10));
  				Assert.Fail ("CF#8: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#8");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new PointF (10, 10));
  				Assert.Fail ("CF#9: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#9");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new Size (10, 10));
  				Assert.Fail ("CF#10: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#10");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new SizeF (10, 10));
  				Assert.Fail ("CF#11: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#11");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  						   new Object ());
  				Assert.Fail ("CF#12: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#12");
  			}
  
  			try {
  				rconv.ConvertFrom (null, CultureInfo.InvariantCulture, 1001);
  				Assert.Fail ("CF#13: must throw NotSupportedException");
  			} catch (Exception e) {
  				Assert.IsTrue (e is NotSupportedException, "CF#13");
  			}
  		}
  
  		[Test]
  		public void TestConvertTo ()
  		{
  			Assert.AreEqual (rectStrInvariant, (String) rconv.ConvertTo (null,
  				CultureInfo.InvariantCulture, rect, typeof (String)), "CT#1");
  			Assert.AreEqual (rectnegStrInvariant, (String) rconv.ConvertTo (null,
  				CultureInfo.InvariantCulture, rectneg, typeof (String)), "CT#2");
  
  			try {
  				rconv.ConvertTo (null, CultureInfo.InvariantCulture, 
  
gt: 						 rect, typeof (Rectangle));