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,30 @@
2009-06-18 Marek Habersack <mhabersack@novell.com>
* ListViewTest.cs: hushed the output in ListView_Edit ()
2008-11-20 Marek Habersack <mhabersack@novell.com>
* ListViewTest.cs: added tests for several properties.
2008-11-19 Marek Habersack <mhabersack@novell.com>
* EventRecorder.cs: class is now serializable.
* ListViewTest.cs: use system.web Mainsoft test framework.
ListViewPoker is now able to record events.
Added wrappers for ListView protected methods to ListViewPoker,
Added two simple test ITemplate classes.
Added tests for initial values.
Added tests for all the methods which can be tested in a simple
way, without using a real asp.net page.
Added test for the Edit functionality.
2008-10-30 Marek Habersack <mhabersack@novell.com>
* DataPagerFieldCollectionTest.cs: created. Some basic tests for
DataPagerFieldCollection
* EventRecorder.cs: created. A helper class for tests.
* ListViewTest.cs: created. Some basic test for ListView.

View File

@@ -0,0 +1,225 @@
//
// System.Web.UI.WebControls.ListView
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2008 Novell, Inc
//
//
// 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_3_5
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUnit.Framework;
namespace MonoTests.System.Web.UI.WebControls
{
class DataPagerFieldCollectionPoker : DataPagerFieldCollection
{
EventRecorder recorder;
void RecordEvent (string suffix)
{
if (recorder == null)
return;
recorder.Record (suffix);
}
public DataPagerFieldCollectionPoker ()
: base (null)
{
}
public DataPagerFieldCollectionPoker (DataPager pager)
: base (pager)
{
}
public DataPagerFieldCollectionPoker (DataPager pager, EventRecorder recorder)
: base (pager)
{
this.recorder = recorder;
}
public Type[] DoGetKnownTypes ()
{
return base.GetKnownTypes ();
}
public object DoCreateKnownType (int index)
{
return CreateKnownType (index);
}
public void DoOnValidate (object value)
{
OnValidate (value);
}
public void CatchFieldsChangedEvent ()
{
FieldsChanged += new EventHandler (OnFieldsChanged);
}
protected override void OnValidate (object o)
{
RecordEvent ("Enter");
base.OnValidate (o);
RecordEvent ("Leave");
}
protected override void OnClearComplete ()
{
RecordEvent ("Enter");
base.OnClearComplete ();
RecordEvent ("Leave");
}
protected override void OnInsertComplete (int index, object value)
{
RecordEvent ("Enter");
base.OnInsertComplete (index, value);
RecordEvent ("Leave");
}
protected override void OnRemoveComplete (int index, object value)
{
RecordEvent ("Enter");
base.OnRemoveComplete (index, value);
RecordEvent ("Leave");
}
void OnFieldsChanged (object sender, EventArgs args)
{
RecordEvent ("Enter");
RecordEvent ("Leave");
}
}
[TestFixture]
public class DataPagerCollectionTest
{
[Test]
public void GetKnownTypes_Test ()
{
var coll = new DataPagerFieldCollectionPoker ();
Type[] knownTypes = coll.DoGetKnownTypes ();
Assert.AreEqual (3, knownTypes.Length, "#A1");
Assert.AreEqual (typeof (NextPreviousPagerField), knownTypes [0], "#A2");
Assert.AreEqual (typeof (NumericPagerField), knownTypes [1], "#A3");
Assert.AreEqual (typeof (TemplatePagerField), knownTypes [2], "#A4");
}
[Test]
public void CreateKnownTypes_Types ()
{
var coll = new DataPagerFieldCollectionPoker ();
Assert.AreEqual (typeof (NextPreviousPagerField), coll.DoCreateKnownType (0).GetType (), "#A1");
Assert.AreEqual (typeof (NumericPagerField), coll.DoCreateKnownType (1).GetType (), "#A2");
Assert.AreEqual (typeof (TemplatePagerField), coll.DoCreateKnownType (2).GetType (), "#A3");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CreateKnownTypes_Arguments ()
{
var coll = new DataPagerFieldCollectionPoker ();
coll.DoCreateKnownType (3);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void OnValidate_Arguments_Null ()
{
var coll = new DataPagerFieldCollectionPoker ();
coll.DoOnValidate (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void OnValidate_Arguments_NotDataPagerField ()
{
var coll = new DataPagerFieldCollectionPoker ();
coll.DoOnValidate (String.Empty);
}
[Test]
public void DataPagerFieldCollection_Events ()
{
var events = new EventRecorder ();
var coll = new DataPagerFieldCollectionPoker (new DataPager (), events);
coll.CatchFieldsChangedEvent ();
coll.Insert (0, new NextPreviousPagerField ());
Assert.AreEqual (6, events.Count);
Assert.AreEqual ("OnValidate:Enter", events [0], "#A1");
Assert.AreEqual ("OnValidate:Leave", events [1], "#A2");
Assert.AreEqual ("OnInsertComplete:Enter", events [2], "#A3");
Assert.AreEqual ("OnFieldsChanged:Enter", events [3], "#A4");
Assert.AreEqual ("OnFieldsChanged:Leave", events [4], "#A5");
Assert.AreEqual ("OnInsertComplete:Leave", events [5], "#A6");
events.Clear ();
coll.Clear ();
Assert.AreEqual (4, events.Count);
Assert.AreEqual ("OnClearComplete:Enter", events [0], "#B1");
Assert.AreEqual ("OnFieldsChanged:Enter", events [1], "#B2");
Assert.AreEqual ("OnFieldsChanged:Leave", events [2], "#B3");
Assert.AreEqual ("OnClearComplete:Leave", events [3], "#B4");
NextPreviousPagerField field = new NextPreviousPagerField ();
coll.Insert (0, field);
events.Clear ();
coll.Remove (field);
Assert.AreEqual (8, events.Count);
Assert.AreEqual ("OnValidate:Enter", events [0], "#C1");
Assert.AreEqual ("OnValidate:Leave", events [1], "#C2");
Assert.AreEqual ("OnValidate:Enter", events [2], "#C3");
Assert.AreEqual ("OnValidate:Leave", events [3], "#C4");
Assert.AreEqual ("OnRemoveComplete:Enter", events [4], "#C5");
Assert.AreEqual ("OnFieldsChanged:Enter", events [5], "#C6");
Assert.AreEqual ("OnFieldsChanged:Leave", events [6], "#C7");
Assert.AreEqual ("OnRemoveComplete:Leave", events [7], "#C8");
coll.Insert (0, field);
events.Clear ();
coll.RemoveAt (0);
Assert.AreEqual (4, events.Count);
Assert.AreEqual ("OnRemoveComplete:Enter", events [0], "#D1");
Assert.AreEqual ("OnFieldsChanged:Enter", events [1], "#D2");
Assert.AreEqual ("OnFieldsChanged:Leave", events [2], "#D3");
Assert.AreEqual ("OnRemoveComplete:Leave", events [3], "#D4");
}
}
}
#endif

View File

@@ -0,0 +1,58 @@
//
// System.Web.UI.WebControls.ListView
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2008 Novell, Inc
//
//
// 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_3_5
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
namespace MonoTests.System.Web.UI.WebControls
{
[Serializable]
public sealed class EventRecorder : List <string>
{
List <string> list;
public EventRecorder ()
{
list = (List <string>)this;
}
public void Record (string suffix)
{
var sf = new StackFrame (2);
MethodBase mb = sf.GetMethod ();
list.Add (mb.Name + ":" + suffix);
sf = null;
mb = null;
}
}
}
#endif

View File

@@ -0,0 +1,232 @@
//
// System.Web.UI.WebControls.ListView
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2009 Novell, Inc
//
//
// 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_3_5
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUnit.Framework;
using MonoTests.SystemWeb.Framework;
using MonoTests.stand_alone.WebHarness;
namespace MonoTests.System.Web.UI.WebControls
{
[TestFixture]
public class ListViewPagedDataSourceTest
{
string EnumerableToString (IEnumerable data)
{
var sb = new StringBuilder ();
foreach (object d in data)
sb.Append (d.ToString ());
return sb.ToString ();
}
List<string> GetData (int count)
{
var ret = new List<string> ();
for (int i = 0; i < count; i++)
ret.Add (i.ToString ());
return ret;
}
ListViewPagedDataSource GetDataSource (List<string> ds, int startRowIndex, int maximumRows, int totalRowCount, bool allowServerPaging)
{
var ret = new ListViewPagedDataSource ();
ret.DataSource = ds;
ret.StartRowIndex = startRowIndex;
ret.MaximumRows = maximumRows;
ret.TotalRowCount = totalRowCount;
ret.AllowServerPaging = allowServerPaging;
return ret;
}
[Test]
public void Counts ()
{
List<string> l = GetData (10);
ListViewPagedDataSource pds = GetDataSource (l, 0, 10, 25, false);
Assert.AreEqual (10, pds.Count, "#A1-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A1-2");
pds = GetDataSource (l, 0, 10, 25, true);
Assert.AreEqual (10, pds.Count, "#A2-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A2-2");
pds = GetDataSource (l, 10, 10, 25, false);
Assert.AreEqual (0, pds.Count, "#A3-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A3-2");
pds = GetDataSource (l, 10, 10, 25, true);
Assert.AreEqual (10, pds.Count, "#A4-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A4-2");
pds = GetDataSource (l, 15, 10, 25, false);
Assert.AreEqual (-5, pds.Count, "#A5-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A5-2");
pds = GetDataSource (l, 15, 10, 25, true);
Assert.AreEqual (10, pds.Count, "#A6-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A6-2");
pds = GetDataSource (l, 20, 10, 25, false);
Assert.AreEqual (-10, pds.Count, "#A7-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A7-2");
pds = GetDataSource (l, 20, 10, 25, true);
Assert.AreEqual (5, pds.Count, "#A8-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A8-2");
pds = GetDataSource (l, 25, 10, 25, false);
Assert.AreEqual (-15, pds.Count, "#A9-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A9-2");
pds = GetDataSource (l, 25, 10, 25, true);
Assert.AreEqual (0, pds.Count, "#A10-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A10-2");
pds = GetDataSource (l, 30, 10, 25, false);
Assert.AreEqual (-20, pds.Count, "#A11-1");
Assert.AreEqual (10, pds.DataSourceCount, "#A11-2");
pds = GetDataSource (l, 30, 10, 25, true);
Assert.AreEqual (-5, pds.Count, "#A12-1");
Assert.AreEqual (25, pds.DataSourceCount, "#A12-2");
l = GetData (11);
pds = GetDataSource (l, 0, 11, 25, false);
Assert.AreEqual (11, pds.Count, "#B1-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B1-2");
pds = GetDataSource (l, 0, 11, 25, true);
Assert.AreEqual (11, pds.Count, "#B2-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B2-2");
pds = GetDataSource (l, 10, 11, 25, false);
Assert.AreEqual (1, pds.Count, "#B3-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B3-2");
pds = GetDataSource (l, 10, 11, 25, true);
Assert.AreEqual (11, pds.Count, "#B4-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B4-2");
pds = GetDataSource (l, 15, 11, 25, false);
Assert.AreEqual (-4, pds.Count, "#B5-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B5-2");
pds = GetDataSource (l, 15, 11, 25, true);
Assert.AreEqual (10, pds.Count, "#B6-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B6-2");
pds = GetDataSource (l, 20, 11, 25, false);
Assert.AreEqual (-9, pds.Count, "#B7-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B7-2");
pds = GetDataSource (l, 20, 11, 25, true);
Assert.AreEqual (5, pds.Count, "#B8-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B8-2");
pds = GetDataSource (l, 25, 11, 25, false);
Assert.AreEqual (-14, pds.Count, "#B9-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B9-2");
pds = GetDataSource (l, 25, 11, 25, true);
Assert.AreEqual (0, pds.Count, "#B10-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B10-2");
pds = GetDataSource (l, 30, 11, 25, false);
Assert.AreEqual (-19, pds.Count, "#B11-1");
Assert.AreEqual (11, pds.DataSourceCount, "#B11-2");
pds = GetDataSource (l, 30, 11, 25, true);
Assert.AreEqual (-5, pds.Count, "#B12-1");
Assert.AreEqual (25, pds.DataSourceCount, "#B12-2");
}
[Test]
public void Enumerator ()
{
List<string> l = GetData (10);
ListViewPagedDataSource pds = GetDataSource (l, 0, 10, 25, false);
Assert.AreEqual ("0123456789", EnumerableToString (pds), "#A1");
pds = GetDataSource (l, 5, 10, 25, false);
Assert.AreEqual ("56789", EnumerableToString (pds), "#A2");
pds = GetDataSource (l, 9, 10, 25, false);
Assert.AreEqual ("9", EnumerableToString (pds), "#A3");
pds = GetDataSource (l, 10, 10, 25, false);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A4");
pds = GetDataSource (l, 20, 10, 25, false);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A5");
pds = GetDataSource (l, 25, 10, 25, false);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A6");
pds = GetDataSource (l, 30, 10, 25, false);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A7");
pds = GetDataSource (l, 0, 10, 25, true);
Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B1");
pds = GetDataSource (l, 5, 10, 25, true);
Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B2");
pds = GetDataSource (l, 9, 10, 25, true);
Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B3");
pds = GetDataSource (l, 10, 10, 25, true);
Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B4");
pds = GetDataSource (l, 20, 10, 25, true);
Assert.AreEqual ("01234", EnumerableToString (pds), "#B5");
pds = GetDataSource (l, 25, 10, 25, true);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#B6");
pds = GetDataSource (l, 30, 10, 25, true);
Assert.AreEqual (String.Empty, EnumerableToString (pds), "#B7");
}
}
}
#endif

File diff suppressed because it is too large Load Diff