Test to make sure that setting focus activates the focused
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / GridTableStylesCollectionTest.cs
blob708f284587ba0a9927e841d798de75352ea2bcce
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
22 // Author:
23 // Jordi Mas i Hernandez <jordi@ximian.com>
27 using System;
28 using System.Collections;
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Windows.Forms;
32 using System.Xml;
33 using NUnit.Framework;
35 namespace MonoTests.System.Windows.Forms
37 [TestFixture]
38 class GridTableStylesCollectionTest
40 private bool eventhandled;
41 private object Element;
42 private CollectionChangeAction Action;
43 private int times;
45 [Test]
46 public void TestDefaultValues ()
48 DataGrid grid = new DataGrid ();
49 GridTableStylesCollection sc = grid.TableStyles;
51 Assert.AreEqual (false, sc.IsSynchronized, "IsSynchronized property");
52 Assert.AreEqual (0, sc.Count, "Count");
53 Assert.AreEqual (sc, sc.SyncRoot, "SyncRoot property");
54 Assert.AreEqual (false, ((IList)sc).IsFixedSize, "IsFixedSize property");
55 Assert.AreEqual (false, sc.IsReadOnly, "IsReadOnly property");
58 [Test]
59 public void TestAdd ()
61 DataGrid grid = new DataGrid ();
62 GridTableStylesCollection sc = grid.TableStyles;
63 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
65 // Add single
66 ResetEventData ();
67 DataGridTableStyle ts = new DataGridTableStyle ();
68 ts.MappingName = "Table1";
69 sc.Add (ts);
70 Assert.AreEqual (true, eventhandled, "A1");
71 Assert.AreEqual (ts, Element, "A2");
72 Assert.AreEqual (CollectionChangeAction.Add, Action, "A3");
74 // Add multiple
75 ResetEventData ();
76 sc.AddRange (new DataGridTableStyle [] {new DataGridTableStyle (), new DataGridTableStyle ()});
77 Assert.AreEqual (true, eventhandled, "A4");
78 Assert.AreEqual (null, Element, "A5");
79 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A6");
82 [Test]
83 public void TestAddRange ()
85 DataGrid grid = new DataGrid ();
86 GridTableStylesCollection sc = grid.TableStyles;
87 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
89 ResetEventData ();
90 DataGridTableStyle ts1 = new DataGridTableStyle ();
91 ts1.MappingName = "Table1";
93 DataGridTableStyle ts2 = new DataGridTableStyle ();
94 ts2.MappingName = "Table2";
95 sc.AddRange (new DataGridTableStyle[] {ts1, ts2});
97 Assert.AreEqual (true, eventhandled, "A1");
98 Assert.AreEqual (null, Element, "A2");
99 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
100 Assert.AreEqual (1, times, "A4");
103 [Test]
104 public void TestRemove ()
106 DataGrid grid = new DataGrid ();
107 GridTableStylesCollection sc = grid.TableStyles;
108 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
110 // Add single
111 DataGridTableStyle ts1 = new DataGridTableStyle ();
112 ts1.MappingName = "Table1";
113 sc.Add (ts1);
115 DataGridTableStyle ts2 = new DataGridTableStyle ();
116 ts2.MappingName = "Table2";
117 sc.Add (ts2);
119 DataGridTableStyle ts3 = new DataGridTableStyle ();
120 ts3.MappingName = "Table3";
121 sc.Add (ts3);
123 ResetEventData ();
124 sc.Remove (ts2);
125 Assert.AreEqual (true, eventhandled, "A1");
126 Assert.AreEqual (ts2, Element, "A2");
127 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A3");
128 Assert.AreEqual (2, sc.Count, "A4");
130 ResetEventData ();
131 sc.RemoveAt (0);
132 Assert.AreEqual (true, eventhandled, "A5");
133 Assert.AreEqual (ts1, Element, "A6");
134 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A7");
135 Assert.AreEqual (1, sc.Count, "A8");
137 ResetEventData ();
138 sc.Clear ();
139 Assert.AreEqual (null, Element, "A9");
140 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A10");
144 [Test]
145 public void TestIndexContains ()
147 DataGrid grid = new DataGrid ();
148 GridTableStylesCollection sc = grid.TableStyles;
149 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
151 // Add single
152 DataGridTableStyle ts1 = new DataGridTableStyle ();
153 ts1.MappingName = "Table1";
154 sc.Add (ts1);
156 DataGridTableStyle ts2 = new DataGridTableStyle ();
157 ts2.MappingName = "Table2";
158 sc.Add (ts2);
160 DataGridTableStyle ts3 = new DataGridTableStyle ();
161 ts3.MappingName = "Table3";
162 sc.Add (ts3);
164 ResetEventData ();
165 IList ilist = (IList) sc;
166 Assert.AreEqual (1, ilist.IndexOf (ts2), "A1");
167 Assert.AreEqual (false, sc.Contains ("nothing"), "A2");
168 Assert.AreEqual (true, sc.Contains (ts3), "A3");
171 private void ResetEventData ()
173 times = 0;
174 eventhandled = false;
175 Element = null;
176 Action = (CollectionChangeAction) 0;
179 private void OnEventHandler (object sender, EventArgs e)
181 eventhandled = true;
184 private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)
186 times++;
187 eventhandled = true;
188 Element = e.Element;
189 Action = e.Action;