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,103 @@
//
// System.ComponentModel.ArrayConverter test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2006 Gert Driesen
//
using System;
using System.ComponentModel;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class ArrayConverterTests
{
private ArrayConverter converter;
[SetUp]
public void SetUp ()
{
converter = new ArrayConverter ();
}
[Test]
public void ConvertTo ()
{
int [] numbers = new int [] { 5, 7 };
string text = (string) converter.ConvertTo (null, CultureInfo.InvariantCulture,
numbers, typeof (string));
Assert.AreEqual ("Int32[] Array", text);
}
[Test]
public void ConvertTo_DestinationType_Null ()
{
int[] numbers = new int[] { 5, 7 };
try {
converter.ConvertTo (null, CultureInfo.InvariantCulture,
numbers, (Type) null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
#if !TARGET_JVM
Assert.AreEqual ("destinationType", ex.ParamName, "#2");
#endif
}
}
[Test]
public void GetProperties ()
{
int [] numbers = new int [] { 5, 7 };
PropertyDescriptorCollection pds = converter.GetProperties (null,
numbers, null);
Assert.IsNotNull (pds, "#A1");
Assert.AreEqual (2, pds.Count, "#A2");
PropertyDescriptor pd = pds [0];
Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#B1");
Assert.AreEqual (false, pd.IsReadOnly, "#B2");
Assert.AreEqual ("[0]", pd.Name, "#B3");
Assert.AreEqual (typeof (int), pd.PropertyType, "#B4");
Assert.IsFalse (pd.CanResetValue (numbers), "#B5");
Assert.AreEqual (5, pd.GetValue (numbers), "#B6");
pd.SetValue (numbers, 9);
Assert.AreEqual (9, pd.GetValue (numbers), "#B7");
pd.ResetValue (numbers);
Assert.AreEqual (9, pd.GetValue (numbers), "#B8");
Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#B9");
pd = pds [1];
Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#C1");
Assert.AreEqual (false, pd.IsReadOnly, "#C2");
Assert.AreEqual ("[1]", pd.Name, "#C3");
Assert.AreEqual (typeof (int), pd.PropertyType, "#C4");
Assert.IsFalse (pd.CanResetValue (numbers), "#C5");
Assert.AreEqual (7, pd.GetValue (numbers), "#C6");
pd.SetValue (numbers, 3);
Assert.AreEqual (3, pd.GetValue (numbers), "#C7");
pd.ResetValue (numbers);
Assert.AreEqual (3, pd.GetValue (numbers), "#C8");
Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#C9");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void GetProperties_Value_Null ()
{
converter.GetProperties (null, null, null);
}
[Test]
public void GetPropertiesSupported ()
{
Assert.IsTrue (converter.GetPropertiesSupported (null));
}
}
}

View File

@@ -0,0 +1,65 @@
//
// AsyncOperationManager.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (C) 2007 Novell, Inc.
//
#if NET_2_0
using System;
using System.Threading;
using System.ComponentModel;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class AsyncOperationManagerTest
{
[Test]
public void SyncContext ()
{
SynchronizationContext sc1 = new SynchronizationContext ();
SynchronizationContext sc2 = new SynchronizationContext ();
#if MOBILE
Assert.IsNotNull (SynchronizationContext.Current, "A1");
#else
Assert.IsNull (SynchronizationContext.Current, "A1");
#endif
Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A2");
Assert.IsNotNull (SynchronizationContext.Current, "A3");
SynchronizationContext.SetSynchronizationContext (sc1);
Assert.AreSame (sc1, SynchronizationContext.Current, "A4");
Assert.AreSame (sc1, AsyncOperationManager.SynchronizationContext, "A5");
AsyncOperationManager.SynchronizationContext = sc2;
Assert.AreSame (sc2, SynchronizationContext.Current, "A6");
Assert.AreSame (sc2, AsyncOperationManager.SynchronizationContext, "A7");
SynchronizationContext.SetSynchronizationContext (null);
Assert.IsNull (SynchronizationContext.Current, "A8");
// This is a brand new one, not sc1 or sc2
Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A9");
Assert.IsNotNull (SynchronizationContext.Current, "A10");
AsyncOperationManager.SynchronizationContext = null;
Assert.IsNull (SynchronizationContext.Current, "A11");
// This is a brand new one, not sc1 or sc2
Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A12");
Assert.IsNotNull (SynchronizationContext.Current, "A13");
}
}
}
#endif

View File

@@ -0,0 +1,82 @@
//
// AttributeCollectionTest.cs
//
// Author:
// Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
// Copyright (C) 2010 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.ComponentModel;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class AttributeCollectionTest {
#if NET_4_0
[Test]
public void Ctor_4_0 ()
{
CustomAttributeCollection attr_coll = new CustomAttributeCollection ();
Attribute [] attributes = attr_coll.GetAttributes ();
Assert.AreEqual (true, attributes == null, "#A0");
}
[Test]
public void AttributesTest ()
{
SerializableAttribute serializable_attr = new SerializableAttribute ();
FlagsAttribute flags_attr = new FlagsAttribute ();
CustomAttributeCollection attr_coll = new CustomAttributeCollection (serializable_attr, flags_attr);
Attribute [] attributes = attr_coll.GetAttributes ();
Assert.AreEqual (true, attributes != null, "#A0");
Assert.AreEqual (2, attributes.Length, "#A1");
// The property is supposed to be giving us the same instance in all the invocations
Assert.AreSame (attributes, attr_coll.GetAttributes (), "#A2");
}
class CustomAttributeCollection : AttributeCollection
{
public CustomAttributeCollection (params Attribute [] attributes)
: base (attributes)
{
}
public CustomAttributeCollection ()
: base ()
{
}
public Attribute [] GetAttributes ()
{
return Attributes;
}
}
#endif
}
}

View File

@@ -0,0 +1,58 @@
//
// 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) 2006 Novell, Inc (http://www.novell.com)
#if !MOBILE
using NUnit.Framework;
using System;
using System.IO;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml.Serialization;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class AttributeProviderAttributeTest {
[Test]
public void CtorTest ()
{
AttributeProviderAttribute a;
a = new AttributeProviderAttribute (typeof (string));
Assert.AreEqual (typeof (string).AssemblyQualifiedName, a.TypeName, "1");
Assert.IsNull (a.PropertyName, "2");
a = new AttributeProviderAttribute ("typename");
Assert.AreEqual ("typename", a.TypeName, "3");
Assert.AreEqual (null, a.PropertyName, "4");
a = new AttributeProviderAttribute ("typename", "propertyname");
Assert.AreEqual ("typename", a.TypeName, "5");
Assert.AreEqual ("propertyname", a.PropertyName, "6");
}
}
}
#endif

