context: // 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.
  //
  // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
  //
  // Authors:
  //	Chris Toshok (toshok@ximian.com)
  //
  
  using System;
  using System.Globalization;
  using System.Windows;
  using System.Windows.Media;
  using NUnit.Framework;
  
  namespace MonoTests.System.Windows {
  
  	[TestFixture]
  	public class RectTest
  	{
  		[Test]
  		public void Ctor_Accessor ()
  		{
  			Rect r;
  
  			r = new Rect (new Size (40, 50));
  			Assert.AreEqual (0, r.X);
  			Assert.AreEqual (0, r.Y);
  			Assert.AreEqual (40, r.Width);
  			Assert.AreEqual (50, r.Height);
  			Assert.AreEqual (0, r.Left);
  			Assert.AreEqual (0, r.Top);
  			Assert.AreEqual (40, r.Right);
  			Assert.AreEqual (50, r.Bottom);
  			Assert.AreEqual (new Point (0, 0), r.TopLeft);
  			Assert.AreEqual (new Point (40, 0), r.TopRight);
  			Assert.AreEqual (new Point (0, 50), r.BottomLeft);
  			Assert.AreEqual (new Point (40, 50), r.BottomRight);
  			Assert.AreEqual (new Point (0, 0), r.Location);
  			Assert.AreEqual (new Size (40, 50), r.Size);
  
  			r = new Rect (new Point (4, 5), new Vector (20, 30));
  			Assert.AreEqual (4, r.X);
  			Assert.AreEqual (5, r.Y);
  			Assert.AreEqual (20, r.Width);
  			Assert.AreEqual (30, r.Height);
  			Assert.AreEqual (4, r.Left);
  			Assert.AreEqual (5, r.Top);
  			Assert.AreEqual (24, r.Right);
  			Assert.AreEqual (35, r.Bottom);
  			Assert.AreEqual (new Point (4, 5), r.TopLeft);
  			Assert.AreEqual (new Point (24, 5), r.TopRight);
  			Assert.AreEqual (new Point (4, 35), r.BottomLeft);
  			Assert.AreEqual (new Point (24, 35), r.BottomRight);
  			Assert.AreEqual (new Point (4, 5), r.Location);
  			Assert.AreEqual (new Size (20, 30), r.Size);
  
  			r = new Rect (new Point (4, 5), new Point (20, 30));
  			Assert.AreEqual (4, r.X);
  			Assert.AreEqual (5, r.Y);
  			Assert.AreEqual (16, r.Width);
  			Assert.AreEqual (25, r.Height);
  			Assert.AreEqual (4, r.Left);
  			Assert.AreEqual (5, r.Top);
  			Assert.AreEqual (20, r.Right);
  			Assert.AreEqual (30, r.Bottom);
  			Assert.AreEqual (new Point (4, 5), r.TopLeft);
  			Assert.AreEqual (new Point (20, 5), r.TopRight);
  			Assert.AreEqual (new Point (4, 30), r.BottomLeft);
  			Assert.AreEqual (new Point (20, 30), r.BottomRight);
  			Assert.AreEqual (new Point (4, 5), r.Location);
  			Assert.AreEqual (new Size (16,25), r.Size);
  
  			r = new Rect (new Point (20, 30), new Point (4, 5));
  			Assert.AreEqual (4, r.X);
  			Assert.AreEqual (5, r.Y);
  			Assert.AreEqual (16, r.Width);
  			Assert.AreEqual (25, r.Height);
  			Assert.AreEqual (4, r.Left);
  			Assert.AreEqual (5, r.Top);
  			Assert.AreEqual (20, r.Right);
  			Assert.AreEqual (30, r.Bottom);
  			Assert.AreEqual (new Point (4, 5), r.TopLeft);
  			Assert.AreEqual (new Point (20, 5), r.TopRight);
  			Assert.AreEqual (new Point (4, 30), r.BottomLeft);
  			Assert.AreEqual (new Point (20, 30), r.BottomRight);
  			Assert.AreEqual (new Point (4, 5), r.Location);
  			Assert.AreEqual (new Size (16,25), r.Size);
  
  			r = new Rect (10, 15, 20, 30);
  			Assert.AreEqual (10, r.X);
  			Assert.AreEqual (15, r.Y);
  			Assert.AreEqual (20, r.Width);
  			Assert.AreEqual (30, r.Height);
  			Assert.AreEqual (10, r.Left);
  			Assert.AreEqual (15, r.Top);
  			Assert.AreEqual (30, r.Right);
  			Assert.AreEqual (45, r.Bottom);
  			Assert.AreEqual (new Point (10, 15), r.TopLeft);
  			Assert.AreEqual (new Point (30, 15), r.TopRight);
  			Assert.AreEqual (new Point (10, 45), r.BottomLeft);
  			Assert.AreEqual (new Point (30, 45), r.BottomRight);
  			Assert.AreEqual (new Point (10, 15), r.Location);
  			Assert.AreEqual (new Size (20, 30), r.Size);
  
  			r = new Rect (new Point (10, 15), new Size (20, 30));
  			Assert.AreEqual (10, r.X);
  			Assert.AreEqual (15, r.Y);
  			Assert.AreEqual (20, r.Width);
  			Assert.AreEqual (30, r.Height);
  			Assert.AreEqual (10, r.Left);
  			Assert.AreEqual (15, r.Top);
  			Assert.AreEqual (30, r.Right);
  			Assert.AreEqual (45, r.Bottom);
  			Assert.AreEqual (new Point (10, 15), r.TopLeft);
  			Assert.AreEqual (new Point (30, 15), r.TopRight);
  			Assert.AreEqual (new Point (10, 45), r.BottomLeft);
  			Assert.AreEqual (new Point (30, 45), r.BottomRight);
  			Assert.AreEqual (new Point (10, 15), r.Location);
  			Assert.AreEqual (new Size (20, 30), r.Size);
  		}
  
  		[Test]
  		[ExpectedException (typeof (ArgumentException))]
  		public void Ctor_NegativeWidth ()
  		{
  			new Rect (10, 10, -10, 10);
  		}
  
  		[Test]
  		[ExpectedException (typeof (ArgumentException))]
  		public void Ctor_NegativeHeight ()
  		{
  			new Rect (10, 10, 10, -10);
  		}
  
  		[Test]
  		public void Empty ()
  		{
  			Rect r = Rect.Empty;
  			Assert.AreEqual (Double.PositiveInfinity, r.X);
  			Assert.AreEqual (Double.PositiveInfinity, r.Y);
  			Assert.AreEqual (Double.NegativeInfinity, r.Width);
  			Assert.AreEqual (Double.NegativeInfinity, r.Height);
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_x ()
  		{
  			Rect r = Rect.Empty;
  			r.X = 5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_y ()
  		{
  			Rect r = Rect.Empty;
  			r.Y = 5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_width ()
  		{
  			Rect r = Rect.Empty;
  			r.Width = 5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_height ()
  		{
  			Rect r = Rect.Empty;
  			r.Height = 5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_negative_width ()
  		{
  			Rect r = Rect.Empty;
  			r.Width = -5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ModifyEmpty_negative_height ()
  		{
  			Rect r = Rect.Empty;
  			r.Height = -5;
  		}
  
  
  		[Test]
  		[ExpectedException (typeof (ArgumentException))]
  		public void Modify_negative_width ()
  		{
  			Rect r = new Rect (0, 0, 10, 10);
  			r.Width = -5;
  		}
  
  		[Test]
  		[ExpectedException (typeof (ArgumentException))]
  		public void Modify_negative_height ()
  		{
  			Rect r = new Rect (0, 0, 10, 10);
  			r.Height = -5;
  		}
  
  		[Test]
  		public void Empty_Size ()
  		{
  			Assert.AreEqual (Size.Empty, Rect.Empty.Size);
  		}
  
  		[Test]
  		public void IsEmpty ()
  		{
  			Assert.IsTrue (Rect.Empty.IsEmpty);
  			Assert.IsFalse ((new Rect (5, 5, 5, 5)).IsEmpty);
  		}
  
  		[Test]
  		public void Location ()
  		{
  			Rect r = new Rect (0, 0, 0, 0);
  
  			r.Location = new Point (10, 15);
  			Assert.AreEqual (10, r.X);
  			Assert.AreEqual (15, r.Y);
  		}
  
  		[Test]
  		public void RectSize ()
  		{
  			Rect r = new Rect (0, 0, 5, 5);
  
  			r.Size = new Size (10, 15);
  			Assert.AreEqual (10, r.Width);
  			Assert.AreEqual (15, r.Height);
  		}
  
  		[Test]
  		public void ToStringTest ()
  		{
  			Rect r = new Rect (1.0, 2.5, 3, 4);
  
  			string expectedStringOutput = "1,2.5,3,4";
  			Assert.AreEqual (expectedStringOutput, r.ToString ());
  			Assert.AreEqual (expectedStringOutput, r.ToString (null));
  			Assert.AreEqual ("Empty", Rect.Empty.ToString ());
  
  			// IFormattable.ToString
  			IFormattable rFormattable = r;
  			Assert.AreEqual (expectedStringOutput,
  				rFormattable.ToString (null, null),
  				"IFormattable.ToString with null format");
  			Assert.AreEqual (expectedStringOutput,
  				rFormattable.ToString (string.Empty, null),
  				"IFormattable.ToString with empty format");
  			Assert.AreEqual ("1.00,2.50,3.00,4.00",
  				rFormattable.ToString ("N2", null),
  				"IFormattable.ToString with N2 format");
  			Assert.AreEqual ("blah,blah,blah,blah",
  				rFormattable.ToString ("blah", null),
  				"IFormattable.ToString with blah format");
  			Assert.AreEqual (":,:,:,:",
  				rFormattable.ToString (":", null),
  				"IFormattable.ToString with : format");
  			Assert.AreEqual ("Empty",
  				((IFormattable) Rect.Empty).ToString ("blah", null),
  				"IFormattable.ToString on Rect.Empty with blah format");
  
  			foreach (CultureInfo culture in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
  				if (culture.IsNeutralCulture)
  					continue;
  				string separator = ",";
  				if (culture.NumberFormat.NumberDecimalSeparator == separator)
  					separator = ";";
  				expectedStringOutput =
  					1.ToString (culture) + separator +
  					2.5.ToString (culture) + separator +
  					3.ToString (culture) + separator +
  					4.ToString (culture);
  				Assert.AreEqual (expectedStringOutput,
  					r.ToString (culture),
  					"ToString with Culture: " + culture.Name);
  				Assert.AreEqual ("Empty",
  					Rect.Empty.ToString (culture),
  					"ToString on Empty with Culture: " + culture.Name);
  
  				// IFormattable.ToString
  				Assert.AreEqual (expectedStringOutput,
  					rFormattable.ToString (null, culture),
  					"IFormattable.ToString with null format with Culture: " + culture.Name);
  				Assert.AreEqual (expectedStringOutput,
  					rFormattable.ToString (string.Empty, culture),
  					"IFormattable.ToString with empty format with Culture: " + culture.Name);
  				expectedStringOutput =
  					1.ToString ("N2", culture) + separator +
  					2.5.ToString ("N2", culture) + separator +
  					3.ToString ("N2", culture) + separator +
  					4.ToString ("N2", culture);
  				Assert.AreEqual (expectedStringOutput,
  					rFormattable.ToString ("N2", culture),
  					"IFormattable.ToString with N2 format with Culture: " + culture.Name);
  			}
  		}
  		
  		[Test]
  		[Category ("NotWorking")]
  		public void ToString_FormatException ()
  		{
  			// This test does not currently work because
  			// String.Format does not throw all necessary exceptions
  			IFormattable rFormattable = new Rect (1.0, 2.5, 3, 4);
  			bool exceptionRaised = false;
  			try {
  				rFormattable.ToString ("{", null);
  			} catch (FormatException) {
  				exceptionRaised = true;
  			}
  			Assert.IsTrue (exceptionRaised, "Expected FormatException with IFormattable.ToString (\"{\", null)");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		public void Parse ()
  		{
  			Rect r = Rect.Parse ("1 , 2, 3, 4");
  			Assert.AreEqual (new Rect (1, 2, 3, 4), r);
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		public void Parse2 ()
  		{
  			Rect r = Rect.Parse ("1 2 3 4");
  			Assert.AreEqual (new Rect (1, 2, 3, 4), r);
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		public void Parse3 ()
  		{
  			Rect r = Rect.Parse ("  1 2 3 4  ");
  			Assert.AreEqual (new Rect (1, 2, 3, 4), r);
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		public void ParseWithBothSeparators ()
  		{
  			Rect.Parse ("1.0, 3 2.0, 5.0");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (ArgumentException))]
  		public void ParseNegative ()
  		{
  			Rect.Parse ("1, 2, -3, -4");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (InvalidOperationException))] // "Premature string termination encountered."
  		public void Parse3Doubles ()
  		{
  			Rect.Parse ("1.0, 3, -5");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (FormatException))]
  		public void ParseInvalidString1 ()
  		{
  			Rect.Parse ("1.0, 3, -x, 5.0");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ParseInvalidString3 ()
  		{
  			Rect.Parse ("1.0, 3, 2.0, 5.0, 2");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (FormatException))]
  		public void ParseInvalidString4 ()
  		{
  			Rect.Parse ("1.0-3, 2.0, 5.0, 2");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ParseInvalidString5 ()
  		{
  			Rect.Parse ("1.0, 2.0, 5.0, 2,");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		public void ParseInvalidString6 ()
  		{
  			Rect.Parse ("\n1.0, 2.0, 5.0, 2");
  		}
  
  		[Test]
  		[Category ("NotWorking")]
  		[ExpectedException (typeof (InvalidOperationException))]
  		public void ParseInvalidString7 ()
  		{
  			Rect r = Rect.Parse ("1,, 2, 3, 4");
  			Assert.AreEqual (new Rect (1, 2, 3, 4), r);
  		}
  
  		[Test]
  		public void Equals ()
  		{
  
gt: 			Rect r1 = new Rect (1, 2, 3, 4);