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,120 @@
// 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)
//
// (C) iain@mccoy.id.au
//
// Authors:
// Iain McCoy (iain@mccoy.id.au)
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
class X {
public static readonly DependencyProperty AProperty = DependencyProperty.RegisterAttached("A", typeof(int), typeof(X));
public static void SetA(DependencyObject obj, int value)
{
obj.SetValue(AProperty, value);
}
public static int GetA(DependencyObject obj)
{
return (int)obj.GetValue(AProperty);
}
public static readonly DependencyProperty BProperty = DependencyProperty.RegisterAttached("B", typeof(string), typeof(X));
public static void SetB(DependencyObject obj, string value)
{
obj.SetValue(BProperty, value);
}
public static string GetB(DependencyObject obj)
{
return (string)obj.GetValue(BProperty);
}
}
class Y : DependencyObject {
}
class DefaultValueTest : DependencyObject {
public static readonly DependencyProperty AProperty = DependencyProperty.Register("A", typeof(string), typeof(DefaultValueTest), new PropertyMetadata("defaultValueTest"));
}
[TestFixture]
public class DependencyObjectTest {
[Test]
[Category ("NotWorking")]
public void TestAttachedProperty()
{
Y y1 = new Y();
X.SetA(y1, 2);
Assert.AreEqual(2, X.GetA(y1));
}
[Test]
[Category ("NotWorking")]
public void Test2AttachedProperties()
{
Y y1 = new Y();
Y y2 = new Y();
X.SetA(y1, 2);
X.SetA(y2, 3);
Assert.AreEqual(2, X.GetA(y1));
Assert.AreEqual(3, X.GetA(y2));
}
[Test]
[Category ("NotWorking")]
public void TestEnumerationOfAttachedProperties()
{
int count = 0;
Y y = new Y();
X.SetA(y, 2);
X.SetB(y, "Hi");
LocalValueEnumerator e = y.GetLocalValueEnumerator();
while (e.MoveNext()) {
count++;
if (e.Current.Property == X.AProperty)
Assert.AreEqual(e.Current.Value, 2);
else if (e.Current.Property == X.BProperty)
Assert.AreEqual(e.Current.Value, "Hi");
else
Assert.Fail("Wrong sort of property" + e.Current.Property);
}
Assert.AreEqual(2, count);
}
[Test]
public void TestDefaultValue()
{
DefaultValueTest obj = new DefaultValueTest ();
Assert.AreEqual (obj.GetValue(DefaultValueTest.AProperty), "defaultValueTest");
}
}
}

View File

@@ -0,0 +1,66 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class DependencyObjectTypeTest {
[Test]
public void Accessors ()
{
DependencyObjectType t = DependencyObjectType.FromSystemType (typeof (TestDepObj));
Assert.AreEqual ("TestDepObj", t.Name);
Assert.AreEqual (typeof (TestDepObj), t.SystemType);
Assert.AreEqual (typeof (DependencyObject), t.BaseType.SystemType);
// we can't test the Id field's value, as it's
// not guaranteed to be anything in
// particular.
}
[Test]
public void IsInstanceOfType ()
{
DependencyObjectType t = DependencyObjectType.FromSystemType (typeof (TestDepObj));
DependencyObjectType t2 = DependencyObjectType.FromSystemType (typeof (TestSubclass));
Assert.IsTrue (t.IsInstanceOfType (new TestSubclass()));
Assert.IsTrue (t2.IsSubclassOf (t));
Assert.IsFalse (t.IsSubclassOf (t2));
}
[Test]
public void TestCache ()
{
DependencyObjectType t = DependencyObjectType.FromSystemType (typeof (TestDepObj));
DependencyObjectType t2 = DependencyObjectType.FromSystemType (typeof (TestDepObj));
Assert.AreSame (t, t2);
}
}
}

View File