View File

@@ -0,0 +1,198 @@
//
// BackgroundWorkerTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 Novell, Inc.
//
using System;
using System.Threading;
using System.Reflection;
using System.ComponentModel;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class BackgroundWorkerTest
{
ManualResetEvent m;
bool runworkercalled;
SynchronizationContext old_context;
[TestFixtureSetUp]
public void FixtureSetup ()
{
old_context = AsyncOperationManager.SynchronizationContext;
AsyncOperationManager.SynchronizationContext = new SynchronizationContext ();
}
[TestFixtureTearDown]
public void TestFixtureTearDown ()
{
AsyncOperationManager.SynchronizationContext = old_context;
}
[SetUp]
public void Setup ()
{
m = new ManualResetEvent (false);
runworkercalled = false;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReportProgressNoReportingSupported ()
{
BackgroundWorker b = new BackgroundWorker ();
Assert.IsFalse (b.IsBusy, "#1");
b.ReportProgress (0);
}
[Test]
public void ReportProgressNonBusy ()
{
BackgroundWorker b = new BackgroundWorker ();
b.WorkerReportsProgress = true;
Assert.IsFalse (b.IsBusy, "#1");
b.ReportProgress (0);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void CancelAsyncNoCancellationSupported ()
{
BackgroundWorker b = new BackgroundWorker ();
Assert.IsFalse (b.IsBusy, "#1");
b.CancelAsync ();
}
[Test]
public void CancelAsyncNonBusy ()
{
BackgroundWorker b = new BackgroundWorker ();
b.WorkerSupportsCancellation = true;
Assert.IsFalse (b.IsBusy, "#1");
b.CancelAsync ();
}
[Test]
public void CancelBackgroundWorker ()
{
BackgroundWorker bw = new BackgroundWorker ();
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler (bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler (bw_RunWorkerCompleted);
runworkercalled = false;
bw.RunWorkerAsync ("cancel");
// We don't want to hang forever if the test fails.
Assert.AreEqual (true, m.WaitOne (10000, false), "A");
Assert.AreEqual (true, runworkercalled, "B");
Assert.AreEqual (false, bw.IsBusy, "C");
}
void bw_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
{
runworkercalled = true;
Assert.AreEqual (true, e.Cancelled, "A1");
try {
object o = e.Result;
Assert.Fail ("There should be an IOE for cancelling the operation");
}
catch (InvalidOperationException)
{ }
Assert.IsNull (e.Error, "A3");
m.Set ();
}
[Test]
public void ExceptionBackgroundWorker ()
{
BackgroundWorker bw = new BackgroundWorker ();
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler (bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler (bw_RunWorkerCompletedException);
runworkercalled = false;
bw.RunWorkerAsync ("exception");
// We don't want to hang forever if the test fails.
Assert.AreEqual (true, m.WaitOne (10000, false), "A");
Assert.AreEqual (true, runworkercalled, "B");
Assert.AreEqual (false, bw.IsBusy, "C");
}
void bw_RunWorkerCompletedException (object sender, RunWorkerCompletedEventArgs e)
{
runworkercalled = true;
Assert.AreEqual (false, e.Cancelled, "A1");
try
{
object o = e.Result;
Assert.Fail ("There should be an TargetInvocationException");
}
catch (TargetInvocationException)
{ }
Assert.IsNotNull (e.Error, "A3");
m.Set ();
}
[Test]
public void CompleteBackgroundWorker ()
{
BackgroundWorker bw = new BackgroundWorker ();
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler (bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler (bw_RunWorkerCompletedSuccess);
runworkercalled = false;
bw.RunWorkerAsync ();
// We don't want to hang forever if the test fails.
Assert.AreEqual (true, m.WaitOne (10000, false), "A");
Assert.AreEqual (true, runworkercalled, "B");
Assert.AreEqual (false, bw.IsBusy, "C");
}
void bw_RunWorkerCompletedSuccess (object sender, RunWorkerCompletedEventArgs e)
{
runworkercalled = true;
Assert.AreEqual (false, e.Cancelled, "A1");
Assert.AreEqual ("B", e.Result, "A2");
Assert.IsNull (e.Error, "A3");
m.Set ();
}
void bw_DoWork (object sender, DoWorkEventArgs e)
{
if ((string)e.Argument == "cancel") {
e.Cancel = true;
e.Result = "A";
} else if ((string)e.Argument == "exception") {
throw new ApplicationException ("Whoops!");
} else
e.Result = "B";
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,147 @@
//
// System.ComponentModel.CharConverter test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2008 Gert Driesen
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class CharConverterTest
{
private CharConverter converter;
private string pattern;
[SetUp]
public void SetUp ()
{
converter = new CharConverter ();
DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat;
pattern = info.ShortDatePattern + " " + info.ShortTimePattern;
}
[Test]
public void CanConvertFrom ()
{
Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertFrom (typeof (char)), "#2");
Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
Assert.IsFalse (converter.CanConvertFrom (typeof (int)), "#4");
Assert.IsFalse (converter.CanConvertFrom (typeof (char [])), "#5");
Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#6");
}
[Test]
public void CanConvertTo ()
{
Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertTo (typeof (char)), "#2");
Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#3");
Assert.IsFalse (converter.CanConvertTo (typeof (int)), "#4");
Assert.IsFalse (converter.CanConvertTo (typeof (char [])), "#5");
Assert.IsFalse (converter.CanConvertTo (typeof (InstanceDescriptor)), "#6");
}
[Test]
public void ConvertFrom_String ()
{
char c;
c = (char) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
String.Empty);
Assert.AreEqual ('\0', c, "#1");
c = (char) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"e");
Assert.AreEqual ('e', c, "#2");
c = (char) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"\t f\r\n ");
Assert.AreEqual ('f', c, "#3");
}
[Test]
public void ConvertFrom_String_Invalid ()
{
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"ef");
Assert.Fail ("#A1");
} catch (FormatException ex) {
// ef is not a valid value for Char
Assert.AreEqual (typeof (FormatException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsTrue (ex.Message.IndexOf (typeof (char).Name) != -1, "#A5");
Assert.IsTrue (ex.Message.IndexOf ("ef") != -1, "#A6");
}
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"\ref \n");
Assert.Fail ("#B1");
} catch (FormatException ex) {
// \ref\n is not a valid value for Char
Assert.AreEqual (typeof (FormatException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsTrue (ex.Message.IndexOf (typeof (char).Name) != -1, "#B5");
Assert.IsTrue (ex.Message.IndexOf ("ef") != -1, "#B6");
}
}
[Test]
public void ConvertFrom_Value_Null ()
{
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
(string) null);
Assert.Fail ("#1");
} catch (NotSupportedException ex) {
// CharConverter cannot convert from (null)
Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CharConverter).Name) != -1, "#5");
Assert.IsTrue (ex.Message.IndexOf ("(null)") != -1, "#6");
}
}
[Test]
public void ConvertToString ()
{
string result;
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
' ');
Assert.AreEqual (" ", result, "#1");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
'\0');
Assert.AreEqual (string.Empty, result, "#2");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
'f');
Assert.AreEqual ("f", result, "#3");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
null);
Assert.AreEqual (string.Empty, result, "#4");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
new char [] { 'a', 'f' });
Assert.AreEqual ("System.Char[]", result, "#5");
}
}
}

