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,78 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Brian O'Keefe (zer0keefie@gmail.com)
//
using System;
using NUnit.Framework;
using System.ComponentModel;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class CurrentChangingEventArgsTest {
public CurrentChangingEventArgsTest()
{
}
[Test]
public void CurrentChangingEventArgsConstructor1Test()
{
CurrentChangingEventArgs args = new CurrentChangingEventArgs ();
Assert.IsFalse (args.Cancel, "CTOR1_#1");
Assert.IsTrue (args.IsCancelable, "CTOR1_#2");
}
[Test]
public void CurrentChangingEventArgsConstructor2Test()
{
CurrentChangingEventArgs args = new CurrentChangingEventArgs (false);
Assert.IsFalse (args.Cancel, "CTOR2_#1");
Assert.IsFalse (args.IsCancelable, "CTOR2_#2");
args = new CurrentChangingEventArgs (true);
Assert.IsFalse (args.Cancel, "CTOR1_#3");
Assert.IsTrue (args.IsCancelable, "CTOR1_#4");
args.Cancel = true;
Assert.IsTrue (args.Cancel, "CTOR1_#5");
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void ChangeCancelIfNotCancelableTest()
{
CurrentChangingEventArgs args = new CurrentChangingEventArgs (false);
Assert.IsFalse (args.Cancel, "InvOp_#1");
Assert.IsFalse (args.IsCancelable, "InvOp_#2");
args.Cancel = true;
}
}
}

View File

@@ -0,0 +1,68 @@
//
// GroupDescriptionTest.cs
//
// Author:
// Antonius Riha <antoniusriha@gmail.com>
//
// Copyright (c) 2014 Antonius Riha
//
// 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 System.Globalization;
using NUnit.Framework;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class GroupDescriptionTest
{
[Test]
public void NamesMatch ()
{
var gd = new ConcreteGroupDescription ();
var obj = new object ();
Assert.IsTrue (gd.NamesMatch (obj, obj), "A1");
Assert.IsFalse (gd.NamesMatch (new object (), new object ()), "A2");
}
[Test]
public void ShouldSerializeGroupNames ()
{
var g = new ConcreteGroupDescription ();
g.GroupNames.Add ("name");
Assert.IsTrue (g.ShouldSerializeGroupNames (), "#A1");
}
[Test]
public void ShouldSerializeGroupNamesEmpty ()
{
var g = new ConcreteGroupDescription ();
Assert.IsFalse (g.ShouldSerializeGroupNames (), "#A1");
}
class ConcreteGroupDescription : GroupDescription
{
public override object GroupNameFromItem (object item, int level, CultureInfo culture)
{
throw new NotSupportedException ();
}
}
}
}

View File