@@ -0,0 +1,118 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class DependencyPropertyTest {
class ObjectPoker : DependencyObject {
public static readonly DependencyProperty TestProp1 = DependencyProperty.Register ("property1", typeof (string), typeof (ObjectPoker));
}
class SubclassPoker : ObjectPoker {
}
[Test]
[ExpectedException (typeof (ArgumentException))] // "'p1' property was already registered by 'ObjectPoker'."
public void TestMultipleRegisters ()
{
DependencyProperty.Register ("p1", typeof (string), typeof (ObjectPoker));
DependencyProperty.Register ("p1", typeof (string), typeof (ObjectPoker));
}
[Test]
[ExpectedException (typeof (ArgumentException))] // "'property1' property was already registered by 'SubclassPoker'."
public void TestMultipleAddOwner ()
{
ObjectPoker.TestProp1.AddOwner (typeof (SubclassPoker), new PropertyMetadata());
ObjectPoker.TestProp1.AddOwner (typeof (SubclassPoker), new PropertyMetadata());
}
[Test]
public void TestDefaultMetadata ()
{
DependencyProperty p;
p = DependencyProperty.Register ("TestDefaultMetadata1", typeof (string), typeof (ObjectPoker));
Assert.IsNotNull (p.DefaultMetadata);
p = DependencyProperty.Register ("TestDefaultMetadata2", typeof (string), typeof (ObjectPoker), new PropertyMetadata ("hi"));
Assert.IsNotNull (p.DefaultMetadata);
Assert.AreEqual ("hi", p.DefaultMetadata.DefaultValue);
}
[Test]
public void TestAddOwnerNullMetadata()
{
DependencyProperty p = DependencyProperty.Register ("TestAddOwnerNullMetadata", typeof (string), typeof (ObjectPoker));
p.AddOwner (typeof (SubclassPoker), null);
PropertyMetadata pm = p.GetMetadata (typeof (SubclassPoker));
Assert.IsNotNull (pm);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestOverrideMetadataNullMetadata()
{
DependencyProperty p = DependencyProperty.Register ("TestOverrideMetadataNullMetadata", typeof (string), typeof (ObjectPoker));
p.OverrideMetadata (typeof (SubclassPoker), null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestOverrideMetadataNullType()
{
DependencyProperty p = DependencyProperty.Register ("TestOverrideMetadataNullType", typeof (string), typeof (ObjectPoker));
p.OverrideMetadata (null, new PropertyMetadata());
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestReadonlyOverrideMetadata ()
{
DependencyPropertyKey ro_key = DependencyProperty.RegisterReadOnly ("readonly-prop1",
typeof(double),
typeof(ObjectPoker),
new PropertyMetadata(double.NaN));
ro_key.DependencyProperty.OverrideMetadata (typeof (SubclassPoker), new PropertyMetadataPoker());
}
[Test]
public void TestReadonlyOverrideMetadataFromKey ()
{
DependencyPropertyKey ro_key = DependencyProperty.RegisterReadOnly ("readonly-prop2",
typeof(double),
typeof(ObjectPoker),
new PropertyMetadata(double.NaN));
ro_key.OverrideMetadata (typeof (SubclassPoker), new PropertyMetadataPoker ());
}
}
}

View File

@@ -0,0 +1,107 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class Int32RectConverterTest
{
[Test]
public void CanConvertFrom ()
{
Int32RectConverter r = new Int32RectConverter ();
Assert.IsTrue (r.CanConvertFrom (typeof (string)));
Assert.IsFalse (r.CanConvertFrom (typeof (Int32Rect)));
Assert.IsFalse (r.CanConvertFrom (typeof (Size)));
}
[Test]
public void CanConvertTo ()
{
Int32RectConverter r = new Int32RectConverter ();
Assert.IsTrue (r.CanConvertTo (typeof (string)));
Assert.IsFalse (r.CanConvertTo (typeof (Int32Rect)));
Assert.IsFalse (r.CanConvertTo (typeof (Size)));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom ()
{
Int32RectConverter r = new Int32RectConverter ();
object or = r.ConvertFrom ("1, 2, 3, 4");
Assert.AreEqual (typeof (Int32Rect), or.GetType());
Assert.AreEqual (new Int32Rect (1, 2, 3, 4), or);
or = r.ConvertFrom ("Empty");
Assert.AreEqual (typeof (Int32Rect), or.GetType());
Assert.IsTrue (((Int32Rect)or).IsEmpty);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_size ()
{
Int32RectConverter r = new Int32RectConverter ();
r.ConvertFrom (new Size (10, 20));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom_negative ()
{
Int32RectConverter r = new Int32RectConverter ();
object or = r.ConvertFrom ("1, 2, -4, -5");
Assert.AreEqual (typeof (Int32Rect), or.GetType());
Assert.AreEqual (new Int32Rect (1, 2, -4, -5), or);
}
[Test]
[Category ("NotWorking")]
public void ConvertTo ()
{
Int32RectConverter r = new Int32RectConverter ();
Int32Rect rect = new Int32Rect (0, 0, 1, 2);
object o = r.ConvertTo (rect, typeof (string));
Assert.AreEqual (typeof (string), o.GetType());
Assert.AreEqual ("0,0,1,2", (string)o);
}
}
}

View File

@@ -0,0 +1,186 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class Int32RectTest
{
[Test]
public void Ctor_Accessor ()
{
Int32Rect r;
r = new Int32Rect (10, 15, 20, 30);
Assert.AreEqual (10, r.X);
Assert.AreEqual (15, r.Y);
Assert.AreEqual (20, r.Width);
Assert.AreEqual (30, r.Height);
}
[Test]
public void Ctor_NegativeWidth ()
{
new Int32Rect (10, 10, -10, 10);
}
[Test]
public void Ctor_NegativeHeight ()
{
new Int32Rect (10, 10, 10, -10);
}
[Test]
public void Empty ()
{
Int32Rect r = Int32Rect.Empty;
Assert.AreEqual (0, r.X);
Assert.AreEqual (0, r.Y);
Assert.AreEqual (0, r.Width);
Assert.AreEqual (0, r.Height);
}
[Test]
public void ModifyEmpty_x ()
{
Int32Rect r = Int32Rect.Empty;
r.X = 5;
}
[Test]
public void ModifyEmpty_y ()
{
Int32Rect r = Int32Rect.Empty;
r.Y = 5;
}
[Test]
public void ModifyEmpty_width ()
{
Int32Rect r = Int32Rect.Empty;
r.Width = 5;
}
[Test]
public void ModifyEmpty_height ()
{
Int32Rect r = Int32Rect.Empty;
r.Height = 5;
}
[Test]
public void ModifyEmpty_negative_width ()
{
Int32Rect r = Int32Rect.Empty;
r.Width = -5;
}
[Test]
public void ModifyEmpty_negative_height ()
{
Int32Rect r = Int32Rect.Empty;
r.Height = -5;
}
[Test]
public void Modify_negative_width ()
{
Int32Rect r = new Int32Rect (0, 0, 10, 10);
r.Width = -5;
}
[Test]
public void Modify_negative_height ()
{
Int32Rect r = new Int32Rect (0, 0, 10, 10);
r.Height = -5;
}
[Test]
public void IsEmpty ()
{
Assert.IsTrue (Int32Rect.Empty.IsEmpty);
Assert.IsTrue ((new Int32Rect (0, 0, 0, 0)).IsEmpty);
Assert.IsFalse ((new Int32Rect (5, 5, 5, 5)).IsEmpty);
}
[Test]
public void ToStringTest ()
{
Int32Rect r = new Int32Rect (1, 2, 3, 4);
Assert.AreEqual ("1,2,3,4", r.ToString());
Assert.AreEqual ("Empty", Int32Rect.Empty.ToString());
}
[Test]
[Category ("NotWorking")]
public void Parse ()
{
Int32Rect r = Int32Rect.Parse ("1, 2, 3, 4");
Assert.AreEqual (new Int32Rect (1, 2, 3, 4), r);
}
[Test]
[Category ("NotWorking")]
public void ParseNegative ()
{
Int32Rect.Parse ("1, 2, -3, -4");
}
[Test]
public void Equals ()
{
Int32Rect r1 = new Int32Rect (1, 2, 3, 4);
Int32Rect r2 = r1;
Assert.IsTrue (r1.Equals (r1));
r2.X = 0;
Assert.IsFalse (r1.Equals (r2));
r2.X = r1.X;
r2.Y = 0;
Assert.IsFalse (r1.Equals (r2));
r2.Y = r1.Y;
r2.Width = 0;
Assert.IsFalse (r1.Equals (r2));
r2.Width = r1.Width;
r2.Height = 0;
Assert.IsFalse (r1.Equals (r2));
r2.Height = r1.Height;
Assert.IsFalse (r1.Equals (new object()));
}
}
}

View File

@@ -0,0 +1,94 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class PointConverterTest
{
[Test]
public void CanConvertFrom ()
{
PointConverter r = new PointConverter ();
Assert.IsTrue (r.CanConvertFrom (typeof (string)));
Assert.IsFalse (r.CanConvertFrom (typeof (Point)));
}
[Test]
public void CanConvertTo ()
{
PointConverter r = new PointConverter ();
Assert.IsTrue (r.CanConvertTo (typeof (string)));
Assert.IsFalse (r.CanConvertTo (typeof (Point)));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom ()
{
PointConverter r = new PointConverter ();
object or = r.ConvertFrom ("3, 4");
Assert.AreEqual (typeof (Point), or.GetType());
Assert.AreEqual (new Point (3, 4), or);
or = r.ConvertFrom ("-1, -4");
Assert.AreEqual (typeof (Point), or.GetType());
Assert.AreEqual (new Point (-1, -4), or);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_size ()
{
PointConverter r = new PointConverter ();
r.ConvertFrom (new Point (10, 20));
}
[Test]
[Category ("NotWorking")]
public void ConvertTo ()
{
PointConverter r = new PointConverter ();
Point rect = new Point (1, 2);
object o = r.ConvertTo (rect, typeof (string));
Assert.AreEqual (typeof (string), o.GetType());
Assert.AreEqual ("1,2", (string)o);
}
}
}

View File

@@ -0,0 +1,151 @@
// 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.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class PointTest {
[Test]
public void Accessors ()
{
Point p = new Point (4, 5);
Assert.AreEqual (4, p.X);
Assert.AreEqual (5, p.Y);
}
[Test]
public void Equals ()
{
Point p = new Point (4, 5);
Assert.IsTrue (p.Equals (new Point (4, 5)));
Assert.IsFalse (p.Equals (new Point (5, 4)));
Assert.IsFalse (p.Equals (new object()));
}
[Test]
[Category ("NotWorking")]
public void getHashCodeTest()
{
Point p1 = new Point(-5, -4);
Point p2 = new Point(5, 4);
Point p3 = new Point(5, 4);
Assert.AreEqual(p2.GetHashCode(), p3.GetHashCode());
Assert.AreEqual(p1.GetHashCode(),p2.GetHashCode());
}
[Test]
[Category ("NotWorking")]
public void ToStringTest ()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us");
Point p = new Point (4, 5);
Assert.AreEqual ("4,5", p.ToString());
Point p2 = new Point(4.1, 5.1);
Assert.AreEqual("4.1,5.1",p2.ToString());
Point p3 = new Point(0, 0);
Assert.AreEqual("0,0", p3.ToString());
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-de");
Point p4 = new Point(4, 5);
Assert.AreEqual("4;5", p4.ToString());
Point p5 = new Point(4.1, 5.1);
Assert.AreEqual("4,1;5,1", p5.ToString());
Point p6 = new Point(0, 0);
Assert.AreEqual("0;0", p6.ToString());
}
[Test]
[Category ("NotWorking")]
public void Parse ()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-fr");
Point p = Point.Parse ("4,5");
Assert.AreEqual (new Point (4, 5), p);
p = Point.Parse ("-4,-5");
Assert.AreEqual (new Point (-4, -5), p);
p = Point.Parse ("-4.4,-5.5");
Assert.AreEqual (new Point (-4.4, -5.5), p);
p = Point.Parse("4.4,5.5");
Assert.AreEqual(new Point(4.4, 5.5), p);
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us");
Assert.AreEqual(new Point(4.4, 5.5), p);
}
[Test]
public void Offset ()
{
Point p = new Point (4, 5);
p.Offset (3, 4);
Assert.AreEqual (new Point (7, 9), p);
}
[Test]
public void Add ()
{
Point p = Point.Add (new Point (4, 5), new Vector (2, 3));
Assert.AreEqual (new Point (6, 8), p);
}
[Test]
public void Subtract1 ()
{
Point p = Point.Subtract (new Point (4, 5), new Vector (2, 3));
Assert.AreEqual (new Point (2, 2), p);
}
[Test]
public void Subtract2 ()
{
Vector v = Point.Subtract (new Point (4, 5), new Point (2, 3));
Assert.AreEqual (new Vector (2, 2), v);
}
[Test]
public void Multiply ()
{
Matrix m = Matrix.Identity;
m.Scale (2, 2);
Point p = Point.Multiply (new Point (2, 3), m);
Assert.AreEqual (new Point (4, 6), p);
}
}
}

View File

@@ -0,0 +1,202 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
class TestDepObj : DependencyObject {
public static readonly DependencyProperty TestProp1 = DependencyProperty.Register ("property1", typeof (string), typeof (TestDepObj));
public static readonly DependencyProperty TestProp2 = DependencyProperty.Register ("property2", typeof (string), typeof (TestDepObj));
public static readonly DependencyProperty TestProp3 = DependencyProperty.Register ("property3", typeof (string), typeof (TestDepObj));
public static readonly DependencyProperty TestProp4 = DependencyProperty.Register ("property4", typeof (string), typeof (TestDepObj), new PropertyMetadata ("default", changed, coerce));
static void changed (DependencyObject d, DependencyPropertyChangedEventArgs e) { }
static object coerce (DependencyObject d, object baseValue) { return baseValue; }
}
class TestSubclass : TestDepObj {
}
public class PropertyMetadataPoker : PropertyMetadata {
public bool BaseIsSealed {
get { return base.IsSealed; }
}
public void CallApply ()
{
OnApply (TestDepObj.TestProp1, typeof (TestDepObj));
}
public void CallMerge (PropertyMetadata baseMetadata, DependencyProperty dp)
{
Merge (baseMetadata, dp);
}
protected override void Merge (PropertyMetadata baseMetadata, DependencyProperty dp)
{
Console.WriteLine (Environment.StackTrace);
base.Merge (baseMetadata, dp);
}
protected override void OnApply (DependencyProperty dp, Type targetType)
{
base.OnApply (dp, targetType);
Console.WriteLine ("IsSealed in OnApply? {0}", IsSealed);
Console.WriteLine (Environment.StackTrace);
}
}
[TestFixture]
public class PropertyMetadataTest {
[Test]
public void DefaultValues ()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
Assert.AreEqual (null, m.DefaultValue);
Assert.AreEqual (null, m.PropertyChangedCallback);
Assert.AreEqual (null, m.CoerceValueCallback);
}
[Test]
public void IsSealed ()
{
PropertyMetadataPoker m;
Console.WriteLine (1);
// calling OnApply isn't what sets the metadata to be sealed
m = new PropertyMetadataPoker();
Assert.IsFalse (m.BaseIsSealed);
m.CallApply ();
Assert.IsFalse (m.BaseIsSealed);
Console.WriteLine (2);
// calling OverrideMetadata does, however
m = new PropertyMetadataPoker ();
TestDepObj.TestProp1.OverrideMetadata (typeof (TestSubclass), m);
Assert.IsTrue (m.BaseIsSealed);
Console.WriteLine (3);
// calling DependencyProperty.AddOwner does too, but only because it calls OverrideMetadata
m = new PropertyMetadataPoker ();
TestDepObj.TestProp2.AddOwner (typeof (TestSubclass), m);
Assert.IsTrue (m.BaseIsSealed);
Console.WriteLine (4);
// lastly, calling DependencyProperty.Register does.
m = new PropertyMetadataPoker ();
DependencyProperty.Register ("xxx", typeof (string), typeof (TestDepObj), m);
Assert.IsTrue (m.BaseIsSealed);
}
[Test]
public void TestAddOwnerResult()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
DependencyProperty p = TestDepObj.TestProp3.AddOwner (typeof (TestSubclass), m);
// they're the same object
Assert.AreSame (p, TestDepObj.TestProp3);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ModifyAfterSealed1 ()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
DependencyProperty.Register ("p1", typeof (string), typeof (TestDepObj), m);
Assert.IsTrue (m.BaseIsSealed);
m.CoerceValueCallback = null;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ModifyAfterSealed2 ()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
DependencyProperty.Register ("p2", typeof (string), typeof (TestDepObj), m);
Assert.IsTrue (m.BaseIsSealed);
m.PropertyChangedCallback = null;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ModifyAfterSealed3 ()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
DependencyProperty.Register ("p3", typeof (string), typeof (TestDepObj), m);
Assert.IsTrue (m.BaseIsSealed);
m.DefaultValue = "hi";
}
[Test]
public void TestMerge ()
{
PropertyMetadataPoker m = new PropertyMetadataPoker ();
m.CallMerge (TestDepObj.TestProp4.GetMetadata (typeof (TestDepObj)), TestDepObj.TestProp4);
Assert.AreEqual ("default", m.DefaultValue);
Assert.IsNotNull (m.CoerceValueCallback);
Assert.IsNotNull (m.PropertyChangedCallback);
m = new PropertyMetadataPoker ();
m.DefaultValue = "non-default";
m.CallMerge (TestDepObj.TestProp4.GetMetadata (typeof (TestDepObj)), TestDepObj.TestProp4);
Assert.AreEqual ("non-default", m.DefaultValue);
Assert.IsNotNull (m.CoerceValueCallback);
Assert.IsNotNull (m.PropertyChangedCallback);
// XXX should check overriding of coerce and
// property changed callbacks, but we'll trust
// they behave the same..
}
[Test]
[ExpectedException (typeof (ArgumentException))] // "Default value cannot be 'Unset'."
public void TestSetDefaultToUnsetValue ()
{
PropertyMetadata m = new PropertyMetadata ();
m.DefaultValue = DependencyProperty.UnsetValue;
}
[Test]
[ExpectedException (typeof (ArgumentException))] // "Default value cannot be 'Unset'."
public void TestInitDefaultToUnsetValue ()
{
new PropertyMetadata (DependencyProperty.UnsetValue);
}
}
}

