Test to make sure that setting focus activates the focused
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridTest.cs
blob4d013ff3de3514a2bb5cc3fe843eb9a21d86407a
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;
34 using System.Data;
36 namespace MonoTests.System.Windows.Forms
38 // Helper classes
40 class TestDataGrid : DataGrid
42 public TestDataGrid ()
47 public CurrencyManager Manager {
48 get {
49 return ListManager;
54 [TestFixture]
55 public class DataGridTest
57 private bool eventhandled;
59 [TearDown]
60 public void Clean() {}
62 [SetUp]
63 public void GetReady ()
67 [Test]
68 public void TestDefaultValues ()
70 DataGrid dg = new DataGrid ();
72 Assert.AreEqual (true, dg.AllowNavigation, "AllowNavigation property");
73 Assert.AreEqual (true, dg.AllowSorting, "AllowSorting property");
74 Assert.AreEqual (BorderStyle.Fixed3D, dg.BorderStyle, "BorderStyle property");
75 Assert.AreEqual (string.Empty, dg.CaptionText, "CaptionText property");
76 Assert.AreEqual (true, dg.CaptionVisible, "CaptionVisible property");
77 Assert.AreEqual (true, dg.ColumnHeadersVisible, "ColumnHeadersVisible property");
78 Assert.AreEqual (new DataGridCell (), dg.CurrentCell, "CurrentCell property");
79 Assert.AreEqual (-1, dg.CurrentRowIndex, "CurrentRowIndex property");
80 Assert.AreEqual (string.Empty, dg.DataMember, "DataMember property");
81 Assert.AreEqual (null, dg.DataSource, "DataSource property");
82 Assert.AreEqual (0, dg.FirstVisibleColumn, "FirstVisibleColumn property");
83 Assert.AreEqual (false, dg.FlatMode, "FlatMode property");
84 Assert.AreEqual (DataGridLineStyle.Solid, dg.GridLineStyle, "GridLineStyle property");
85 Assert.AreEqual (DataGridParentRowsLabelStyle.Both, dg.ParentRowsLabelStyle, "ParentRowsLabelStyle property");
86 Assert.AreEqual (true, dg.ParentRowsVisible, "ParentRowsVisible property");
87 Assert.AreEqual (75, dg.PreferredColumnWidth, "PreferredColumnWidth property");
88 //Assert.AreEqual (16, dg.PreferredRowHeight, "PreferredRowHeight property");
89 Assert.AreEqual (false, dg.ReadOnly, "ReadOnly property");
90 Assert.AreEqual (true, dg.RowHeadersVisible, "RowHeadersVisible property");
91 Assert.AreEqual (35, dg.RowHeaderWidth, "RowHeaderWidth property");
92 Assert.AreEqual (null, dg.Site, "Site property");
93 Assert.AreEqual (string.Empty, dg.Text, "Text property");
94 Assert.AreEqual (0, dg.VisibleColumnCount, "VisibleColumnCount property");
97 [Test]
98 public void TestAllowNavigationChangedEvent ()
100 DataGrid dg = new DataGrid ();
101 eventhandled = false;
102 dg.AllowNavigationChanged += new EventHandler (OnEventHandler);
103 dg.AllowNavigation = !dg.AllowNavigation;
104 Assert.AreEqual (true, eventhandled, "A1");
107 [Test]
108 public void TestBackgroundColorChangedEvent ()
110 DataGrid dg = new DataGrid ();
111 eventhandled = false;
112 dg.BackgroundColorChanged += new EventHandler (OnEventHandler);
113 dg.BackgroundColor = Color.Red;
114 Assert.AreEqual (true, eventhandled, "A1");
117 [Test]
118 public void TestBorderStyleChangedEvent ()
120 DataGrid dg = new DataGrid ();
121 eventhandled = false;
122 dg.BorderStyleChanged += new EventHandler (OnEventHandler);
123 dg.BorderStyle = BorderStyle.None;
124 Assert.AreEqual (true, eventhandled, "A1");
127 [Test]
128 public void TestCaptionVisibleChangedEvent ()
130 DataGrid dg = new DataGrid ();
131 eventhandled = false;
132 dg.CaptionVisibleChanged += new EventHandler (OnEventHandler);
133 dg.CaptionVisible = !dg.CaptionVisible;
134 Assert.AreEqual (true, eventhandled, "A1");
137 [Test]
138 public void TestFlatModeChangedEvent ()
140 DataGrid dg = new DataGrid ();
141 eventhandled = false;
142 dg.FlatModeChanged += new EventHandler (OnEventHandler);
143 dg.FlatMode = !dg.FlatMode;
144 Assert.AreEqual (true, eventhandled, "A1");
147 [Test]
148 public void TestParentRowsLabelStyleChangedEvent ()
150 DataGrid dg = new DataGrid ();
151 eventhandled = false;
152 dg.ParentRowsLabelStyleChanged += new EventHandler (OnEventHandler);
153 dg.ParentRowsLabelStyle = DataGridParentRowsLabelStyle.None;
154 Assert.AreEqual (true, eventhandled, "A1");
157 [Test]
158 public void TestParentRowsVisibleChangedEvent ()
160 DataGrid dg = new DataGrid ();
161 eventhandled = false;
162 dg.ParentRowsVisibleChanged += new EventHandler (OnEventHandler);
163 dg.ParentRowsVisible = !dg.ParentRowsVisible;
164 Assert.AreEqual (true, eventhandled, "A1");
167 [Test]
168 public void TestReadOnlyChangedEvent ()
170 DataGrid dg = new DataGrid ();
171 eventhandled = false;
172 dg.ReadOnlyChanged += new EventHandler (OnEventHandler);
173 dg.ReadOnly = !dg.ReadOnly;
174 Assert.AreEqual (true, eventhandled, "A1");
177 public void OnEventHandler (object sender, EventArgs e)
179 eventhandled = true;
182 // Property exceptions
184 [Test]
185 [ExpectedException (typeof (ArgumentException))]
186 public void GridLineColorException ()
188 DataGrid dg = new DataGrid ();
189 dg.GridLineColor = Color.Empty;
192 [Test]
193 [ExpectedException (typeof (ArgumentException))]
194 public void HeaderBackColorException ()
196 DataGrid dg = new DataGrid ();
197 dg.HeaderBackColor = Color.Empty;
200 [Test]
201 [ExpectedException (typeof (ArgumentException))]
202 public void PreferredColumnWidthException ()
204 DataGrid dg = new DataGrid ();
205 dg.PreferredColumnWidth = -1;
208 [Test]
209 public void ResetAlternatingBackColor ()
211 DataGrid dg = new DataGrid ();
212 DataGrid dg2 = new DataGrid ();
213 dg2.AlternatingBackColor = Color.Red;
214 dg2.ResetAlternatingBackColor ();
215 Assert.AreEqual (dg.AlternatingBackColor, dg2.AlternatingBackColor, "A1");
218 // Test reset colour methods
219 [Test]
220 public void ResetBackColorMethod ()
222 DataGrid dg = new DataGrid ();
223 DataGrid dg2 = new DataGrid ();
224 dg2.BackColor = Color.Red;
225 dg2.ResetBackColor ();
226 Assert.AreEqual (dg.BackColor, dg2.BackColor, "A1");
229 [Test]
230 public void ResetForeColorMethod ()
232 DataGrid dg = new DataGrid ();
233 DataGrid dg2 = new DataGrid ();
234 dg2.ForeColor = Color.Red;
235 dg2.ResetForeColor ();
236 Assert.AreEqual (dg.ForeColor, dg2.ForeColor, "A1");
239 [Test]
240 public void ResetGridLineColorMethod ()
242 DataGrid dg = new DataGrid ();
243 DataGrid dg2 = new DataGrid ();
244 dg2.GridLineColor = Color.Red;
245 dg2.ResetGridLineColor ();
246 Assert.AreEqual (dg.GridLineColor, dg2.GridLineColor, "A1");
249 [Test]
250 public void ResetHeaderBackColorMethod ()
252 DataGrid dg = new DataGrid ();
253 DataGrid dg2 = new DataGrid ();
254 dg2.HeaderBackColor = Color.Red;
255 dg2.ResetHeaderBackColor ();
256 Assert.AreEqual (dg.HeaderBackColor, dg2.HeaderBackColor, "A1");
259 [Test]
260 public void ResetHeaderFontMethod ()
264 [Test]
265 public void ResetHeaderForeColorMethod ()
267 DataGrid dg = new DataGrid ();
268 DataGrid dg2 = new DataGrid ();
269 dg2.HeaderForeColor = Color.Red;
270 dg2.ResetHeaderForeColor ();
271 Assert.AreEqual (dg.HeaderForeColor, dg2.HeaderForeColor, "A1");
274 [Test]
275 public void ResetLinkColorMethod ()
277 DataGrid dg = new DataGrid ();
278 DataGrid dg2 = new DataGrid ();
279 dg2.LinkColor = Color.Red;
280 dg2.ResetLinkColor ();
281 Assert.AreEqual (dg.LinkColor, dg2.LinkColor, "A1");
284 [Test]
285 public void ResetLinkHoverColor ()
287 DataGrid dg = new DataGrid ();
288 DataGrid dg2 = new DataGrid ();
289 dg2.LinkHoverColor = Color.Red;
290 dg2.ResetLinkHoverColor ();
291 Assert.AreEqual (dg.LinkHoverColor, dg2.LinkHoverColor, "A1");
294 [Test]
295 public void ResetSelectionBackColor ()
297 DataGrid dg = new DataGrid ();
298 DataGrid dg2 = new DataGrid ();
299 dg2.SelectionBackColor = Color.Red;
300 dg2.ResetSelectionBackColor ();
301 Assert.AreEqual (dg.SelectionBackColor, dg2.SelectionBackColor, "A1");
304 [Test]
305 public void ResetSelectionForeColor ()
307 DataGrid dg = new DataGrid ();
308 DataGrid dg2 = new DataGrid ();
309 dg2.SelectionForeColor = Color.Red;
310 dg2.ResetSelectionForeColor ();
311 Assert.AreEqual (dg.SelectionForeColor, dg2.SelectionForeColor, "A1");
314 [Test]
315 public void TestSetDataBinding ()
317 DataGrid dg = new DataGrid ();
318 DataSet ds = new DataSet ("DataSet");
319 DataTable dt = new DataTable ("DataTable");
320 DataColumn dc = new DataColumn ("C");
321 ds.Tables.Add (dt);
323 dg.SetDataBinding (ds, "DataTable");