@@ -0,0 +1,287 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Brian O'Keefe (zer0keefie@gmail.com)
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.ComponentModel;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class PropertyFilterAttributeTest
{
public PropertyFilterAttributeTest()
{
}
[Test]
public void PropertyFilterAttributeFilterTest()
{
Assert.AreEqual (PropertyFilterOptions.All, PropertyFilterAttribute.Default.Filter, "Filter_#1");
Assert.AreEqual (PropertyFilterOptions.None, new PropertyFilterAttribute(PropertyFilterOptions.None).Filter, "Filter_#2");
Assert.AreEqual (PropertyFilterOptions.SetValues, new PropertyFilterAttribute (PropertyFilterOptions.SetValues).Filter, "Filter_#3");
Assert.AreEqual (PropertyFilterOptions.Valid.GetHashCode(), new PropertyFilterAttribute (PropertyFilterOptions.Valid).GetHashCode(), "Filter_#4");
}
private static PropertyFilterAttribute [] CreateAllAttributeOptions()
{
// This iterates over all possible combinations
PropertyFilterAttribute [] opts = new PropertyFilterAttribute [16];
for (int i = 0; i < 16; i++) {
// Note: This is certainly not an ideal technique for this, but it saves space
opts [i] = new PropertyFilterAttribute ((PropertyFilterOptions)i);
}
return opts;
}
private static readonly PropertyFilterAttribute [] AllAttributeOptions = CreateAllAttributeOptions ();
private static void ValidateFilterValues(PropertyFilterAttribute test, bool[] matchResults, int equalsResult, string message)
{
for (int i = 0; i < 16; i++) {
Assert.AreEqual(matchResults[i], test.Match(AllAttributeOptions[i]),
message + " - Match - Iteration " + i + ": " +
Enum.GetName(typeof(PropertyFilterOptions), (PropertyFilterOptions)i));
Assert.AreEqual (equalsResult == i, test.Equals (AllAttributeOptions [i]),
message + " - Equals - Iteration " + i + ": " +
Enum.GetName (typeof (PropertyFilterOptions), (PropertyFilterOptions)i));
}
}
[Test]
public void PropertyFilterAttributeOptionsNoneTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.None);
bool [] matches = new bool [] {
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.None, "None");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid);
bool [] matches = new bool [] {
false, true, false, true, false, true, false, true,
false, true, false, true, false, true, false, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.Invalid, "Invalid");
}
[Test]
public void PropertyFilterAttributeOptionsSetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues);
bool [] matches = new bool [] {
false, false, true, true, false, false, true, true,
false, false, true, true, false, false, true, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.SetValues, "SetValues");
}
[Test]
public void PropertyFilterAttributeOptionsUnsetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.UnsetValues);
bool [] matches = new bool [] {
false, false, false, false, true, true, true, true,
false, false, false, false, true, true, true, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.UnsetValues, "UnsetValues");
}
[Test]
public void PropertyFilterAttributeOptionsValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
true, true, true, true, true, true, true, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.Valid, "Valid");
}
[Test]
public void PropertyFilterAttributeOptionsAllTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.All);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, true,
};
ValidateFilterValues (all, matches, (int)PropertyFilterOptions.All, "All");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidSetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues);
bool [] matches = new bool [] {
false, false, false, true, false, false, false, true,
false, false, false, true, false, false, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues), "Invalid|SetValues");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidUnsetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.UnsetValues);
bool [] matches = new bool [] {
false, false, false, false, false, true, false, true,
false, false, false, false, false, true, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.UnsetValues), "Invalid|UnsetValues");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, true, false, true, false, true, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.Valid), "Invalid|Valid");
}
[Test]
public void PropertyFilterAttributeOptionsSetValuesUnsetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues);
bool [] matches = new bool [] {
false, false, false, false, false, false, true, true,
false, false, false, false, false, false, true, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues), "SetValues|UnsetValues");
}
[Test]
public void PropertyFilterAttributeOptionsSetValuesValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, true, true, false, false, true, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.SetValues | PropertyFilterOptions.Valid), "SetValues|Valid");
}
[Test]
public void PropertyFilterAttributeOptionsUnsetValuesValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, false, false, true, true, true, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid), "UnsetValues|Valid");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidSetValuesUnsetValuesTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, true,
false, false, false, false, false, false, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues), "Invalid|SetValues|UnsetValues");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidSetValuesValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, false, true, false, false, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.Valid), "Invalid|SetValues|Valid");
}
[Test]
public void PropertyFilterAttributeOptionsInvalidUnsetValuesValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, false, false, false, true, false, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid), "Invalid|UnsetValues|Valid");
}
[Test]
public void PropertyFilterAttributeOptionsSetValuesUnsetValuesValidTest()
{
PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid);
bool [] matches = new bool [] {
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, true, true,
};
ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid), "SetValues|UnsetValues|Valid");
}
}
}

View File