View File

@@ -0,0 +1,105 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class RectConverterTest
{
[Test]
public void CanConvertFrom ()
{
RectConverter r = new RectConverter ();
Assert.IsTrue (r.CanConvertFrom (typeof (string)));
Assert.IsFalse (r.CanConvertFrom (typeof (Rect)));
Assert.IsFalse (r.CanConvertFrom (typeof (Size)));
}
[Test]
public void CanConvertTo ()
{
RectConverter r = new RectConverter ();
Assert.IsTrue (r.CanConvertTo (typeof (string)));
Assert.IsFalse (r.CanConvertTo (typeof (Rect)));
Assert.IsFalse (r.CanConvertTo (typeof (Size)));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom ()
{
RectConverter r = new RectConverter ();
object or = r.ConvertFrom ("1, 2, 3, 4");
Assert.AreEqual (typeof (Rect), or.GetType());
Assert.AreEqual (new Rect (1, 2, 3, 4), or);
or = r.ConvertFrom ("Empty");
Assert.AreEqual (typeof (Rect), or.GetType());
Assert.IsTrue (((Rect)or).IsEmpty);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_size ()
{
RectConverter r = new RectConverter ();
r.ConvertFrom (new Size (10, 20));
}
[Test]
[Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void ConvertFrom_negative ()
{
RectConverter r = new RectConverter ();
r.ConvertFrom ("1, 2, -4, -5");
}
[Test]
[Category ("NotWorking")]
public void ConvertTo ()
{
RectConverter r = new RectConverter ();
Rect rect = new Rect (0, 0, 1, 2);
object o = r.ConvertTo (rect, typeof (string));
Assert.AreEqual (typeof (string), o.GetType());
Assert.AreEqual ("0,0,1,2", (string)o);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class SizeConverterTest
{
[Test]
public void CanConvertFrom ()
{
SizeConverter r = new SizeConverter ();
Assert.IsTrue (r.CanConvertFrom (typeof (string)));
Assert.IsFalse (r.CanConvertFrom (typeof (Size)));
}
[Test]
public void CanConvertTo ()
{
SizeConverter r = new SizeConverter ();
Assert.IsTrue (r.CanConvertTo (typeof (string)));
Assert.IsFalse (r.CanConvertTo (typeof (Size)));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom ()
{
SizeConverter r = new SizeConverter ();
object or = r.ConvertFrom ("3, 4");
Assert.AreEqual (typeof (Size), or.GetType());
Assert.AreEqual (new Size (3, 4), or);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_size ()
{
SizeConverter r = new SizeConverter ();
r.ConvertFrom (new Size (10, 20));
}
[Test]
[Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void ConvertFrom_negative ()
{
SizeConverter r = new SizeConverter ();
r.ConvertFrom ("-1, -4");
}
[Test]
[Category ("NotWorking")]
public void ConvertTo ()
{
SizeConverter r = new SizeConverter ();
Size rect = new Size (1, 2);
object o = r.ConvertTo (rect, typeof (string));
Assert.AreEqual (typeof (string), o.GetType());
Assert.AreEqual ("1,2", (string)o);
}
}
}

View File

@@ -0,0 +1,157 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class SizeTest
{
[Test]
public void Ctor_Accessors ()
{
Size s = new Size (10, 20);
Assert.AreEqual (10, s.Width);
Assert.AreEqual (20, s.Height);
}
[Test]
public void Equals ()
{
Size s = new Size (10, 20);
Assert.IsTrue (s.Equals (s));
Assert.IsTrue (s.Equals (new Size (10, 20)));
Assert.IsTrue (Size.Equals (s, s));
Assert.IsFalse (s.Equals (new Size (5, 10)));
Assert.IsFalse (Size.Equals (s, new Size (5, 10)));
Assert.IsFalse (s.Equals (new object()));
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_negative_width()
{
new Size (-10, 5);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_negative_height()
{
new Size (5, -10);
}
[Test]
public void Modify_width ()
{
Size s = new Size (10, 10);
s.Width = 20;
Assert.AreEqual (new Size (20, 10), s);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ModifyEmpty_width ()
{
Size s = Size.Empty;
s.Width = 20;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Modify_negative_width ()
{
Size s = new Size (10, 10);
s.Width = -20;
}
[Test]
public void Modify_height ()
{
Size s = new Size (10, 10);
s.Height = 20;
Assert.AreEqual (new Size (10, 20), s);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ModifyEmpty_height ()
{
Size s = Size.Empty;
s.Height = 20;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Modify_negative_height ()
{
Size s = new Size (10, 10);
s.Height = -20;
}
[Test]
[Category ("NotWorking")]
public void Parse ()
{
Assert.AreEqual (new Size (1, 2), Size.Parse ("1, 2"));
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ParseNegative ()
{
Assert.AreEqual (new Size (-1, 2), Size.Parse ("-1, 2"));
}
[Test]
public void ToStringTest ()
{
Assert.AreEqual ("1,2", (new Size (1, 2)).ToString());
}
[Test]
public void Empty ()
{
Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Width);
Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Height);
}
[Test]
public void IsEmpty ()
{
Assert.IsTrue (Size.Empty.IsEmpty);
Assert.IsFalse ((new Size (10, 10)).IsEmpty);
Assert.IsFalse ((new Size (0, 0)).IsEmpty);
}
}
}

View File

@@ -0,0 +1,94 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class VectorConverterTest
{
[Test]
public void CanConvertFrom ()
{
VectorConverter r = new VectorConverter ();
Assert.IsTrue (r.CanConvertFrom (typeof (string)));
Assert.IsFalse (r.CanConvertFrom (typeof (Vector)));
}
[Test]
public void CanConvertTo ()
{
VectorConverter r = new VectorConverter ();
Assert.IsTrue (r.CanConvertTo (typeof (string)));
Assert.IsFalse (r.CanConvertTo (typeof (Vector)));
}
[Test]
[Category ("NotWorking")]
public void ConvertFrom ()
{
VectorConverter r = new VectorConverter ();
object or = r.ConvertFrom ("3, 4");
Assert.AreEqual (typeof (Vector), or.GetType());
Assert.AreEqual (new Vector (3, 4), or);
or = r.ConvertFrom ("-1, -4");
Assert.AreEqual (typeof (Vector), or.GetType());
Assert.AreEqual (new Vector (-1, -4), or);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_size ()
{
VectorConverter r = new VectorConverter ();
r.ConvertFrom (new Vector (10, 20));
}
[Test]
[Category ("NotWorking")]
public void ConvertTo ()
{
VectorConverter r = new VectorConverter ();
Vector rect = new Vector (1, 2);
object o = r.ConvertTo (rect, typeof (string));
Assert.AreEqual (typeof (string), o.GetType());
Assert.AreEqual ("1,2", (string)o);
}
}
}

View File

@@ -0,0 +1,181 @@
// 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.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
public class VectorTest
{
const double DELTA = 0.000000001d;
[Test]
public void Accessors ()
{
Vector v = new Vector (4, 5);
Assert.AreEqual (4, v.X);
Assert.AreEqual (5, v.Y);
}
[Test]
public void Equals ()
{
Vector v = new Vector (4, 5);
Assert.IsTrue (v.Equals (new Vector (4, 5)));
Assert.IsFalse (v.Equals (new Vector (5, 4)));
Assert.IsFalse (v.Equals (new object()));
}
[Test]
public void ToStringTest ()
{
Vector v = new Vector (4, 5);
Assert.AreEqual ("4,5", v.ToString());
}
[Test]
[Category ("NotWorking")]
public void Parse ()
{
Vector v = Vector.Parse ("4,5");
Assert.AreEqual (new Vector (4, 5), v);
v = Vector.Parse ("-4,-5");
Assert.AreEqual (new Vector (-4, -5), v);
v = Vector.Parse ("-4.4,-5.5");
Assert.AreEqual (new Vector (-4.4, -5.5), v);
}
[Test]
public void Add ()
{
Point p = Vector.Add (new Vector (2, 3), new Point (4, 5));
Assert.AreEqual (new Point (6, 8), p);
Vector v = Vector.Add (new Vector (2, 3), new Vector (4, 5));
Assert.AreEqual (new Vector (6, 8), v);
}
[Test]
public void Length ()
{
Vector v = new Vector (1, 0);
Assert.AreEqual (1, v.LengthSquared);
Assert.AreEqual (1, v.Length);
v = new Vector (5, 5);
Assert.AreEqual (50, v.LengthSquared);
Assert.AreEqual (Math.Sqrt(50), v.Length);
}
[Test]
public void AngleBetween ()
{
double angle = Vector.AngleBetween (new Vector (1, 0), new Vector (0, 1));
Assert.AreEqual (90, angle);
angle = Vector.AngleBetween (new Vector (1, 0), new Vector (0.5, 0.5));
Assert.AreEqual (45, angle, DELTA);
}
[Test]
public void CrossProduct ()
{
Assert.AreEqual (1, Vector.CrossProduct (new Vector (1, 0), new Vector (0, 1)));
Assert.AreEqual (50, Vector.CrossProduct (new Vector (20, 30), new Vector (45, 70)));
}
[Test]
public void Determinant ()
{
Assert.AreEqual (1, Vector.Determinant (new Vector (1, 0), new Vector (0, 1)));
Assert.AreEqual (50, Vector.Determinant (new Vector (20, 30), new Vector (45, 70)));
}
[Test]
public void Divide ()
{
Assert.AreEqual (new Vector (5, 7), Vector.Divide (new Vector (10, 14), 2));
}
[Test]
public void Multiply_VV_M ()
{
Assert.AreEqual (60, Vector.Multiply (new Vector (5, 7), new Vector (5, 5)));
}
[Test]
public void Multiply_VM_V ()
{
Matrix m = Matrix.Identity;
m.Rotate (45);
Console.WriteLine (Vector.Multiply (new Vector (3, 4), m));
}
[Test]
public void Multiply_dV_V ()
{
Assert.AreEqual (new Vector (10, 18), Vector.Multiply (2, new Vector (5, 9)));
}
[Test]
public void Multiply_Vd_V ()
{
Assert.AreEqual (new Vector (10, 18), Vector.Multiply (new Vector (5, 9), 2));
}
[Test]
public void Negate ()
{
Vector v = new Vector (4, 5);
v.Negate ();
Assert.AreEqual (new Vector (-4, -5), v);
}
[Test]
public void Normalize ()
{
Vector v = new Vector (5, 5);
v.Normalize ();
Assert.AreEqual (v.X, v.Y);
Assert.AreEqual (1, v.Length, DELTA);
}
[Test]
public void Subtract ()
{
Assert.AreEqual (new Vector (3, 4), Vector.Subtract (new Vector (5, 7), new Vector (2, 3)));
}
}
}