View File

@@ -0,0 +1,139 @@
//
// System.ComponentModel.CollectionConverterTest.cs -
// NUnit Test Cases for System.ComponentModel.CollectionConverter
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2006 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 NUnit.Framework;
using System;
using System.IO;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml.Serialization;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class CollectionConverterTest {
private CollectionConverter cc;
private StringCollection sc;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
cc = new CollectionConverter ();
sc = new StringCollection ();
}
[Test]
public void ApplicableTypes ()
{
Type t = cc.GetType ();
Assert.AreEqual (t, TypeDescriptor.GetConverter (typeof (StringCollection)).GetType (), "StringCollection");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFromString_Null ()
{
cc.ConvertFromString (null);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFromString_Empty ()
{
cc.ConvertFromString (String.Empty);
}
private const string array_of_strings = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <string>go</string>\r\n <string>mono</string>\r\n </ArrayOfString>";
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFromString ()
{
cc.ConvertFromString (array_of_strings);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom ()
{
cc.ConvertFrom (array_of_strings);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_XmlSerializer ()
{
XmlSerializer xs = new XmlSerializer (typeof (string[]));
object o = xs.Deserialize (new StringReader (array_of_strings));
cc.ConvertFrom (o);
}
[Test]
public void ConvertTo ()
{
Assert.AreEqual (String.Empty, cc.ConvertTo (null, null, null, typeof (string)), "null");
Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "0");
sc.Add ("some string value");
Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "1");
sc.Clear ();
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConvertTo_TypeNull ()
{
cc.ConvertTo (null, null, sc, null);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertTo_TypeNotString ()
{
cc.ConvertTo (null, null, sc, typeof (int));
}
[Test]
public void GetProperties ()
{
// documented to always return null
Assert.IsNull (cc.GetProperties (null), "null");
Assert.IsNull (cc.GetProperties (null, null), "null,null");
Assert.IsNull (cc.GetProperties (null, null, null), "null,null,null");
}
[Test]
public void GetPropertiesSupported ()
{
// documented to always return false
Assert.IsFalse (cc.GetPropertiesSupported (), "empty");
Assert.IsFalse (cc.GetPropertiesSupported (null), "null");
}
}
}

View File

@@ -0,0 +1,87 @@
//
// 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) 2006 Novell, Inc (http://www.novell.com)
#if !MOBILE
using NUnit.Framework;
using System;
using System.IO;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml.Serialization;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class ComplexBindingPropertiesAttributeTest {
[Test]
public void CtorTest ()
{
ComplexBindingPropertiesAttribute a;
a = new ComplexBindingPropertiesAttribute ("source", "member");
Assert.AreEqual ("source", a.DataSource, "1");
Assert.AreEqual ("member", a.DataMember, "2");
a = new ComplexBindingPropertiesAttribute ("source");
Assert.AreEqual ("source", a.DataSource, "3");
Assert.AreEqual (null, a.DataMember, "4");
a = new ComplexBindingPropertiesAttribute ();
Assert.AreEqual (null, a.DataSource, "5");
Assert.AreEqual (null, a.DataMember, "6");
}
[Test]
public void EqualsTest ()
{
ComplexBindingPropertiesAttribute a;
a = new ComplexBindingPropertiesAttribute ("source", "member");
Assert.IsFalse (a.Equals (null), "1");
Assert.IsFalse (a.Equals (new ComplexBindingPropertiesAttribute ("member", "source")), "2");
Assert.IsTrue (a.Equals (new ComplexBindingPropertiesAttribute ("source", "member")), "3");
}
[Test]
public void GetHashCodeTest ()
{
ComplexBindingPropertiesAttribute a;
a = new ComplexBindingPropertiesAttribute ("source", "member");
Assert.IsFalse (0 == a.GetHashCode (), "1");
a = new ComplexBindingPropertiesAttribute ("source");
Assert.IsFalse (0 == a.GetHashCode (), "2");
}
[Test]
public void DefaultTest ()
{
Assert.AreEqual (ComplexBindingPropertiesAttribute.Default, new ComplexBindingPropertiesAttribute (), "1");
}
}
}
#endif

View File

@@ -0,0 +1,38 @@
//
// System.ComponentModel.TypeConverter test cases
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (c) 2008 Novell, Inc. (http://novell.com)
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Data;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class ComponentConverterTests
{
[Test]
[NUnit.Framework.Category ("MobileNotWorking")] // IComponent doesn't have the TypeConverter attribute
public void DataSetConversions ()
{
TypeConverter converter = TypeDescriptor.GetConverter (typeof (DataSet));
Assert.AreEqual (typeof (ComponentConverter), converter != null ? converter.GetType () : null, "A1");
DataSet ds = new DataSet ();
string s = (string) converter.ConvertTo (null, CultureInfo.InvariantCulture, ds, typeof (string));
Assert.AreEqual (String.Empty, s, "A2");
object obj = converter.ConvertFrom (null, CultureInfo.InvariantCulture, s);
Assert.IsNull (obj, "A3");
}
}
}

View File

@@ -0,0 +1,163 @@
//
// System.ComponentModel.ComponentResourceManager test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2007 Gert Driesen
//
#if !MOBILE
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using System.Resources;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class ComponentResourceManagerTest
{
[Test]
public void Constructor0 ()
{
MockComponentResourceManager crm = new MockComponentResourceManager ();
Assert.IsNull (crm.BaseName, "#1");
Assert.IsNull (crm.BaseNameField, "#2");
Assert.IsFalse (crm.IgnoreCase, "#3");
Assert.IsNull (crm.MainAssembly, "#4");
Assert.IsNull (crm.ResourceSets, "#5");
Assert.IsNotNull (crm.ResourceSetType, "#6");
Assert.IsTrue (typeof (ResourceSet).IsAssignableFrom (crm.ResourceSetType), "#7");
//Assert.IsFalse (typeof (ResourceSet) == crm.ResourceSetType, "#7");
}
[Test]
public void Constructor1 ()
{
MockComponentResourceManager crm = new MockComponentResourceManager (
typeof (Component));
Assert.IsNotNull (crm.BaseName, "#1");
Assert.AreEqual ("Component", crm.BaseName, "#2");
Assert.IsNotNull (crm.BaseNameField, "#3");
Assert.AreEqual ("Component", crm.BaseNameField, "#4");
Assert.IsFalse (crm.IgnoreCase, "#5");
Assert.IsNotNull (crm.MainAssembly, "#6");
Assert.AreEqual (typeof (Component).Assembly, crm.MainAssembly, "#7");
Assert.IsNotNull (crm.ResourceSets, "#8");
Assert.AreEqual (0, crm.ResourceSets.Count, "#9");
Assert.IsNotNull (crm.ResourceSetType, "#10");
Assert.IsTrue (typeof (ResourceSet).IsAssignableFrom (crm.ResourceSetType), "#11");
//Assert.IsFalse (typeof (ResourceSet) == crm.ResourceSetType, "#12");
}
[Test]
public void Constructor1_ResourceSource_Null ()
{
try {
new ComponentResourceManager ((Type) null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("resourceSource", ex.ParamName, "#6");
}
}
[Test]
public void ApplyResources_ObjectName_Null ()
{
ComponentResourceManager crm = new ComponentResourceManager ();
try {
crm.ApplyResources (new object (), (string) null);
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsNotNull (ex.ParamName, "#A5");
Assert.AreEqual ("objectName", ex.ParamName, "#A6");
}
try {
crm.ApplyResources (new object (), (string) null, CultureInfo.InvariantCulture);
Assert.Fail ("#B1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsNotNull (ex.ParamName, "#B5");
Assert.AreEqual ("objectName", ex.ParamName, "#B6");
}
}
[Test]
public void ApplyResources_Value_Null ()
{
ComponentResourceManager crm = new ComponentResourceManager ();
try {
crm.ApplyResources (null, "$this");
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsNotNull (ex.ParamName, "#A5");
Assert.AreEqual ("value", ex.ParamName, "#A6");
}
try {
crm.ApplyResources (null, "$this", CultureInfo.InvariantCulture);
Assert.Fail ("#B1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsNotNull (ex.ParamName, "#B5");
Assert.AreEqual ("value", ex.ParamName, "#B6");
}
}
[Test]
public void IgnoreCase ()
{
ComponentResourceManager crm = new ComponentResourceManager ();
Assert.IsFalse (crm.IgnoreCase, "#1");
crm.IgnoreCase = true;
Assert.IsTrue (crm.IgnoreCase, "#2");
}
class MockComponentResourceManager : ComponentResourceManager
{
public MockComponentResourceManager ()
{
}
public MockComponentResourceManager (Type resourceSource)
: base (resourceSource)
{
}
public new string BaseNameField {
get { return base.BaseNameField; }
}
public new Assembly MainAssembly {
get { return base.MainAssembly; }
}
public new Hashtable ResourceSets {
get { return base.ResourceSets; }
}
}
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,233 @@
//
// System.ComponentModel.CultureInfoConverter test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2008 Gert Driesen
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class CultureInfoConverterTest
{
private CultureInfoConverter converter;
[SetUp]
public void SetUp ()
{
converter = new CultureInfoConverter ();
}
[Test]
public void CanConvertFrom ()
{
Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertFrom (typeof (CultureInfo)), "#2");
Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
Assert.IsFalse (converter.CanConvertFrom (typeof (int)), "#4");
Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#5");
}
[Test]
public void CanConvertTo ()
{
Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
Assert.IsFalse (converter.CanConvertTo (typeof (CultureInfo)), "#3");
Assert.IsFalse (converter.CanConvertTo (typeof (int)), "#4");
Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "#5");
}
[Test]
public void ConvertFrom_String ()
{
CultureInfo c;
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
String.Empty);
Assert.AreEqual (CultureInfo.InvariantCulture, c, "#1");
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"nl-BE");
Assert.AreEqual (new CultureInfo ("nl-BE"), c, "#2");
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"Dut");
Assert.AreEqual (new CultureInfo ("nl"), c, "#3");
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"Dutch (Bel");
Assert.AreEqual (new CultureInfo ("nl-BE"), c, "#4");
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"duTcH (Bel");
Assert.AreEqual (new CultureInfo ("nl-BE"), c, "#5");
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"(Default)");
Assert.AreEqual (CultureInfo.InvariantCulture, c, "#6");
#if ONLY_1_1
c = (CultureInfo) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"(defAuLt)");
Assert.AreEqual (CultureInfo.InvariantCulture, c, "#6");
#endif
}
[Test]
public void ConvertFrom_String_IncompleteName ()
{
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"nl-B");
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// The nl-B culture cannot be converted to a
// CultureInfo object on this computer
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CultureInfo).Name) != -1, "#5");
Assert.IsTrue (ex.Message.IndexOf ("nl-B") != -1, "#6");
Assert.IsNull (ex.ParamName, "#7");
}
}
[Test]
public void ConvertFrom_String_InvalidCulture ()
{
#if NET_2_0
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"(default)");
Assert.Fail ("#A1");
} catch (ArgumentException ex) {
// The (default) culture cannot be converted to
// a CultureInfo object on this computer
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CultureInfo).Name) != -1, "#A5");
Assert.IsTrue (ex.Message.IndexOf ("(default)") != -1, "#A6");
Assert.IsNull (ex.ParamName, "#A7");
}
#endif
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
" ");
Assert.Fail ("#B1");
} catch (ArgumentException ex) {
// The culture cannot be converted to
// a CultureInfo object on this computer
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CultureInfo).Name) != -1, "#B5");
Assert.IsTrue (ex.Message.IndexOf (" ") != -1, "#B6");
Assert.IsNull (ex.ParamName, "#B7");
}
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
"\r\n");
Assert.Fail ("#C1");
} catch (ArgumentException ex) {
// The \r\n culture cannot be converted to
// a CultureInfo object on this computer
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
Assert.IsNull (ex.InnerException, "#C3");
Assert.IsNotNull (ex.Message, "#C4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CultureInfo).Name) != -1, "#C5");
Assert.IsTrue (ex.Message.IndexOf ("\r\n") != -1, "#C6");
Assert.IsNull (ex.ParamName, "#C7");
}
}
[Test]
public void ConvertFrom_Value_Null ()
{
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
(string) null);
Assert.Fail ("#1");
} catch (NotSupportedException ex) {
// CultureInfoConverter cannot convert from (null)
Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (typeof (CultureInfoConverter).Name) != -1, "#5");
Assert.IsTrue (ex.Message.IndexOf ("(null)") != -1, "#6");
}
}
[Test]
public void ConvertToString ()
{
string result;
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
new MyCultureInfo ());
Assert.AreEqual ("display", result, "#1");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
null);
Assert.AreEqual ("(Default)", result, "#2");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
CultureInfo.InvariantCulture);
Assert.AreEqual ("(Default)", result, "#3");
result = converter.ConvertToString (null, CultureInfo.InvariantCulture,
new CultureInfo ("nl-BE"));
Assert.AreEqual ("Dutch (Belgium)", result, "#4");
}
[Serializable]
private sealed class MyCultureInfo : CultureInfo
{
internal MyCultureInfo () : base ("nl-BE")
{
}
public override string DisplayName {
get { return "display"; }
}
public override string EnglishName {
get { return "english"; }
}
}
#if NET_4_0
[Test]
public void GetCultureName ()
{
CustomCultureInfoConverter custom_converter = new CustomCultureInfoConverter ();
CultureInfo fr_culture = CultureInfo.GetCultureInfo ("fr-FR");
Assert.AreEqual (fr_culture.Name, custom_converter.GetCultureName (fr_culture), "#A1");
CultureInfo es_culture = CultureInfo.GetCultureInfo ("es-MX");
Assert.AreEqual (es_culture.Name, custom_converter.GetCultureName (es_culture), "#A2");
}
class CustomCultureInfoConverter : CultureInfoConverter
{
public new string GetCultureName (CultureInfo culture)
{
return base.GetCultureName (culture);
}
}
#endif
}
}

