// Chris Toshok (toshok@ximian.com)
//
-using System;
+using System.Globalization;
using System.Windows.Markup;
namespace System.Windows.Converters {
{
public override bool CanConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return true;
}
public override bool CanConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return value is Int32Rect;
}
public override object ConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ return Int32Rect.Parse (value);
}
public override string ConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value is Int32Rect int32Rect)
+ return int32Rect.ToString (CultureInfo.InvariantCulture);
+ return base.ConvertToString (value, context);
}
}
// Chris Toshok (toshok@ximian.com)
//
-using System;
+using System.Globalization;
using System.Windows.Markup;
namespace System.Windows.Converters {
{
public override bool CanConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return true;
}
public override bool CanConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return value is Point;
}
public override object ConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ return Point.Parse (value);
}
public override string ConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value is Point point)
+ return point.ToString (CultureInfo.InvariantCulture);
+ return base.ConvertToString (value, context);
}
}
// Authors:
// Chris Toshok (toshok@ximian.com)
//
-
-using System;
+using System.Globalization;
using System.Windows.Markup;
namespace System.Windows.Converters {
{
public override bool CanConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return true;
}
public override bool CanConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return value is Rect;
}
public override object ConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ return Rect.Parse (value);
}
public override string ConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value is Rect rect)
+ return rect.ToString (CultureInfo.InvariantCulture);
+ return base.ConvertToString (value, context);
}
}
// Chris Toshok (toshok@ximian.com)
//
-using System;
+using System.Globalization;
using System.Windows.Markup;
namespace System.Windows.Converters {
{
public override bool CanConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return true;
}
public override bool CanConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ return value is Vector;
}
public override object ConvertFromString (string value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ return Vector.Parse (value);
}
public override string ConvertToString (object value, IValueSerializerContext context)
{
- throw new NotImplementedException ();
+ if (value is Vector vector)
+ return vector.ToString (CultureInfo.InvariantCulture);
+ return base.ConvertToString (value, context);
}
}
}
else
{
- var parts = source.Split (',');
- if (parts.Length != 6)
- throw new FormatException (string.Format ("Invalid Matrix format: {0}", source));
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
double m11;
double m12;
double m21;
double m22;
double offsetX;
double offsetY;
- if (double.TryParse (parts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out m11)
- && double.TryParse (parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out m12)
- && double.TryParse (parts[2], NumberStyles.Float, CultureInfo.InvariantCulture, out m21)
- && double.TryParse (parts[3], NumberStyles.Float, CultureInfo.InvariantCulture, out m22)
- && double.TryParse (parts[4], NumberStyles.Float, CultureInfo.InvariantCulture, out offsetX)
- && double.TryParse (parts[5], NumberStyles.Float, CultureInfo.InvariantCulture, out offsetY))
+ if (double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out m11)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out m12)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out m21)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out m22)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out offsetX)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out offsetY))
{
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException ("Invalid Matrix format: " + source);
+ }
value = new Matrix (m11, m12, m21, m22, offsetX, offsetY);
}
else
Prepend (m);
}
- string IFormattable.ToString (string format,
- IFormatProvider provider)
- {
- return ToString (provider);
- }
-
public override string ToString ()
{
return ToString (null);
public string ToString (IFormatProvider provider)
{
- return IsIdentity
- ? "Identity"
- : string.Concat (_m11, ",", _m12, ",", _m21, ",", _m22, ",", _offsetX, ",", _offsetY);
+ return ToString (null, provider);
+ }
+
+ string IFormattable.ToString (string format,
+ IFormatProvider provider)
+ {
+ return ToString (provider);
+ }
+
+ private string ToString (string format, IFormatProvider provider)
+ {
+ if (IsIdentity)
+ return "Identity";
+
+ if (provider == null)
+ provider = CultureInfo.CurrentCulture;
+
+ if (format == null)
+ format = string.Empty;
+
+ var separator = NumericListTokenizer.GetSeparator (provider);
+
+ var matrixFormat = string.Format (
+ "{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}{1}{{4:{0}}}{1}{{5:{0}}}",
+ format, separator);
+ return string.Format (provider, matrixFormat,
+ _m11, _m12, _m21, _m22, _offsetX, _offsetY);
}
public Point Transform (Point point)
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.ComponentModel;
+using System.Globalization;
using System.Windows.Converters;
using System.Windows.Markup;
public override int GetHashCode ()
{
- throw new NotImplementedException ();
+ unchecked
+ {
+ var hashCode = _x;
+ hashCode = (hashCode * 397) ^ _y;
+ hashCode = (hashCode * 397) ^ _width;
+ hashCode = (hashCode * 397) ^ _height;
+ return hashCode;
+ }
}
public static Int32Rect Parse (string source)
{
- throw new NotImplementedException ();
+ if (source == null)
+ throw new ArgumentNullException ("source");
+ Int32Rect value;
+ if (source.Trim () == "Empty")
+ {
+ value = Empty;
+ }
+ else
+ {
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+ int x;
+ int y;
+ int width;
+ int height;
+ if (int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out x)
+ && int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out y)
+ && int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out width)
+ && int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
+ {
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException ("Invalid Int32Rect format: " + source);
+ }
+ value = new Int32Rect (x, y, width, height);
+ }
+ else
+ {
+ throw new FormatException (string.Format ("Invalid Int32Rect format: {0}", source));
+ }
+ }
+ return value;
}
public override string ToString ()
{
- if (IsEmpty)
- return "Empty";
- return String.Format ("{0},{1},{2},{3}", _x, _y, _width, _height);
+ return ToString (null);
}
public string ToString (IFormatProvider provider)
{
- throw new NotImplementedException ();
+ return ToString (null, provider);
}
string IFormattable.ToString (string format, IFormatProvider provider)
{
- throw new NotImplementedException ();
+ return ToString (provider);
+ }
+
+ private string ToString (string format, IFormatProvider provider)
+ {
+ if (IsEmpty)
+ return "Empty";
+
+ if (provider == null)
+ provider = CultureInfo.CurrentCulture;
+
+ if (format == null)
+ format = string.Empty;
+
+ var separator = NumericListTokenizer.GetSeparator (provider);
+
+ var rectFormat = string.Format (
+ "{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}",
+ format, separator);
+ return string.Format (provider, rectFormat,
+ _x, _y, _width, _height);
}
}
}
--- /dev/null
+using System.Globalization;
+
+namespace System.Windows
+{
+ /// <summary>
+ /// Helper class for parsing serialized data structures from the System.Windows namespace.
+ /// </summary>
+ internal class NumericListTokenizer
+ {
+ private readonly string _str;
+ private readonly char _separator;
+ private int _position;
+
+ private enum Symbol
+ {
+ Token,
+ Separator,
+ Whitspace,
+ EndOfLine
+ }
+
+ public NumericListTokenizer (string str, IFormatProvider formatProvider)
+ {
+ _str = str ?? throw new ArgumentNullException (nameof(str));
+ _separator = GetSeparator (formatProvider ?? throw new ArgumentNullException (nameof(formatProvider)));
+ }
+
+ public static char GetSeparator (IFormatProvider formatProvider)
+ {
+ // By convention, string representations of target classes always use ';' as a separator
+ // if the decimal number separator is ','. Otherwise, the separator is ','.
+ return NumberFormatInfo.GetInstance (formatProvider).NumberDecimalSeparator != "," ? ',' : ';';
+ }
+
+ private Symbol GetCurrentSymbol ()
+ {
+ if (_position >= _str.Length)
+ return Symbol.EndOfLine;
+ if (_str[_position] == _separator)
+ return Symbol.Separator;
+ if (char.IsWhiteSpace (_str, _position))
+ return Symbol.Whitspace;
+ return Symbol.Token;
+ }
+
+ private void SkipAllWhitespaces ()
+ {
+ while (GetCurrentSymbol () == Symbol.Whitspace)
+ {
+ _position++;
+ }
+ }
+
+ private void SkipNextDelimeter ()
+ {
+ SkipAllWhitespaces ();
+ switch (GetCurrentSymbol ())
+ {
+ case Symbol.Token:
+ return;
+ case Symbol.Separator:
+ _position++;
+ SkipAllWhitespaces ();
+ return;
+ default:
+ throw new InvalidOperationException ("Separator not found");
+ }
+ }
+
+ public bool HasNoMoreTokens ()
+ {
+ SkipAllWhitespaces ();
+ return GetCurrentSymbol () == Symbol.EndOfLine;
+ }
+
+ public string GetNextToken ()
+ {
+ var length = 0;
+ if (_position == 0)
+ {
+ SkipAllWhitespaces ();
+ }
+ else
+ {
+ SkipNextDelimeter ();
+ }
+
+ while (GetCurrentSymbol () == Symbol.Token)
+ {
+ _position++;
+ length++;
+ }
+
+ if (length == 0)
+ {
+ throw new InvalidOperationException ("Next token not found");
+ }
+
+ return _str.Substring (_position - length, length);
+ }
+ }
+}
\ No newline at end of file
public static Point Parse (string source)
{
- string[] points = source.Split(',');
-
- if (points.Length<2)
- throw new InvalidOperationException ("source does not contain two numbers");
- if (points.Length > 2)
- throw new InvalidOperationException ("source contains too many delimiters");
-
- CultureInfo ci = CultureInfo.InvariantCulture;
- return new Point (Convert.ToDouble(points[0],ci), Convert.ToDouble(points[1],ci));
+ if (source == null)
+ throw new ArgumentNullException ("source");
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+ double x;
+ double y;
+ if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x) ||
+ !double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y))
+ {
+ throw new FormatException (string.Format ("Invalid Point format: {0}", source));
+ }
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException ("Invalid Point format: " + source);
+ }
+ return new Point(x, y);
}
public override string ToString ()
private string ToString(string format,IFormatProvider formatProvider)
{
- CultureInfo ci = (CultureInfo)formatProvider;
-
- if (ci == null)
- ci = CultureInfo.CurrentCulture;
- string seperator = ci.NumberFormat.NumberDecimalSeparator;
- if (seperator.Equals(","))
- seperator = ";";
- else
- seperator = ",";
- object[] ob = { this._x, seperator, this._y };
-
- return string.Format(formatProvider, "{0:" + format + "}{1}{2:" + format + "}", ob);
+ if (formatProvider == null)
+ formatProvider = CultureInfo.CurrentCulture;
+ if (format == null)
+ format = string.Empty;
+ var separator = NumericListTokenizer.GetSeparator (formatProvider);
+ var pointFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
+ return string.Format (formatProvider, pointFormat, _x, _y);
}
string IFormattable.ToString (string format, IFormatProvider formatProvider)
// Sebastien Pouliot <sebastien@ximian.com>
//
-using System;
using System.ComponentModel;
using System.Globalization;
-using System.Text;
using System.Windows.Converters;
using System.Windows.Markup;
using System.Windows.Media;
public override int GetHashCode ()
{
- throw new NotImplementedException ();
+ unchecked
+ {
+ var hashCode = _x.GetHashCode ();
+ hashCode = (hashCode * 397) ^ _y.GetHashCode ();
+ hashCode = (hashCode * 397) ^ _width.GetHashCode ();
+ hashCode = (hashCode * 397) ^ _height.GetHashCode ();
+ return hashCode;
+ }
}
public bool Contains (Rect rect)
public static Rect Parse (string source)
{
- throw new NotImplementedException ();
+ if (source == null)
+ throw new ArgumentNullException ("source");
+ Rect value;
+ if (source.Trim () == "Empty")
+ {
+ value = Empty;
+ }
+ else
+ {
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+ double x;
+ double y;
+ double width;
+ double height;
+ if (double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out width)
+ && double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out height))
+ {
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException ("Invalid Rect format: " + source);
+ }
+ value = new Rect (x, y, width, height);
+ }
+ else
+ {
+ throw new FormatException (string.Format ("Invalid Rect format: {0}", source));
+ }
+ }
+ return value;
}
public override string ToString ()
if (format == null)
format = string.Empty;
- string separator = ",";
- NumberFormatInfo numberFormat =
- provider.GetFormat (typeof (NumberFormatInfo)) as NumberFormatInfo;
- if (numberFormat != null &&
- numberFormat.NumberDecimalSeparator == separator)
- separator = ";";
+ var separator = NumericListTokenizer.GetSeparator (provider);
- string rectFormat = String.Format (
+ var rectFormat = string.Format (
"{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}",
format, separator);
- return String.Format (provider, rectFormat,
+ return string.Format (provider, rectFormat,
_x, _y, _width, _height);
}
Size value;
if (source.Trim () == "Empty")
{
- value = Empty;
+ return Empty;
}
- else
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+ double width;
+ double height;
+ if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out width) ||
+ !double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out height))
{
- var parts = source.Split (',');
- if (parts.Length != 2)
- throw new FormatException (string.Format ("Invalid Size format: {0}", source));
- double width;
- double height;
- if (double.TryParse (parts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out width)
- && double.TryParse (parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out height))
- {
- value = new Size (width, height);
- }
- else
- {
- throw new FormatException (string.Format ("Invalid Size format: {0}", source));
- }
+ throw new FormatException (string.Format ("Invalid Size format: {0}", source));
}
- return value;
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException ("Invalid Size format: " + source);
+ }
+ return new Size(width, height);
}
public override string ToString ()
{
- return ConvertToString (null);
+ return ConvertToString (null, null);
}
public string ToString (IFormatProvider provider)
{
- return ConvertToString (provider);
+ return ConvertToString (null, provider);
}
string IFormattable.ToString (string format, IFormatProvider provider)
{
- return ConvertToString (provider);
+ return ConvertToString (format, provider);
}
- private string ConvertToString (IFormatProvider provider)
+ private string ConvertToString (string format, IFormatProvider provider)
{
- return IsEmpty ? "Empty" : string.Concat (_width, ",", _height);
+ if (IsEmpty)
+ return "Empty";
+
+ if (provider == null)
+ provider = CultureInfo.CurrentCulture;
+ if (format == null)
+ format = string.Empty;
+ var separator = NumericListTokenizer.GetSeparator (provider);
+ var vectorFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
+ return string.Format (provider, vectorFormat, _width, _height);
}
public bool IsEmpty {
// Chris Toshok (toshok@novell.com)
//
-using System;
using System.ComponentModel;
+using System.Globalization;
using System.Windows.Converters;
using System.Windows.Markup;
using System.Windows.Media;
public override int GetHashCode ()
{
- throw new NotImplementedException ();
- }
-
- string IFormattable.ToString (string format, IFormatProvider provider)
- {
- return string.Format (provider, "{0:" + format + "},{1:" + format + "}", _x, _y);
+ unchecked
+ {
+ return (_x.GetHashCode () * 397) ^ _y.GetHashCode ();
+ }
}
public static bool Equals (Vector vector1, Vector vector2)
public static Vector Parse (string source)
{
- throw new NotImplementedException ();
+ if (source == null)
+ throw new ArgumentNullException ("source");
+ var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+ double x;
+ double y;
+ if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x) ||
+ !double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y))
+ {
+ throw new FormatException (string.Format ("Invalid Vector format: {0}", source));
+ }
+ if (!tokenizer.HasNoMoreTokens ())
+ {
+ throw new InvalidOperationException("Invalid Vector format: " + source);
+ }
+ return new Vector(x, y);
}
public override string ToString ()
{
- return String.Format ("{0},{1}", _x, _y);
+ return ToString(null);
}
public string ToString (IFormatProvider provider)
{
- throw new NotImplementedException ();
+ return ToString (null, provider);
+ }
+
+ string IFormattable.ToString (string format, IFormatProvider provider)
+ {
+ return ToString (format, provider);
+ }
+
+ private string ToString(string format,IFormatProvider formatProvider)
+ {
+ if (formatProvider == null)
+ formatProvider = CultureInfo.CurrentCulture;
+ if (format == null)
+ format = string.Empty;
+ var separator = NumericListTokenizer.GetSeparator (formatProvider);
+ var vectorFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
+ return string.Format (formatProvider, vectorFormat, _x, _y);
}
public double Length {
}
[Test]
- [Category ("NotWorking")]
public void ConvertFrom ()
{
Int32RectConverter r = new Int32RectConverter ();
}
[Test]
- [Category ("NotWorking")]
public void ConvertFrom_negative ()
{
Int32RectConverter r = new Int32RectConverter ();
}
[Test]
- [Category ("NotWorking")]
public void Parse ()
{
Int32Rect r = Int32Rect.Parse ("1, 2, 3, 4");
}
[Test]
- [Category ("NotWorking")]
public void ParseNegative ()
{
Int32Rect.Parse ("1, 2, -3, -4");
--- /dev/null
+using System;
+using System.Windows;
+using System.Windows.Converters;
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows {
+
+ [TestFixture]
+ public class Int32RectValueSerializerTest
+ {
+ [Test]
+ public void CanConvertFromString ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertFromString ("", null));
+ }
+
+ [Test]
+ public void CanConvertToString ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertToString (new Int32Rect (0, 0, 0, 0), null));
+ Assert.IsFalse (serializer.CanConvertToString ("", null));
+ }
+
+ [Test]
+ public void ConvertFromString ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ object obj = serializer.ConvertFromString ("3,4,5,6", null);
+ Assert.AreEqual (typeof (Int32Rect), obj.GetType ());
+ Assert.AreEqual (new Int32Rect (3, 4, 5, 6), obj);
+ }
+
+ [Test]
+ public void RoundTripConvert()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ var size = new Int32Rect (7, 8, 9, 10);
+ var obj = serializer.ConvertFromString (serializer.ConvertToString (size, null), null);
+ Assert.AreEqual (size, obj);
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringHasInvalidFormat ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ serializer.ConvertFromString ("a,b,c,d", null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringIsNull ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ serializer.ConvertFromString (null, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void ConvertToStringShouldThrowExceptionWhenInvalidType ()
+ {
+ var serializer = new Int32RectValueSerializer ();
+ serializer.ConvertToString (10, null);
+ }
+ }
+
+}
}
[Test]
- [Category ("NotWorking")]
public void ConvertFrom ()
{
PointConverter r = new PointConverter ();
}
[Test]
- [Category ("NotWorking")]
public void ConvertTo ()
{
PointConverter r = new PointConverter ();
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]
+ 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");
}
[Test]
- [Category ("NotWorking")]
public void Parse ()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-fr");
--- /dev/null
+using System;
+using System.Windows;
+using System.Windows.Converters;
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows {
+
+ [TestFixture]
+ public class PointValueSerializerTest
+ {
+ [Test]
+ public void CanConvertFromString ()
+ {
+ var serializer = new PointValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertFromString ("", null));
+ }
+
+ [Test]
+ public void CanConvertToString ()
+ {
+ var serializer = new PointValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertToString (new Point (0, 0), null));
+ Assert.IsFalse (serializer.CanConvertToString ("", null));
+ }
+
+ [Test]
+ public void ConvertFromString ()
+ {
+ var serializer = new PointValueSerializer ();
+ object obj = serializer.ConvertFromString ("3.14,4.15", null);
+ Assert.AreEqual (typeof (Point), obj.GetType ());
+ Assert.AreEqual (new Point (3.14, 4.15), obj);
+ }
+
+ [Test]
+ public void RoundTripConvert()
+ {
+ var serializer = new PointValueSerializer ();
+ var Point = new Point (1.234, 2.678);
+ var obj = serializer.ConvertFromString (serializer.ConvertToString (Point, null), null);
+ Assert.AreEqual (Point, obj);
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringHasInvalidFormat ()
+ {
+ var serializer = new PointValueSerializer ();
+ serializer.ConvertFromString ("a,b", null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringIsNull ()
+ {
+ var serializer = new PointValueSerializer ();
+ serializer.ConvertFromString (null, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void ConvertToStringShouldThrowExceptionWhenInvalidType ()
+ {
+ var serializer = new PointValueSerializer ();
+ serializer.ConvertToString (10, null);
+ }
+ }
+
+}
}
[Test]
- [Category ("NotWorking")]
public void ConvertFrom ()
{
RectConverter r = new RectConverter ();
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void ConvertFrom_negative ()
{
}
[Test]
- [Category ("NotWorking")]
public void ConvertTo ()
{
RectConverter r = new RectConverter ();
}
[Test]
- [Category ("NotWorking")]
public void ToString_FormatException ()
{
// This test does not currently work because
}
[Test]
- [Category ("NotWorking")]
public void Parse ()
{
Rect r = Rect.Parse ("1 , 2, 3, 4");
}
[Test]
- [Category ("NotWorking")]
public void Parse2 ()
{
Rect r = Rect.Parse ("1 2 3 4");
}
[Test]
- [Category ("NotWorking")]
public void Parse3 ()
{
Rect r = Rect.Parse (" 1 2 3 4 ");
}
[Test]
- [Category ("NotWorking")]
public void ParseWithBothSeparators ()
{
Rect.Parse ("1.0, 3 2.0, 5.0");
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void ParseNegative ()
{
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (InvalidOperationException))] // "Premature string termination encountered."
public void Parse3Doubles ()
{
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (FormatException))]
public void ParseInvalidString1 ()
{
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (InvalidOperationException))]
public void ParseInvalidString3 ()
{
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (FormatException))]
public void ParseInvalidString4 ()
{
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (InvalidOperationException))]
public void ParseInvalidString5 ()
{
}
[Test]
- [Category ("NotWorking")]
public void ParseInvalidString6 ()
{
Rect.Parse ("\n1.0, 2.0, 5.0, 2");
}
[Test]
- [Category ("NotWorking")]
[ExpectedException (typeof (InvalidOperationException))]
public void ParseInvalidString7 ()
{
--- /dev/null
+using System;
+using System.Windows;
+using System.Windows.Converters;
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows {
+
+ [TestFixture]
+ public class RectValueSerializerTest
+ {
+ [Test]
+ public void CanConvertFromString ()
+ {
+ var serializer = new RectValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertFromString ("", null));
+ }
+
+ [Test]
+ public void CanConvertToString ()
+ {
+ var serializer = new RectValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertToString (new Rect (0, 0, 0, 0), null));
+ Assert.IsFalse (serializer.CanConvertToString ("", null));
+ }
+
+ [Test]
+ public void ConvertFromString ()
+ {
+ var serializer = new RectValueSerializer ();
+ object obj = serializer.ConvertFromString ("3.14,4.15,5.16,6.17", null);
+ Assert.AreEqual (typeof (Rect), obj.GetType ());
+ Assert.AreEqual (new Rect (3.14, 4.15, 5.16, 6.17), obj);
+ }
+
+ [Test]
+ public void RoundTripConvert()
+ {
+ var serializer = new RectValueSerializer ();
+ var rect = new Rect (1.234, 2.678, 3.123, 4.567);
+ var obj = serializer.ConvertFromString (serializer.ConvertToString (rect, null), null);
+ Assert.AreEqual (rect, obj);
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringHasInvalidFormat ()
+ {
+ var serializer = new RectValueSerializer ();
+ serializer.ConvertFromString ("a,b,c,d", null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringIsNull ()
+ {
+ var serializer = new RectValueSerializer ();
+ serializer.ConvertFromString (null, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void ConvertToStringShouldThrowExceptionWhenInvalidType ()
+ {
+ var serializer = new RectValueSerializer ();
+ serializer.ConvertToString (10, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ConvertToStringShouldThrowExceptionWhenHeightOrWidthIsNegative ()
+ {
+ var serializer = new RectValueSerializer ();
+ var result = serializer.ConvertFromString ("1,2,-1,-2", null);
+ }
+ }
+
+}
}
[Test]
- [Category ("NotWorking")]
public void ConvertFrom ()
{
VectorConverter r = new VectorConverter ();
}
[Test]
- [Category ("NotWorking")]
public void ConvertTo ()
{
VectorConverter r = new VectorConverter ();
--- /dev/null
+using System;
+using System.Windows;
+using System.Windows.Converters;
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows {
+
+ [TestFixture]
+ public class VectorValueSerializerTest
+ {
+ [Test]
+ public void CanConvertFromString ()
+ {
+ var serializer = new VectorValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertFromString ("", null));
+ }
+
+ [Test]
+ public void CanConvertToString ()
+ {
+ var serializer = new VectorValueSerializer ();
+ Assert.IsTrue (serializer.CanConvertToString (new Vector (0, 0), null));
+ Assert.IsFalse (serializer.CanConvertToString ("", null));
+ }
+
+ [Test]
+ public void ConvertFromString ()
+ {
+ var serializer = new VectorValueSerializer ();
+ object obj = serializer.ConvertFromString ("3.14,4.15", null);
+ Assert.AreEqual (typeof (Vector), obj.GetType ());
+ Assert.AreEqual (new Vector (3.14, 4.15), obj);
+ }
+
+ [Test]
+ public void RoundTripConvert()
+ {
+ var serializer = new VectorValueSerializer ();
+ var Vector = new Vector (1.234, 2.678);
+ var obj = serializer.ConvertFromString (serializer.ConvertToString (Vector, null), null);
+ Assert.AreEqual (Vector, obj);
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringHasInvalidFormat ()
+ {
+ var serializer = new VectorValueSerializer ();
+ serializer.ConvertFromString ("a,b", null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConvertFromStringShouldThrowExceptionWhenStringIsNull ()
+ {
+ var serializer = new VectorValueSerializer ();
+ serializer.ConvertFromString (null, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void ConvertToStringShouldThrowExceptionWhenInvalidType ()
+ {
+ var serializer = new VectorValueSerializer ();
+ serializer.ConvertToString (10, null);
+ }
+ }
+
+}
System.Windows/Size.cs
System.Windows/SizeConverter.cs
System.Windows/SplashScreen.cs
+System.Windows/NumericListTokenizer.cs
System.Windows/ValidateValueCallback.cs
System.Windows/Vector.cs
System.Windows/VectorConverter.cs
System.Windows/DependencyPropertyTest.cs
System.Windows/Int32RectTest.cs
System.Windows/Int32RectConverterTest.cs
+System.Windows/Int32RectValueSerializerTest.cs
System.Windows/PointTest.cs
System.Windows/PointConverterTest.cs
+System.Windows/PointValueSerializerTest.cs
System.Windows/PropertyMetadataTest.cs
System.Windows/RectTest.cs
System.Windows/RectConverterTest.cs
+System.Windows/RectValueSerializerTest.cs
System.Windows/SizeTest.cs
System.Windows/SizeConverterTest.cs
System.Windows/SizeValueSerializerTest.cs
System.Windows/VectorTest.cs
System.Windows/VectorConverterTest.cs
+System.Windows/VectorValueSerializerTest.cs
System.Windows.Markup/ConstructorArgumentAttributeTest.cs
System.Windows.Markup/ContentPropertyAttributeTest.cs
System.Windows.Markup/ContentWrapperAttributeTest.cs