@@ -0,0 +1,202 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Brian O'Keefe (zer0keefie@gmail.com)
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.ComponentModel;
using System.Collections.Specialized;
namespace MonoTests.System.ComponentModel {
[TestFixture]
public class SortDescriptionCollectionTest
{
public SortDescriptionCollectionTest()
{
}
[Test]
public void SortDescriptionCollectionAddTest()
{
SortDescriptionCollection sdc = new SortDescriptionCollection ();
SortDescription addedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
Assert.AreEqual (NotifyCollectionChangedAction.Add, e.Action, "ADD_#0");
addedItem = (SortDescription)e.NewItems [0];
Assert.AreEqual (true, addedItem.IsSealed, "ADD_#0b");
};
sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
Assert.AreEqual ("A", addedItem.PropertyName, "ADD_#1");
Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADD_#2");
Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");
}
[Test]
public void SortDescriptionCollectionAddNoHandlerTest()
{
SortDescriptionCollection sdc = new SortDescriptionCollection ();
SortDescription addedItem = new SortDescription ("A", ListSortDirection.Ascending);
sdc.Add (addedItem);
addedItem = sdc[0];
Assert.AreEqual ("A", addedItem.PropertyName, "ADDN_#1");
Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADDN_#2");
Assert.AreEqual (true, addedItem.IsSealed, "ADDN_#3");
}
[Test]
public void SortDescriptionCollectionRemoveTest()
{
SortDescriptionCollection sdc = new SortDescriptionCollection ();
SortDescription removedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
Assert.AreEqual (NotifyCollectionChangedAction.Remove, e.Action, "REM_#0");
removedItem = (SortDescription)e.OldItems [0];
Assert.AreEqual (true, removedItem.IsSealed, "REM_#0b");
};
sdc.RemoveAt (0);
Assert.AreEqual ("A", removedItem.PropertyName, "REM_#1");
Assert.AreEqual (ListSortDirection.Ascending, removedItem.Direction, "REM_#2");
Assert.AreEqual (true, removedItem.IsSealed, "REM_#3");
}
[Test]
public void SortDescriptionCollectionClearTest()
{
SortDescriptionCollection sdc = new SortDescriptionCollection ();
bool eventFired = false;
sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
Assert.AreEqual (NotifyCollectionChangedAction.Reset, e.Action, "CLR_#0");
eventFired = true;
};
sdc.Clear ();
Assert.IsTrue (eventFired, "CLR_#1");
}
[Test]
public void SortDescriptionCollectionSetTest()
{
SortDescriptionCollection sdc = new SortDescriptionCollection ();
int addEvent = 0, removeEvent = 0;
SortDescription addedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
SortDescription removedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
switch (e.Action) {
case NotifyCollectionChangedAction.Add:
addEvent++;
addedItem = (SortDescription)e.NewItems [0];
break;
case NotifyCollectionChangedAction.Remove:
removeEvent++;
removedItem = (SortDescription)e.OldItems [0];
break;
default:
Assert.Fail ("SET_#0");
break;
}
};
sdc [0] = new SortDescription ("B", ListSortDirection.Descending);
Assert.AreEqual (1, addEvent, "SET_#1");
Assert.AreEqual (1, removeEvent, "SET_#2");
Assert.AreEqual ("A", removedItem.PropertyName, "REM_#1");
Assert.AreEqual (ListSortDirection.Ascending, removedItem.Direction, "REM_#2");
Assert.AreEqual (true, removedItem.IsSealed, "REM_#3");
Assert.AreEqual ("B", addedItem.PropertyName, "ADD_#1");
Assert.AreEqual (ListSortDirection.Descending, addedItem.Direction, "ADD_#2");
Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");
}
[Test]
public void GetEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
CollectionAssert.IsEmpty (collection, "A1");
}
[Test]
[ExpectedException (typeof(NotSupportedException))]
public void AddToEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
collection.Add (new SortDescription ());
}
[Test]
public void RemoveFromEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
Assert.IsFalse (collection.Remove (new SortDescription ()), "A1");
}
[Test]
[ExpectedException (typeof(NotSupportedException))]
public void RemoveAtIndexFromEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
collection.RemoveAt (0);
}
[Test]
[ExpectedException (typeof(NotSupportedException))]
public void ClearEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
collection.Clear ();
}
[Test]
[ExpectedException (typeof(NotSupportedException))]
public void InsertIntoEmptyCollection ()
{
var collection = SortDescriptionCollection.Empty;
collection.Insert (0, new SortDescription ());
}
}
}

View File