View File

@@ -0,0 +1,71 @@
//
// (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)
//
// Authors:
// Konstantin Triger <kostat@mainsoft.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.
//
#if !MOBILE
using System;
using System.ComponentModel;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class DataObjectMethodAttributeTests
{
[Test]
public void Ctor () {
DataObjectMethodAttribute attr = new DataObjectMethodAttribute (DataObjectMethodType.Fill);
Assert.IsFalse (attr.IsDefault);
}
[Test]
public void MatchTest () {
DataObjectMethodAttribute a1 = new DataObjectMethodAttribute (DataObjectMethodType.Fill);
DataObjectMethodAttribute a2 = new DataObjectMethodAttribute (DataObjectMethodType.Delete, true);
Assert.IsFalse (a1.Match (a2), "#1");
DataObjectMethodAttribute a3 = new DataObjectMethodAttribute (DataObjectMethodType.Delete);
Assert.IsTrue (a2.Match (a3), "#2");
}
[Test]
public void EqualsTest () {
DataObjectMethodAttribute a1 = new DataObjectMethodAttribute (DataObjectMethodType.Fill);
DataObjectMethodAttribute a2 = new DataObjectMethodAttribute (DataObjectMethodType.Delete);
Assert.IsFalse (a1.Equals (a2), "#1");
DataObjectMethodAttribute a3 = new DataObjectMethodAttribute (DataObjectMethodType.Delete);
Assert.IsTrue (a2.Equals (a3), "#2");
}
}
}
#endif