@@ -0,0 +1,176 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Brian O'Keefe (zer0keefie@gmail.com)
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.ComponentModel;
using System.Reflection;
namespace MonoTests.System.ComponentModel
{
[TestFixture]
public class SortDescriptionTest
{
public SortDescriptionTest()
{
}
[Test]
public void ConstructorTest()
{
string propertyName = "SampleProperty";
SortDescription sd = new SortDescription (propertyName, ListSortDirection.Ascending);
Assert.AreEqual (propertyName, sd.PropertyName, "CTOR_#1");
Assert.AreEqual (ListSortDirection.Ascending, sd.Direction, "CTOR_#2");
Assert.IsFalse (sd.IsSealed, "CTOR_#3");
sd = new SortDescription (propertyName, ListSortDirection.Descending);
Assert.AreEqual (ListSortDirection.Descending, sd.Direction, "CTOR_#3");
sd.Direction = ListSortDirection.Ascending;
Assert.AreEqual (ListSortDirection.Ascending, sd.Direction, "CTOR_#4");
sd.PropertyName = "NewProperty";
Assert.AreEqual("NewProperty", sd.PropertyName, "CTOR_#5");
}
[Test]
public void NullArgumentTest() {
SortDescription sd = new SortDescription(null, ListSortDirection.Ascending);
Assert.IsNull(sd.PropertyName, "NullArg_#1");
}
[Test]
public void EmptyArgumentTest() {
SortDescription sd = new SortDescription(string.Empty, ListSortDirection.Ascending);
Assert.AreEqual(string.Empty, sd.PropertyName, "EmptyArg_#1");
}
[Test]
[ExpectedException(typeof(InvalidEnumArgumentException))]
public void InvalidEnumArgumentTest() {
new SortDescription("Test", (ListSortDirection)3);
}
[Test]
public void NullArgumentAssignmentTest() {
SortDescription sd = new SortDescription("Test", ListSortDirection.Ascending);
sd.PropertyName = null;
Assert.IsNull(sd.PropertyName, "AssignNull_#1");
}
[Test]
public void EmptyArgumentAssignmentTest() {
SortDescription sd = new SortDescription("Test", ListSortDirection.Ascending);
sd.PropertyName = string.Empty;
Assert.AreEqual(string.Empty, sd.PropertyName, "AssignEmpty_#1");
}
[Test]
public void OperatorTest()
{
SortDescription left = new SortDescription ("A", ListSortDirection.Ascending);
SortDescription same = new SortDescription ("A", ListSortDirection.Ascending);
SortDescription diffProp = new SortDescription ("B", ListSortDirection.Ascending);
SortDescription diffDir = new SortDescription ("A", ListSortDirection.Descending);
Assert.IsTrue (left == same, "OP_#1");
Assert.IsFalse (left == diffProp, "OP_#2");
Assert.IsFalse (left == diffDir, "OP_#3");
Assert.IsFalse (left == null, "OP_#4");
Assert.IsFalse (left != same, "OP_#5");
Assert.IsTrue (left != diffProp, "OP_#6");
Assert.IsTrue (left != diffDir, "OP_#7");
Assert.IsTrue (left != null, "OP_#8");
Assert.IsTrue (left.Equals (same), "OP_#9");
Assert.IsFalse (left.Equals (diffProp), "OP_#10");
Assert.IsFalse (left.Equals (diffDir), "OP_#11");
Assert.IsFalse (left.Equals (null), "OP_#12");
}
[Test]
public void ToStringAndHashCodeTest()
{
SortDescription sd = new SortDescription ("Sample", ListSortDirection.Ascending);
Assert.AreEqual ("System.ComponentModel.SortDescription", sd.ToString (), "TSHC_#1");
Assert.AreEqual ("Sample".GetHashCode () ^ ListSortDirection.Ascending.GetHashCode(),
sd.GetHashCode (), "TSHC_#2");
sd = new SortDescription ("Sample", ListSortDirection.Descending);
Assert.AreEqual ("Sample".GetHashCode () ^ ListSortDirection.Descending.GetHashCode (),
sd.GetHashCode (), "TSHC_#3");
sd = new SortDescription(null, ListSortDirection.Descending);
Assert.AreEqual (ListSortDirection.Descending.GetHashCode (), sd.GetHashCode( ), "TSHC_#4");
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void SetSealedPropertyNameTest() {
SortDescription sd = new SortDescription("Test", ListSortDirection.Ascending);
// Need to borrow the add method of SortDescriptionCollection to seal the
// SortDescription (Seal is internal)
SortDescriptionCollection sdc = new SortDescriptionCollection ();
sdc.Add (sd);
sd = sdc [0];
// SD is sealed now.
Assert.IsTrue (sd.IsSealed, "SealedProp_#1");
sd.PropertyName = "NewProperty";
Assert.AreEqual ("NewProperty", sd.PropertyName, "SealedProp_#1");
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void SetSealedDirectionTest() {
SortDescription sd = new SortDescription ("Test", ListSortDirection.Ascending);
// Need to borrow the add method of SortDescriptionCollection to seal the
// SortDescription (Seal is internal)
SortDescriptionCollection sdc = new SortDescriptionCollection ();
sdc.Add (sd);
sd = sdc [0];
// SD is sealed now.
Assert.IsTrue(sd.IsSealed, "SealedProp_#1");
sd.Direction = ListSortDirection.Descending;
Assert.AreEqual (ListSortDirection.Descending, sd.Direction, "SealedProp_#1");
}
}
}