View File

@@ -0,0 +1,251 @@
//
// System.ComponentModel.DateTimeConverter test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2005 Novell, Inc. (http://www.ximian.com)
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class DateTimeConverterTests
{
private DateTimeConverter converter;
private string pattern;
[SetUp]
public void SetUp ()
{
converter = new DateTimeConverter ();
DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat;
pattern = info.ShortDatePattern + " " + info.ShortTimePattern;
}
[Test]
public void CanConvertFrom ()
{
Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertFrom (typeof (DateTime)), "#2");
Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#4");
}
[Test]
public void CanConvertTo ()
{
Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "#3");
}
[Test]
public void ConvertFrom_String ()
{
DateTime date = DateTime.Now;
DateTime newDate = (DateTime) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
date.ToString(CultureInfo.InvariantCulture));
Assert.AreEqual (date.Year, newDate.Year, "#1");
Assert.AreEqual (date.Month, newDate.Month, "#2");
Assert.AreEqual (date.Day, newDate.Day, "#3");
Assert.AreEqual (date.Hour, newDate.Hour, "#4");
Assert.AreEqual (date.Minute, newDate.Minute, "#5");
Assert.AreEqual (date.Second, newDate.Second, "#6");
Assert.AreEqual (0, newDate.Millisecond, "#7");
newDate = (DateTime) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
String.Empty);
Assert.AreEqual (DateTime.MinValue, newDate, "#8");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Object ()
{
converter.ConvertFrom (new object ());
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Int32 ()
{
converter.ConvertFrom (10);
}
[Test]
public void ConvertTo_MinValue ()
{
Assert.AreEqual (string.Empty, converter.ConvertTo (null,
CultureInfo.InvariantCulture, DateTime.MinValue, typeof (string)), "#1");
Assert.AreEqual (string.Empty, converter.ConvertTo (null,
CultureInfo.CurrentCulture, DateTime.MinValue, typeof (string)), "#2");
Assert.AreEqual (string.Empty, converter.ConvertTo (DateTime.MinValue,
typeof (string)), "#3");
}
[Test]
public void ConvertTo_MaxValue ()
{
Assert.AreEqual (DateTime.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertTo (null, CultureInfo.InvariantCulture, DateTime.MaxValue,
typeof (string)), "#1");
// FIXME: We probably shouldn't be using CurrentCulture in these tests.
if (CultureInfo.CurrentCulture == CultureInfo.InvariantCulture)
return;
Assert.AreEqual (DateTime.MaxValue.ToString (pattern,
CultureInfo.CurrentCulture), converter.ConvertTo (null,
CultureInfo.CurrentCulture, DateTime.MaxValue, typeof (string)),
"#2");
Assert.AreEqual (DateTime.MaxValue.ToString (pattern,
CultureInfo.CurrentCulture), converter.ConvertTo (DateTime.MaxValue,
typeof (string)), "#3");
}
[Test]
public void ConvertToString_MinValue ()
{
Assert.AreEqual (string.Empty, converter.ConvertToString (null,
CultureInfo.InvariantCulture, DateTime.MinValue), "#1");
Assert.AreEqual (string.Empty, converter.ConvertToString (null,
DateTime.MinValue), "#2");
Assert.AreEqual (string.Empty, converter.ConvertToString (null,
CultureInfo.CurrentCulture, DateTime.MinValue), "#3");
Assert.AreEqual (string.Empty, converter.ConvertToString (DateTime.MinValue),
"#4");
}
[Test]
public void ConvertToString_MaxValue ()
{
Assert.AreEqual (DateTime.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertToString (null, CultureInfo.InvariantCulture,
DateTime.MaxValue), "#1");
// FIXME: We probably shouldn't be using CurrentCulture in these tests.
if (CultureInfo.CurrentCulture == CultureInfo.InvariantCulture)
return;
Assert.AreEqual (DateTime.MaxValue.ToString (pattern, CultureInfo.CurrentCulture),
converter.ConvertToString (null, DateTime.MaxValue), "#2");
Assert.AreEqual (DateTime.MaxValue.ToString (pattern, CultureInfo.CurrentCulture),
converter.ConvertToString (null, CultureInfo.CurrentCulture,
DateTime.MaxValue), "#3");
Assert.AreEqual (DateTime.MaxValue.ToString (pattern, CultureInfo.CurrentCulture),
converter.ConvertToString (DateTime.MaxValue), "#4");
}
[Test]
public void ConvertToString ()
{
CultureInfo culture = new MyCultureInfo ();
DateTimeFormatInfo info = (DateTimeFormatInfo) culture.GetFormat (typeof (DateTimeFormatInfo));
DateTime date = DateTime.Now;
Assert.AreEqual (date.ToString (info.ShortDatePattern + " " +
info.ShortTimePattern, culture), converter.ConvertToString (
null, culture, date));
CultureInfo ciUS = new CultureInfo("en-US");
CultureInfo ciGB = new CultureInfo("en-GB");
CultureInfo ciDE = new CultureInfo("de-DE");
//
date = new DateTime(2008, 12, 31, 23, 59, 58, 5);
DoTestToString("12/31/2008 11:59 PM", date, ciUS);
DoTestToString("31/12/2008 23:59", date, ciGB);
DoTestToString("31.12.2008 23:59", date, ciDE);
DoTestToString("12/31/2008 23:59:58", date, CultureInfo.InvariantCulture);
Assert.AreEqual("12/31/2008 23:59:58", converter.ConvertToInvariantString(date), "Invariant");
//
date = new DateTime(2008, 12, 31);
DoTestToString("12/31/2008", date, ciUS);
DoTestToString("31/12/2008", date, ciGB);
DoTestToString("31.12.2008", date, ciDE);
DoTestToString("2008-12-31", date, CultureInfo.InvariantCulture);
Assert.AreEqual("2008-12-31", converter.ConvertToInvariantString(date), "Invariant");
}
private void DoTestToString(String expected, DateTime value, CultureInfo ci)
{
String message = ci.Name;
if (message == null || message.Length == 0)
message = "?Invariant";
Assert.AreEqual(expected, converter.ConvertTo(null, ci, value, typeof(String)), message);
}
[Test]
public void ConvertFromString ()
{
CultureInfo culture = new MyCultureInfo ();
DateTimeFormatInfo info = (DateTimeFormatInfo) culture.GetFormat (typeof (DateTimeFormatInfo));
DateTime date = DateTime.Now;
DateTime newDate = (DateTime) converter.ConvertFrom (null, culture, date.ToString("G", info));
Assert.AreEqual (date.Year, newDate.Year, "#1");
Assert.AreEqual (date.Month, newDate.Month, "#2");
Assert.AreEqual (date.Day, newDate.Day, "#3");
Assert.AreEqual (date.Hour, newDate.Hour, "#4");
Assert.AreEqual (date.Minute, newDate.Minute, "#5");
Assert.AreEqual (date.Second, newDate.Second, "#6");
Assert.AreEqual (0, newDate.Millisecond, "#7");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFrom_InvalidValue ()
{
converter.ConvertFrom ("*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFrom_InvalidValue_Invariant ()
{
converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFromString_InvalidValue ()
{
converter.ConvertFromString ("*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFromString_InvalidValue_Invariant ()
{
converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
}
[Serializable]
private sealed class MyCultureInfo : CultureInfo
{
internal MyCultureInfo () : base ("en-US")
{
}
public override object GetFormat (Type formatType)
{
if (formatType == typeof (DateTimeFormatInfo)) {
DateTimeFormatInfo info = (DateTimeFormatInfo) ((DateTimeFormatInfo) base.GetFormat (formatType)).Clone ();
info.ShortDatePattern = "MM?dd?yyyy";
info.ShortTimePattern = "hh!mm";
return DateTimeFormatInfo.ReadOnly (info);
} else {
return base.GetFormat (formatType);
}
}
}
}
}

View File

@@ -0,0 +1,241 @@
//
// DateTimeOffsetConverterTests.cs
//
// Author:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// Copyright (C) 2010 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.
//
#if NET_4_0 && !MOBILE
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class DateTimeOffsetConverterTests
{
DateTimeOffsetConverter converter;
[SetUp]
public void SetUp ()
{
converter = new DateTimeOffsetConverter ();
}
[Test]
public void CanConvertFrom ()
{
Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#A1");
Assert.IsFalse (converter.CanConvertFrom (typeof (DateTime)), "#A2");
Assert.IsFalse (converter.CanConvertFrom (typeof (DateTimeOffset)), "#A3");
Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#A4");
Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#A5");
}
[Test]
public void CanConvertTo ()
{
Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#A1");
Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#A2");
Assert.IsFalse (converter.CanConvertTo (typeof (DateTime)), "#A3");
Assert.IsFalse (converter.CanConvertTo (typeof (DateTimeOffset)), "#A4");
Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "#A5");
}
[Test]
public void ConvertFrom_String ()
{
DateTimeOffset dateOffset = DateTimeOffset.Now;
DateTimeOffset newDateOffset = (DateTimeOffset) converter.ConvertFrom (null, CultureInfo.InvariantCulture,
dateOffset.ToString (CultureInfo.InvariantCulture));
Assert.AreEqual (dateOffset.Date, newDateOffset.Date, "#A1");
Assert.AreEqual (dateOffset.Hour, newDateOffset.Hour, "#A2");
Assert.AreEqual (dateOffset.Minute, newDateOffset.Minute, "#A3");
Assert.AreEqual (dateOffset.Second, newDateOffset.Second, "#A4");
Assert.AreEqual (dateOffset.Offset, newDateOffset.Offset, "#A5");
newDateOffset = (DateTimeOffset) converter.ConvertFrom (null, CultureInfo.InvariantCulture, String.Empty);
Assert.AreEqual (DateTimeOffset.MinValue, newDateOffset, "#B1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Object ()
{
converter.ConvertFrom (new object ());
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Int32 ()
{
converter.ConvertFrom (10);
}
[Test]
public void ConvertTo_MinValue ()
{
Assert.AreEqual (String.Empty, converter.ConvertTo (null,
CultureInfo.InvariantCulture, DateTimeOffset.MinValue, typeof (string)), "#A1");
Assert.AreEqual (String.Empty, converter.ConvertTo (null,
CultureInfo.CurrentCulture, DateTimeOffset.MinValue, typeof (string)), "#A2");
Assert.AreEqual (String.Empty, converter.ConvertTo (DateTimeOffset.MinValue,
typeof (string)), "#A3");
}
[Test]
public void ConvertTo_MaxValue ()
{
Assert.AreEqual (DateTimeOffset.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertTo (null, CultureInfo.InvariantCulture, DateTimeOffset.MaxValue,
typeof (string)), "#A1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertTo_object ()
{
converter.ConvertTo (DateTimeOffset.Now, typeof (object));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertTo_int ()
{
converter.ConvertTo (DateTimeOffset.Now, typeof (int));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertTo_DateTime ()
{
converter.ConvertTo (DateTimeOffset.Now, typeof (DateTime));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertTo_DateTimeOffset ()
{
converter.ConvertTo (DateTimeOffset.Now, typeof (DateTimeOffset));
}
[Test]
public void ConvertToString_MinValue ()
{
Assert.AreEqual (String.Empty, converter.ConvertToString (null,
CultureInfo.InvariantCulture, DateTimeOffset.MinValue), "#A1");
Assert.AreEqual (String.Empty, converter.ConvertToString (null, DateTimeOffset.MinValue), "#A2");
Assert.AreEqual (String.Empty, converter.ConvertToString (null,
CultureInfo.CurrentCulture, DateTimeOffset.MinValue), "#A3");
Assert.AreEqual (String.Empty, converter.ConvertToString (DateTimeOffset.MinValue), "#A4");
}
[Test]
public void ConvertToString_MaxValue ()
{
Assert.AreEqual (DateTimeOffset.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertToString (null, CultureInfo.InvariantCulture, DateTimeOffset.MaxValue), "#A1");
}
[Test]
[SetCulture("en-US")]
public void ConvertToString ()
{
CultureInfo ciUS = new CultureInfo("en-US");
CultureInfo ciGB = new CultureInfo("en-GB");
CultureInfo ciDE = new CultureInfo("de-DE");
DateTimeOffset dateOffset = new DateTimeOffset (2008, 12, 31, 23, 59, 58, 5, new TimeSpan (3, 6, 0));
DoTestToString ("12/31/2008 11:59 PM +03:06", dateOffset, ciUS);
DoTestToString ("31/12/2008 23:59 +03:06", dateOffset, ciGB);
DoTestToString ("31.12.2008 23:59 +03:06", dateOffset, ciDE);
DoTestToString ("12/31/2008 23:59:58 +03:06", dateOffset, CultureInfo.InvariantCulture);
Assert.AreEqual ("12/31/2008 23:59:58 +03:06", converter.ConvertToInvariantString (dateOffset), "Invariant");
dateOffset = new DateTimeOffset (new DateTime (2008, 12, 31), new TimeSpan (0, 0, 0));
DoTestToString ("12/31/2008 +00:00", dateOffset, ciUS);
DoTestToString ("31/12/2008 +00:00", dateOffset, ciGB);
DoTestToString ("31.12.2008 +00:00", dateOffset, ciDE);
DoTestToString ("2008-12-31 +00:00", dateOffset, CultureInfo.InvariantCulture);
Assert.AreEqual ("2008-12-31 +00:00", converter.ConvertToInvariantString (dateOffset), "Invariant");
}
void DoTestToString (string expected, DateTimeOffset value, CultureInfo ci)
{
String message = ci.Name;
if (message == null || message.Length == 0)
message = "?Invariant";
Assert.AreEqual (expected, converter.ConvertTo (null, ci, value, typeof (string)), message);
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFrom_InvalidValue ()
{
converter.ConvertFrom ("*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFrom_InvalidValue_Invariant ()
{
converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFromString_InvalidValue ()
{
converter.ConvertFromString ("*1");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertFromString_InvalidValue_Invariant ()
{
converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
}
[Test]
public void ConvertTo_InstanceDescriptor ()
{
DateTimeOffset dto = new DateTimeOffset (new DateTime (2010, 10, 11), new TimeSpan (3, 6, 0));
InstanceDescriptor descriptor = (InstanceDescriptor) converter.ConvertTo (dto, typeof (InstanceDescriptor));
Assert.AreEqual (".ctor", descriptor.MemberInfo.Name, "#A0");
Assert.AreEqual (8, descriptor.Arguments.Count, "#A1");
DateTimeOffset dto2 = (DateTimeOffset) descriptor.Invoke ();
Assert.AreEqual (dto, dto2, "#A2");
}
}
}
#endif

View File

@@ -0,0 +1,385 @@
//
// System.ComponentModel.DecimalConverter test cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2005 Novell, Inc. (http://www.ximian.com)
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class DecimalConverterTests
{
private DecimalConverter converter;
[SetUp]
public void SetUp ()
{
converter = new DecimalConverter ();
}
[Test]
public void CanConvertFrom ()
{
Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertFrom (typeof (decimal)), "#2");
Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#4");
}
[Test]
public void CanConvertTo ()
{
Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
}
[Test]
public void ConvertFrom_String ()
{
Assert.AreEqual (10, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "10"), "#1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Object ()
{
converter.ConvertFrom (new object ());
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertFrom_Int32 ()
{
converter.ConvertFrom (10);
}
[Test]
public void ConvertTo_MinValue ()
{
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertTo (null, CultureInfo.InvariantCulture, decimal.MinValue,
typeof (string)), "#1");
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertTo (null, CultureInfo.CurrentCulture, decimal.MinValue,
typeof (string)), "#2");
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertTo (decimal.MinValue, typeof (string)), "#3");
}
[Test]
public void ConvertTo_MaxValue ()
{
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertTo (null, CultureInfo.InvariantCulture, decimal.MaxValue,
typeof (string)), "#1");
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertTo (null, CultureInfo.CurrentCulture, decimal.MaxValue,
typeof (string)), "#2");
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertTo (decimal.MaxValue, typeof (string)), "#3");
}
[Test]
public void ConvertToString_MinValue ()
{
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertToString (null, CultureInfo.InvariantCulture,
decimal.MinValue), "#1");
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (null, decimal.MinValue), "#2");
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (null, CultureInfo.CurrentCulture,
decimal.MinValue), "#3");
Assert.AreEqual (decimal.MinValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (decimal.MinValue), "#4");
}
[Test]
public void ConvertToString_MaxValue ()
{
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.InvariantCulture),
converter.ConvertToString (null, CultureInfo.InvariantCulture,
decimal.MaxValue), "#1");
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (null, decimal.MaxValue), "#2");
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (null, CultureInfo.CurrentCulture,
decimal.MaxValue), "#3");
Assert.AreEqual (decimal.MaxValue.ToString (CultureInfo.CurrentCulture),
converter.ConvertToString (decimal.MaxValue), "#4");
}
[Test]
public void ConvertToString ()
{
CultureInfo culture = new MyCultureInfo ();
NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
Assert.AreEqual (numberFormatInfo.NegativeSign + "5", converter.ConvertToString (null, culture, (decimal) -5), "#1");
Assert.AreEqual (culture.NumberFormat.NegativeSign + "5", converter.ConvertToString (null, culture, (int) -5), "#2");
}
[Test]
public void ConvertFromString ()
{
CultureInfo culture = new MyCultureInfo ();
NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
Assert.AreEqual (-5, converter.ConvertFrom (null, culture, numberFormatInfo.NegativeSign + "5"));
}
[Test]
public void ConvertFrom_InvalidValue ()
{
try {
converter.ConvertFrom ("*1");
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFrom_InvalidValue_Invariant ()
{
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFrom_Base10_MinOverflow ()
{
string minOverflow = double.MinValue.ToString (
CultureInfo.CurrentCulture);
try {
converter.ConvertFrom (minOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFrom_Base10_MinOverflow_Invariant ()
{
string minOverflow = double.MinValue.ToString (
CultureInfo.InvariantCulture);
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
minOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFrom_Base10_MaxOverflow ()
{
string maxOverflow = double.MaxValue.ToString (
CultureInfo.CurrentCulture);
try {
converter.ConvertFrom (maxOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFrom_Base10_MaxOverflow_Invariant ()
{
string maxOverflow = double.MaxValue.ToString (
CultureInfo.InvariantCulture);
try {
converter.ConvertFrom (null, CultureInfo.InvariantCulture,
maxOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_InvalidValue ()
{
try {
converter.ConvertFromString ("*1");
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_InvalidValue_Invariant ()
{
try {
converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_Base10_MinOverflow ()
{
string minOverflow = double.MinValue.ToString (
CultureInfo.CurrentCulture);
try {
converter.ConvertFromString (minOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_Base10_MinOverflow_Invariant ()
{
string minOverflow = double.MinValue.ToString (
CultureInfo.InvariantCulture);
try {
converter.ConvertFromString (null, CultureInfo.InvariantCulture,
minOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_Base10_MaxOverflow ()
{
string maxOverflow = double.MaxValue.ToString (
CultureInfo.CurrentCulture);
try {
converter.ConvertFromString (maxOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Test]
public void ConvertFromString_Base10_MaxOverflow_Invariant ()
{
string maxOverflow = double.MaxValue.ToString (
CultureInfo.InvariantCulture);
try {
converter.ConvertFromString (null, CultureInfo.InvariantCulture,
maxOverflow);
Assert.Fail ("#1");
} catch (AssertionException) {
throw;
} catch (Exception ex) {
Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
Assert.IsNotNull (ex.InnerException, "#3");
Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
}
}
[Serializable]
private sealed class MyCultureInfo : CultureInfo
{
internal MyCultureInfo ()
: base ("en-US")
{
}
public override object GetFormat (Type formatType)
{
if (formatType == typeof (NumberFormatInfo)) {
NumberFormatInfo nfi = (NumberFormatInfo) ((NumberFormatInfo) base.GetFormat (formatType)).Clone ();
nfi.NegativeSign = "myNegativeSign";
return NumberFormatInfo.ReadOnly (nfi);
} else {
return base.GetFormat (formatType);
}
}
#if NET_2_0
// adding this override in 1.x shows different result in .NET (it is ignored).
// Some compatibility kids might want to fix this issue.
public override NumberFormatInfo NumberFormat {
get {
NumberFormatInfo nfi = (NumberFormatInfo) base.NumberFormat.Clone ();
nfi.NegativeSign = "myNegativeSign";
return nfi;
}
set { throw new NotSupportedException (); }
}
#endif
}
}
}

View File

@@ -0,0 +1,79 @@
//
// 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) 2006 Novell, Inc (http://www.novell.com)
#if !MOBILE
using NUnit.Framework;
using System;
using System.IO;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml.Serialization;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class DefaultBindingPropertyAttributeTest {
[Test]
public void CtorTest ()
{
DefaultBindingPropertyAttribute a;
a = new DefaultBindingPropertyAttribute ("test");
Assert.AreEqual ("test", a.Name, "1");
a = new DefaultBindingPropertyAttribute ();
Assert.AreEqual (null, a.Name, "2");
}
[Test]
public void EqualsTest ()
{
DefaultBindingPropertyAttribute a;
a = new DefaultBindingPropertyAttribute ("test");
Assert.IsFalse (a.Equals (null), "1");
Assert.IsFalse (a.Equals (new DefaultBindingPropertyAttribute ("other")), "2");
Assert.IsFalse (a.Equals (new DefaultBindingPropertyAttribute ("Test")), "3");
Assert.IsTrue (a.Equals (new DefaultBindingPropertyAttribute ("test")), "4");
}
[Test]
public void GetHashCodeTest ()
{
DefaultBindingPropertyAttribute a;
a = new DefaultBindingPropertyAttribute ("test");
Assert.IsFalse (0 == a.GetHashCode (), "1");
}
[Test]
public void DefaultTest ()
{
Assert.AreEqual (DefaultBindingPropertyAttribute.Default, new DefaultBindingPropertyAttribute (), "1");
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More