Merge pull request #82 from Unity-Technologies/master-gc-race
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewCellTest.cs
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.
11 // 
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.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26 #if NET_2_0
27
28 using System;
29 using System.Collections;
30 using System.ComponentModel;
31 using System.Drawing;
32 using System.Windows.Forms;
33
34 using NUnit.Framework;
35 using System.Threading;
36
37 namespace MonoTests.System.Windows.Forms
38 {
39         [TestFixture]
40         public class DataGridViewCellTest : TestHelper
41         {
42                 [Test]
43                 public void GetClipboardContentTest ()
44                 {
45                         DataGridViewClipboardCell cell = new DataGridViewClipboardCell ();
46                         
47                         cell.Value = "abc";
48                         Assert.IsNull (cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#01");
49                         
50                         using (DataGridView dgv = new DataGridView ()) {
51                                 dgv.Columns.Add ("A", "A");
52                                 DataGridViewRow row = new DataGridViewRow ();
53                                 row.Cells.Add (cell);
54                                 dgv.Rows.Add (row);
55                                 cell.Selected = true;
56
57                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#A1");
58                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.UnicodeText), "#A2");
59                                 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Html), "#A3");
60                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
61
62                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Text), "#A1");
63                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.UnicodeText), "#A2");
64                                 Assert.AreEqual ("<TR><TD>abc</TD>", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Html), "#A3");
65                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
66
67                                 Assert.AreEqual (string.Format("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Text), "#A1");
68                                 Assert.AreEqual (string.Format ("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.UnicodeText), "#A2");
69                                 Assert.AreEqual ("<TD>abc</TD></TR>", cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Html), "#A3");
70                                 Assert.AreEqual (string.Format ("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.CommaSeparatedValue), "#A4");
71
72                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Text), "#A1");
73                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.UnicodeText), "#A2");
74                                 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Html), "#A3");
75                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.CommaSeparatedValue), "#A4");
76
77                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Text), "#A1");
78                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.UnicodeText), "#A2");
79                                 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Html), "#A3");
80                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.CommaSeparatedValue), "#A4");
81
82                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Text), "#A1");
83                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.UnicodeText), "#A2");
84                                 Assert.AreEqual ("<TABLE><TR><TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Html), "#A3");
85                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
86
87                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Text), "#A1");
88                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.UnicodeText), "#A2");
89                                 Assert.AreEqual ("<TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Html), "#A3");
90                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
91
92                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Text), "#A1");
93                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.UnicodeText), "#A2");
94                                 Assert.AreEqual ("<TABLE><TR><TD>abc</TD>", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Html), "#A3");
95                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.CommaSeparatedValue), "#A4");
96
97                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Text), "#A1");
98                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.UnicodeText), "#A2");
99                                 Assert.AreEqual ("<TR><TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Html), "#A3");
100                                 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.CommaSeparatedValue), "#A4");
101                                 
102                                 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Text), "#A1");
103                                 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.UnicodeText), "#A2");
104                                 Assert.AreEqual ("<TABLE><TR><TD>abc</TD></TR>", cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Html), "#A3");
105                                 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.CommaSeparatedValue), "#A4");
106                                 
107                                 cell.Selected = false;
108
109                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#A1");
110                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.UnicodeText), "#A2");
111                                 Assert.AreEqual ("<TD>&nbsp;</TD>", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Html), "#A3");
112                                 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
113
114                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Text), "#A1");
115                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.UnicodeText), "#A2");
116                                 Assert.AreEqual ("<TR><TD>&nbsp;</TD>", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Html), "#A3");
117                                 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
118
119                                 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Text), "#A1");
120                                 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.UnicodeText), "#A2");
121                                 Assert.AreEqual ("<TD>&nbsp;</TD></TR>", cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Html), "#A3");
122                                 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.CommaSeparatedValue), "#A4");
123
124                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Text), "#A1");
125                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.UnicodeText), "#A2");
126                                 Assert.AreEqual ("<TD>&nbsp;</TD>", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Html), "#A3");
127                                 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.CommaSeparatedValue), "#A4");
128
129                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Text), "#A1");
130                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.UnicodeText), "#A2");
131                                 Assert.AreEqual ("<TD>&nbsp;</TD>", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Html), "#A3");
132                                 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.CommaSeparatedValue), "#A4");
133
134                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Text), "#A1");
135                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.UnicodeText), "#A2");
136                                 Assert.AreEqual ("<TABLE><TR><TD>&nbsp;</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Html), "#A3");
137                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
138
139                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Text), "#A1");
140                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.UnicodeText), "#A2");
141                                 Assert.AreEqual ("<TD>&nbsp;</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Html), "#A3");
142                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
143
144                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Text), "#A1");
145                                 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.UnicodeText), "#A2");
146                                 Assert.AreEqual ("<TABLE><TR><TD>&nbsp;</TD>", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Html), "#A3");
147                                 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.CommaSeparatedValue), "#A4");
148
149                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Text), "#A1");
150                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.UnicodeText), "#A2");
151                                 Assert.AreEqual ("<TR><TD>&nbsp;</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Html), "#A3");
152                                 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.CommaSeparatedValue), "#A4");
153
154                                 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Text), "#A1");
155                                 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.UnicodeText), "#A2");
156                                 Assert.AreEqual ("<TABLE><TR><TD>&nbsp;</TD></TR>", cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Html), "#A3");
157                                 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.CommaSeparatedValue), "#A4");
158                         }
159                 }
160
161                 [Test]
162                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
163                 public void GetClipboardContentTestException ()
164                 {
165                         DataGridViewClipboardCell cell = new DataGridViewClipboardCell ();
166
167                         cell.Value = "abc";
168                         Assert.IsNull (cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#01");
169
170                         using (DataGridView dgv = new DataGridView ()) {
171                                 dgv.Columns.Add ("A", "A");
172                                 DataGridViewRow row = new DataGridViewRow ();
173                                 row.Cells.Add (cell);
174                                 dgv.Rows.Add (row);
175                                 cell.Selected = true;
176
177                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.Text), "#A1");
178                                 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.UnicodeText), "#A2");
179                                 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.Html), "#A3");
180                                 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
181                         }
182                 }
183
184                 [Test]
185                 public void ReadOnlyTest ()
186                 {
187                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
188                                 Assert.IsFalse (dgv.ReadOnly, "1-DGV");
189                                 Assert.IsFalse (dgv.Rows [0].ReadOnly, "1-R0");
190                                 Assert.IsFalse (dgv.Rows [1].ReadOnly, "1-R1");
191                                 Assert.IsFalse (dgv.Columns [0].ReadOnly, "1-C1");
192                                 Assert.IsFalse (dgv.Columns [1].ReadOnly, "1-C1");
193                                 Assert.IsFalse (dgv [0, 0].ReadOnly, "1-C00");
194                                 Assert.IsFalse (dgv [1, 0].ReadOnly, "1-C10");
195                                 Assert.IsFalse (dgv [0, 1].ReadOnly, "1-C01");
196                                 Assert.IsFalse (dgv [1, 1].ReadOnly, "1-C11");
197                         }
198
199
200                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
201                                 dgv.ReadOnly = true;
202                                 Assert.IsTrue (dgv.ReadOnly, "2-DGV");
203                                 Assert.IsTrue (dgv.Rows [0].ReadOnly, "2-R0");
204                                 Assert.IsTrue (dgv.Rows [1].ReadOnly, "2-R1");
205                                 Assert.IsTrue (dgv.Columns [0].ReadOnly, "2-C1");
206                                 Assert.IsTrue (dgv.Columns [1].ReadOnly, "2-C1");
207                                 Assert.IsTrue (dgv [0, 0].ReadOnly, "2-C00");
208                                 Assert.IsTrue (dgv [1, 0].ReadOnly, "2-C10");
209                                 Assert.IsTrue (dgv [0, 1].ReadOnly, "2-C01");
210                                 Assert.IsTrue (dgv [1, 1].ReadOnly, "2-C11");
211                         }
212
213                         // If the DGV is ReadOnly, everything is ReadOnly.
214                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
215                                 dgv.ReadOnly = true;
216                                 Assert.IsTrue (dgv.ReadOnly, "3-DGV");
217                                 dgv.Rows [0].ReadOnly = false;
218                                 Assert.IsTrue (dgv.Rows [0].ReadOnly, "3-R0");
219                                 Assert.IsTrue (dgv.Rows [1].ReadOnly, "3-R1");
220                                 dgv.Columns [0].ReadOnly = false;
221                                 Assert.IsTrue (dgv.Columns [0].ReadOnly, "3-C1");
222                                 Assert.IsTrue (dgv.Columns [1].ReadOnly, "3-C1");
223                                 dgv [0, 0].ReadOnly = false;
224                                 Assert.IsTrue (dgv [0, 0].ReadOnly, "3-C00");
225                                 Assert.IsTrue (dgv [1, 0].ReadOnly, "3-C10");
226                                 Assert.IsTrue (dgv [0, 1].ReadOnly, "3-C01");
227                                 Assert.IsTrue (dgv [1, 1].ReadOnly, "3-C11");
228                         }
229
230                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
231                                 Assert.IsFalse (dgv.ReadOnly, "4-DGV");
232                                 dgv.Rows [0].ReadOnly = true;
233                                 Assert.IsTrue (dgv.Rows [0].ReadOnly, "4-R0");
234                                 Assert.IsFalse (dgv.Rows [1].ReadOnly, "4-R1");
235                                 dgv.Columns [0].ReadOnly = true;
236                                 Assert.IsTrue (dgv.Columns [0].ReadOnly, "4-C1");
237                                 Assert.IsFalse (dgv.Columns [1].ReadOnly, "4-C1");
238                                 Assert.IsTrue (dgv [0, 0].ReadOnly, "4-C00");
239                                 Assert.IsTrue (dgv [1, 0].ReadOnly, "4-C10");
240                                 Assert.IsTrue (dgv [0, 1].ReadOnly, "4-C01");
241                                 Assert.IsFalse (dgv [1, 1].ReadOnly, "4-C11");
242                         }
243
244                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
245                                 Assert.IsFalse (dgv.ReadOnly, "5-DGV");
246                                 dgv.Rows [0].ReadOnly = true;
247                                 Assert.IsTrue (dgv.Rows [0].ReadOnly, "5-R0");
248                                 Assert.IsFalse (dgv.Rows [1].ReadOnly, "5-R1");
249                                 dgv.Columns [0].ReadOnly = true;
250                                 Assert.IsTrue (dgv.Columns [0].ReadOnly, "5-C1");
251                                 Assert.IsFalse (dgv.Columns [1].ReadOnly, "5-C1");
252                                 dgv [0, 0].ReadOnly = false; // Cell override
253                                 Assert.IsFalse (dgv [0, 0].ReadOnly, "5-C00");
254                                 Assert.IsTrue (dgv [1, 0].ReadOnly, "5-C10");
255                                 Assert.IsTrue (dgv [0, 1].ReadOnly, "5-C01");
256                                 Assert.IsFalse (dgv [1, 1].ReadOnly, "5-C11");
257                         }
258                 }
259
260                 [Test]
261                 public void EditTypeTest ()
262                 {
263                         DataGridViewCell cell =new DataGridViewCellMockObject ();
264                         Assert.AreEqual ("DataGridViewTextBoxEditingControl", cell.EditType.Name, "#01");
265                 }
266
267                 [Test]
268                 public void TestDefaultValues ()
269                 {
270                         DataGridViewCell cell = new DataGridViewCellMockObject ();
271
272                         Assert.IsNotNull (cell.AccessibilityObject, "#cell.AccessibilityObject");
273                         Assert.AreEqual (-1, cell.ColumnIndex, "#cell.ColumnIndex");
274                         Assert.IsNotNull (cell.ContentBounds, "#cell.ContentBounds");
275                         Assert.IsNull (cell.ContextMenuStrip, "#cell.ContextMenuStrip");
276                         Assert.IsNull (cell.DataGridView, "#cell.DataGridView");
277                         Assert.IsNull (cell.DefaultNewRowValue, "#cell.DefaultNewRowValue");
278                         Assert.AreEqual (false, cell.Displayed, "#cell.Displayed");
279                         Assert.IsNull (cell.EditedFormattedValue, "#cell.EditedFormattedValue");
280                         Assert.IsNotNull (cell.EditType, "#cell.EditType");
281                         try {
282                                 object zxf = cell.ErrorIconBounds;
283                                 TestHelper.RemoveWarning (zxf);
284                                 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#cell.ErrorIconBounds");
285                         } catch (InvalidOperationException ex) {
286                                 // We don't need to check the specific message
287                                 //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
288                         } catch (Exception ex) {
289                                 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#cell.ErrorIconBounds");
290                         }
291                         Assert.AreEqual (@"", cell.ErrorText, "#cell.ErrorText");
292                         Assert.IsNull (cell.FormattedValue, "#cell.FormattedValue");
293                         Assert.IsNull (cell.FormattedValueType, "#cell.FormattedValueType");
294                         Assert.AreEqual (false, cell.Frozen, "#cell.Frozen");
295                         Assert.AreEqual (false, cell.HasStyle, "#cell.HasStyle");
296                         Assert.AreEqual (DataGridViewElementStates.ResizableSet, cell.InheritedState, "#cell.InheritedState");
297                         try {
298                                 object zxf = cell.InheritedStyle;
299                                 TestHelper.RemoveWarning (zxf);
300                                 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#cell.InheritedStyle");
301                         } catch (InvalidOperationException ex) {
302                                 Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
303                         } catch (Exception ex) {
304                                 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#cell.InheritedStyle");
305                         }
306                         Assert.AreEqual (false, cell.IsInEditMode, "#cell.IsInEditMode");
307                         Assert.IsNull (cell.OwningColumn, "#cell.OwningColumn");
308                         Assert.IsNull (cell.OwningRow, "#cell.OwningRow");
309                         Assert.IsNotNull (cell.PreferredSize, "#cell.PreferredSize");
310                         Assert.AreEqual (false, cell.ReadOnly, "#cell.ReadOnly");
311                         Assert.AreEqual (false, cell.Resizable, "#cell.Resizable");
312                         Assert.AreEqual (-1, cell.RowIndex, "#cell.RowIndex");
313                         Assert.AreEqual (false, cell.Selected, "#cell.Selected");
314                         Assert.IsNotNull (cell.Size, "#cell.Size");
315                         Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#cell.State");
316                         Assert.IsNotNull (cell.Style, "#cell.Style");
317                         Assert.IsNull (cell.Tag, "#cell.Tag");
318                         Assert.AreEqual (@"", cell.ToolTipText, "#cell.ToolTipText");
319                         Assert.IsNull (cell.Value, "#cell.Value");
320                         Assert.IsNull (cell.ValueType, "#cell.ValueType");
321                         Assert.AreEqual (false, cell.Visible, "#cell.Visible");
322                 }
323
324                 [Test]
325                 [NUnit.Framework.Category ("NotWorking")]       // DGVComboBox not implemented
326                 public void AddRow_Changes ()
327                 {
328                         using (DataGridView dgv = new DataGridView ()) {
329                                 DataGridViewColumn col = new DataGridViewComboBoxColumn ();
330                                 DataGridViewRow row = new DataGridViewRow ();
331                                 DataGridViewCell cell = new DataGridViewComboBoxCell ();
332
333                                 Assert.IsNotNull (cell.AccessibilityObject, "#A cell.AccessibilityObject");
334                                 Assert.AreEqual (-1, cell.ColumnIndex, "#A cell.ColumnIndex");
335                                 Assert.IsNotNull (cell.ContentBounds, "#A cell.ContentBounds");
336                                 Assert.IsNull (cell.ContextMenuStrip, "#A cell.ContextMenuStrip");
337                                 Assert.IsNull (cell.DataGridView, "#A cell.DataGridView");
338                                 Assert.IsNull (cell.DefaultNewRowValue, "#A cell.DefaultNewRowValue");
339                                 Assert.AreEqual (false, cell.Displayed, "#A cell.Displayed");
340                                 Assert.IsNull (cell.EditedFormattedValue, "#A cell.EditedFormattedValue");
341                                 Assert.IsNotNull (cell.EditType, "#A cell.EditType");
342                                 try {
343                                         object zxf = cell.ErrorIconBounds;
344                                         TestHelper.RemoveWarning (zxf);
345                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A cell.ErrorIconBounds");
346                                 } catch (InvalidOperationException ex) {
347                                         //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
348                                 } catch (Exception ex) {
349                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A cell.ErrorIconBounds");
350                                 }
351                                 Assert.AreEqual (@"", cell.ErrorText, "#A cell.ErrorText");
352                                 Assert.IsNull (cell.FormattedValue, "#A cell.FormattedValue");
353                                 Assert.IsNotNull (cell.FormattedValueType, "#A cell.FormattedValueType");
354                                 Assert.AreEqual (false, cell.Frozen, "#A cell.Frozen");
355                                 Assert.AreEqual (false, cell.HasStyle, "#A cell.HasStyle");
356                                 Assert.AreEqual (DataGridViewElementStates.ResizableSet, cell.InheritedState, "#A cell.InheritedState");
357                                 try {
358                                         object zxf = cell.InheritedStyle;
359                                         TestHelper.RemoveWarning (zxf);
360                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A cell.InheritedStyle");
361                                 } catch (InvalidOperationException ex) {
362                                         Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
363                                 } catch (Exception ex) {
364                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A cell.InheritedStyle");
365                                 }
366                                 Assert.AreEqual (false, cell.IsInEditMode, "#A cell.IsInEditMode");
367                                 Assert.IsNull (cell.OwningColumn, "#A cell.OwningColumn");
368                                 Assert.IsNull (cell.OwningRow, "#A cell.OwningRow");
369                                 Assert.IsNotNull (cell.PreferredSize, "#A cell.PreferredSize");
370                                 Assert.AreEqual (false, cell.ReadOnly, "#A cell.ReadOnly");
371                                 Assert.AreEqual (false, cell.Resizable, "#A cell.Resizable");
372                                 Assert.AreEqual (-1, cell.RowIndex, "#A cell.RowIndex");
373                                 Assert.AreEqual (false, cell.Selected, "#A cell.Selected");
374                                 Assert.IsNotNull (cell.Size, "#A cell.Size");
375                                 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#A cell.State");
376                                 if (cell.HasStyle)
377                                         Assert.IsNotNull (cell.Style, "#A cell.Style");
378                                 Assert.IsNull (cell.Tag, "#A cell.Tag");
379                                 Assert.AreEqual (@"", cell.ToolTipText, "#A cell.ToolTipText");
380                                 Assert.IsNull (cell.Value, "#A cell.Value");
381                                 Assert.IsNotNull (cell.ValueType, "#A cell.ValueType");
382                                 Assert.AreEqual (false, cell.Visible, "#A cell.Visible");
383                                 
384                                 row.Cells.Add (cell);
385
386                                 Assert.IsNotNull (cell.AccessibilityObject, "#B cell.AccessibilityObject");
387                                 Assert.AreEqual (-1, cell.ColumnIndex, "#B cell.ColumnIndex");
388                                 Assert.IsNotNull (cell.ContentBounds, "#B cell.ContentBounds");
389                                 Assert.IsNull (cell.ContextMenuStrip, "#B cell.ContextMenuStrip");
390                                 Assert.IsNull (cell.DataGridView, "#B cell.DataGridView");
391                                 Assert.IsNull (cell.DefaultNewRowValue, "#B cell.DefaultNewRowValue");
392                                 Assert.AreEqual (false, cell.Displayed, "#B cell.Displayed");
393                                 Assert.IsNull (cell.EditedFormattedValue, "#B cell.EditedFormattedValue");
394                                 Assert.IsNotNull (cell.EditType, "#B cell.EditType");
395                                 try {
396                                         object zxf = cell.ErrorIconBounds;
397                                         TestHelper.RemoveWarning (zxf);
398                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B cell.ErrorIconBounds");
399                                 } catch (InvalidOperationException ex) {
400                                         //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
401                                 } catch (Exception ex) {
402                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B cell.ErrorIconBounds");
403                                 }
404                                 Assert.AreEqual (@"", cell.ErrorText, "#B cell.ErrorText");
405                                 Assert.IsNull (cell.FormattedValue, "#B cell.FormattedValue");
406                                 Assert.IsNotNull (cell.FormattedValueType, "#B cell.FormattedValueType");
407                                 Assert.AreEqual (false, cell.Frozen, "#B cell.Frozen");
408                                 Assert.AreEqual (false, cell.HasStyle, "#B cell.HasStyle");
409                                 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Visible, cell.InheritedState, "#B cell.InheritedState");
410                                 try {
411                                         object zxf = cell.InheritedStyle;
412                                         TestHelper.RemoveWarning (zxf);
413                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B cell.InheritedStyle");
414                                 } catch (InvalidOperationException ex) {
415                                         Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
416                                 } catch (Exception ex) {
417                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B cell.InheritedStyle");
418                                 }
419                                 Assert.AreEqual (false, cell.IsInEditMode, "#B cell.IsInEditMode");
420                                 Assert.IsNull (cell.OwningColumn, "#B cell.OwningColumn");
421                                 Assert.IsNotNull (cell.OwningRow, "#B cell.OwningRow");
422                                 Assert.IsNotNull (cell.PreferredSize, "#B cell.PreferredSize");
423                                 Assert.AreEqual (false, cell.ReadOnly, "#B cell.ReadOnly");
424                                 Assert.AreEqual (false, cell.Resizable, "#B cell.Resizable");
425                                 Assert.AreEqual (-1, cell.RowIndex, "#B cell.RowIndex");
426                                 Assert.AreEqual (false, cell.Selected, "#B cell.Selected");
427                                 Assert.IsNotNull (cell.Size, "#B cell.Size");
428                                 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#B cell.State");
429                                 if (cell.HasStyle)
430                                         Assert.IsNotNull (cell.Style, "#B cell.Style");
431                                 Assert.IsNull (cell.Tag, "#B cell.Tag");
432                                 Assert.AreEqual (@"", cell.ToolTipText, "#B cell.ToolTipText");
433                                 Assert.IsNull (cell.Value, "#B cell.Value");
434                                 Assert.IsNotNull (cell.ValueType, "#B cell.ValueType");
435                                 Assert.AreEqual (true, cell.Visible, "#B cell.Visible");
436                                 
437                                 dgv.Columns.Add (col);
438
439                                 Assert.IsNotNull (cell.AccessibilityObject, "#C cell.AccessibilityObject");
440                                 Assert.AreEqual (-1, cell.ColumnIndex, "#C cell.ColumnIndex");
441                                 Assert.IsNotNull (cell.ContentBounds, "#C cell.ContentBounds");
442                                 Assert.IsNull (cell.ContextMenuStrip, "#C cell.ContextMenuStrip");
443                                 Assert.IsNull (cell.DataGridView, "#C cell.DataGridView");
444                                 Assert.IsNull (cell.DefaultNewRowValue, "#C cell.DefaultNewRowValue");
445                                 Assert.AreEqual (false, cell.Displayed, "#C cell.Displayed");
446                                 Assert.IsNull (cell.EditedFormattedValue, "#C cell.EditedFormattedValue");
447                                 Assert.IsNotNull (cell.EditType, "#C cell.EditType");
448                                 try {
449                                         object zxf = cell.ErrorIconBounds;
450                                         TestHelper.RemoveWarning (zxf);
451                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C cell.ErrorIconBounds");
452                                 } catch (InvalidOperationException ex) {
453                                         //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
454                                 } catch (Exception ex) {
455                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C cell.ErrorIconBounds");
456                                 }
457                                 Assert.AreEqual (@"", cell.ErrorText, "#C cell.ErrorText");
458                                 Assert.IsNull (cell.FormattedValue, "#C cell.FormattedValue");
459                                 Assert.IsNotNull (cell.FormattedValueType, "#C cell.FormattedValueType");
460                                 Assert.AreEqual (false, cell.Frozen, "#C cell.Frozen");
461                                 Assert.AreEqual (false, cell.HasStyle, "#C cell.HasStyle");
462                                 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Visible, cell.InheritedState, "#C cell.InheritedState");
463                                 try {
464                                         object zxf = cell.InheritedStyle;
465                                         TestHelper.RemoveWarning (zxf);
466                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C cell.InheritedStyle");
467                                 } catch (InvalidOperationException ex) {
468                                         Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
469                                 } catch (Exception ex) {
470                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C cell.InheritedStyle");
471                                 }
472                                 Assert.AreEqual (false, cell.IsInEditMode, "#C cell.IsInEditMode");
473                                 Assert.IsNull (cell.OwningColumn, "#C cell.OwningColumn");
474                                 Assert.IsNotNull (cell.OwningRow, "#C cell.OwningRow");
475                                 Assert.IsNotNull (cell.PreferredSize, "#C cell.PreferredSize");
476                                 Assert.AreEqual (false, cell.ReadOnly, "#C cell.ReadOnly");
477                                 Assert.AreEqual (false, cell.Resizable, "#C cell.Resizable");
478                                 Assert.AreEqual (-1, cell.RowIndex, "#C cell.RowIndex");
479                                 Assert.AreEqual (false, cell.Selected, "#C cell.Selected");
480                                 Assert.IsNotNull (cell.Size, "#C cell.Size");
481                                 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#C cell.State");
482                                 if (cell.HasStyle)
483                                         Assert.IsNotNull (cell.Style, "#C cell.Style");
484                                 Assert.IsNull (cell.Tag, "#C cell.Tag");
485                                 Assert.AreEqual (@"", cell.ToolTipText, "#C cell.ToolTipText");
486                                 Assert.IsNull (cell.Value, "#C cell.Value");
487                                 Assert.IsNotNull (cell.ValueType, "#C cell.ValueType");
488                                 Assert.AreEqual (true, cell.Visible, "#C cell.Visible");
489                                 
490                                 dgv.Rows.Add (row);
491
492                                 Assert.IsNotNull (cell.AccessibilityObject, "#D cell.AccessibilityObject");
493                                 Assert.AreEqual (0, cell.ColumnIndex, "#D cell.ColumnIndex");
494                                 try {
495                                         object zxf = cell.ContentBounds;
496                                         TestHelper.RemoveWarning (zxf);
497                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.ContentBounds");
498                                 } catch (ArgumentOutOfRangeException ex) {
499                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
500                                 } catch (Exception ex) {
501                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.ContentBounds");
502                                 }
503                                 Assert.IsNull (cell.ContextMenuStrip, "#D cell.ContextMenuStrip");
504                                 Assert.IsNotNull (cell.DataGridView, "#D cell.DataGridView");
505                                 Assert.IsNull (cell.DefaultNewRowValue, "#D cell.DefaultNewRowValue");
506                                 Assert.AreEqual (false, cell.Displayed, "#D cell.Displayed");
507                                 try {
508                                         object zxf = cell.EditedFormattedValue;
509                                         TestHelper.RemoveWarning (zxf);
510                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.EditedFormattedValue");
511                                 } catch (ArgumentOutOfRangeException ex) {
512                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
513                                 } catch (Exception ex) {
514                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.EditedFormattedValue");
515                                 }
516                                 Assert.IsNotNull (cell.EditType, "#D cell.EditType");
517                                 try {
518                                         object zxf = cell.ErrorIconBounds;
519                                         TestHelper.RemoveWarning (zxf);
520                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.ErrorIconBounds");
521                                 } catch (ArgumentOutOfRangeException ex) {
522                                         //Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
523                                 } catch (Exception ex) {
524                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.ErrorIconBounds");
525                                 }
526                                 Assert.AreEqual (@"", cell.ErrorText, "#D cell.ErrorText");
527                                 try {
528                                         object zxf = cell.FormattedValue;
529                                         TestHelper.RemoveWarning (zxf);
530                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.FormattedValue");
531                                 } catch (ArgumentOutOfRangeException ex) {
532                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
533                                 } catch (Exception ex) {
534                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.FormattedValue");
535                                 }
536                                 Assert.IsNotNull (cell.FormattedValueType, "#D cell.FormattedValueType");
537                                 Assert.AreEqual (false, cell.Frozen, "#D cell.Frozen");
538                                 Assert.AreEqual (false, cell.HasStyle, "#D cell.HasStyle");
539                                 try {
540                                         object zxf = cell.InheritedState;
541                                         TestHelper.RemoveWarning (zxf);
542                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.InheritedState");
543                                 } catch (ArgumentOutOfRangeException ex) {
544                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
545                                 } catch (Exception ex) {
546                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.InheritedState");
547                                 }
548                                 try {
549                                         object zxf = cell.InheritedStyle;
550                                         TestHelper.RemoveWarning (zxf);
551                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.InheritedStyle");
552                                 } catch (ArgumentOutOfRangeException ex) {
553                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
554                                 } catch (Exception ex) {
555                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.InheritedStyle");
556                                 }
557                                 try {
558                                         object zxf = cell.IsInEditMode;
559                                         TestHelper.RemoveWarning (zxf);
560                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D cell.IsInEditMode");
561                                 } catch (InvalidOperationException ex) {
562                                         Assert.AreEqual (@"Operation cannot be performed on a cell of a shared row.", ex.Message);
563                                 } catch (Exception ex) {
564                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D cell.IsInEditMode");
565                                 }
566                                 Assert.IsNotNull (cell.OwningColumn, "#D cell.OwningColumn");
567                                 Assert.IsNotNull (cell.OwningRow, "#D cell.OwningRow");
568                                 try {
569                                         object zxf = cell.PreferredSize;
570                                         TestHelper.RemoveWarning (zxf);
571                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.PreferredSize");
572                                 } catch (ArgumentOutOfRangeException ex) {
573                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
574                                 } catch (Exception ex) {
575                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.PreferredSize");
576                                 }
577                                 Assert.AreEqual (false, cell.ReadOnly, "#D cell.ReadOnly");
578                                 Assert.AreEqual (false, cell.Resizable, "#D cell.Resizable");
579                                 Assert.AreEqual (-1, cell.RowIndex, "#D cell.RowIndex");
580                                 Assert.AreEqual (false, cell.Selected, "#D cell.Selected");
581                                 try {
582                                         object zxf = cell.Size;
583                                         TestHelper.RemoveWarning (zxf);
584                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D cell.Size");
585                                 } catch (InvalidOperationException ex) {
586                                         Assert.AreEqual (@"Getting the Size property of a cell in a shared row is not a valid operation.", ex.Message);
587                                 } catch (Exception ex) {
588                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D cell.Size");
589                                 }
590                                 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#D cell.State");
591                                 if (cell.HasStyle)
592                                         Assert.IsNotNull (cell.Style, "#D cell.Style");
593                                 Assert.IsNull (cell.Tag, "#D cell.Tag");
594                                 Assert.AreEqual (@"", cell.ToolTipText, "#D cell.ToolTipText");
595                                 try {
596                                         object zxf = cell.Value;
597                                         TestHelper.RemoveWarning (zxf);
598                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.Value");
599                                 } catch (ArgumentOutOfRangeException ex) {
600                                         Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
601                                 } catch (Exception ex) {
602                                         Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.Value");
603                                 }
604                                 Assert.IsNotNull (cell.ValueType, "#D cell.ValueType");
605                                 Assert.AreEqual (false, cell.Visible, "#D cell.Visible");
606                         }
607                 }
608
609                 /*
610                 [Test]
611                 [ExpectedException(typeof(Exception))]
612                 public void TestException () {
613                         ConcreteCollection myCollection;
614                         myCollection = new ConcreteCollection();
615                         ....
616                         Assert.AreEqual (expected, actual, "#UniqueID");
617                         ....
618                         Assert.Fail ("Message");
619                 }
620                 */
621
622                 [Test]
623                 public void ColumnIndex ()
624                 {
625                         DataGridViewCell c = new BaseCell ();
626                         Assert.AreEqual (-1, c.ColumnIndex, "A1");
627                         
628                         DataGridView dgv = new DataGridView ();
629                         dgv.Columns.Add ("hi", "there");
630
631                         DataGridViewRow row = new DataGridViewRow ();
632                         row.Cells.Add (c);
633                         dgv.Rows.Add (row);
634
635                         Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
636                 }
637
638                 [Test]
639                 public void ContentBounds ()
640                 {
641                         DataGridViewCell c = new BaseCell ();
642                         Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
643
644                         DataGridView dgv = new DataGridView ();
645                         dgv.Columns.Add ("hi", "there");
646
647                         DataGridViewRow row = new DataGridViewRow ();
648                         row.Cells.Add (c);
649                         dgv.Rows.Add (row);
650
651                         Assert.AreEqual (Rectangle.Empty, dgv.Rows[0].Cells[0].ContentBounds, "A2");
652                 }
653
654                 [Test]
655                 public void ContextMenuStrip ()
656                 {
657                         DataGridViewCell c = new BaseCell ();
658                         Assert.AreEqual (null, c.ContextMenuStrip, "A1");
659
660                         DataGridView dgv = new DataGridView ();
661                         dgv.Columns.Add ("hi", "there");
662
663                         DataGridViewRow row = new DataGridViewRow ();
664                         row.Cells.Add (c);
665                         dgv.Rows.Add (row);
666
667                         ContextMenuStrip cms1 = new ContextMenuStrip ();
668                         cms1.Items.Add ("hey");
669
670                         ContextMenuStrip cms2 = new ContextMenuStrip ();
671                         cms2.Items.Add ("yo");
672                         
673                         dgv.Rows[0].ContextMenuStrip = cms1;
674                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
675                         
676                         dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
677                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
678                 }
679
680                 [Test]
681                 public void DataGridView ()
682                 {
683                         DataGridViewCell c = new BaseCell ();
684                         Assert.AreEqual (null, c.DataGridView, "A1");
685
686                         DataGridView dgv = new DataGridView ();
687                         dgv.Columns.Add ("hi", "there");
688
689                         DataGridViewRow row = new DataGridViewRow ();
690                         row.Cells.Add (c);
691                         dgv.Rows.Add (row);
692
693                         Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
694                 }
695
696                 [Test]
697                 public void DefaultNewRowValue ()
698                 {
699                         DataGridViewCell c = new BaseCell ();
700                         Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
701
702                         DataGridView dgv = new DataGridView ();
703                         dgv.Columns.Add ("hi", "there");
704
705                         DataGridViewRow row = new DataGridViewRow ();
706                         row.Cells.Add (c);
707                         dgv.Rows.Add (row);
708
709                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
710                 }
711
712                 [Test]
713                 public void Displayed ()
714                 {
715                         DataGridViewCell c = new BaseCell ();
716                         Assert.AreEqual (false, c.Displayed, "A1");
717
718                         DataGridView dgv = new DataGridView ();
719                         dgv.Columns.Add ("hi", "there");
720
721                         DataGridViewRow row = new DataGridViewRow ();
722                         row.Cells.Add (c);
723                         dgv.Rows.Add (row);
724
725                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
726                 }
727
728                 [Test]
729                 public void EditedFormattedValue ()
730                 {
731                         DataGridViewCell c = new BaseCell ();
732                         Assert.AreEqual (null, c.EditedFormattedValue, "A1");
733                 }
734
735                 [Test]
736                 public void FormattedValueType ()
737                 {
738                         DataGridViewCell c = new BaseCell ();
739                         Assert.AreEqual (null, c.FormattedValueType, "A1");
740                 }
741
742                 [Test]
743                 public void Frozen ()
744                 {
745                         DataGridViewCell c = new BaseCell ();
746                         Assert.AreEqual (false, c.Frozen, "A1");
747
748                         DataGridView dgv = new DataGridView ();
749                         dgv.Columns.Add ("hi", "there");
750
751                         DataGridViewRow row = new DataGridViewRow ();
752                         row.Cells.Add (c);
753                         dgv.Rows.Add (row);
754
755                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
756
757                         dgv.Columns[0].Frozen = true;
758                         dgv.Rows[0].Frozen = true;
759                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
760                 }
761
762                 [Test]
763                 public void HasStyle ()
764                 {
765                         DataGridViewCell c = new BaseCell ();
766                         Assert.AreEqual (false, c.HasStyle, "A1");
767
768                         DataGridView dgv = new DataGridView ();
769                         dgv.Columns.Add ("hi", "there");
770
771                         DataGridViewRow row = new DataGridViewRow ();
772                         row.Cells.Add (c);
773                         dgv.Rows.Add (row);
774
775                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
776                         
777                         dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
778                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
779                 }
780
781                 [Test]
782                 public void InheritedState ()
783                 {
784                         DataGridViewCell c = new BaseCell ();
785                         Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
786
787                         DataGridView dgv = new DataGridView ();
788                         dgv.Columns.Add ("hi", "there");
789
790                         DataGridViewRow row = new DataGridViewRow ();
791                         row.Cells.Add (c);
792                         dgv.Rows.Add (row);
793
794                         Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
795
796                         dgv.Rows[0].Selected = true;
797                         Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
798
799                         dgv.Rows[0].Selected = false;
800                         dgv.Columns[0].Selected = true;
801                         Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
802                 }
803
804                 [Test]
805                 public void InheritedStyle ()
806                 {
807                         DataGridViewCell c = new BaseCell ();
808                         DataGridView dgv = new DataGridView ();
809                         dgv.Columns.Add ("hi", "there");
810
811                         DataGridViewRow row = new DataGridViewRow ();
812                         row.Cells.Add (c);
813                         dgv.Rows.Add (row);
814
815                         Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
816
817                         dgv.DefaultCellStyle.BackColor = Color.Firebrick;
818                         Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
819
820                         dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
821                         Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
822
823                         dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
824                         Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
825
826                         dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
827                         Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
828
829                         dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
830                         Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
831                 }
832
833                 [Test]
834                 public void IsInEditMode ()
835                 {
836                         DataGridViewCell c = new BaseCell ();
837                         Assert.AreEqual (false, c.IsInEditMode, "A1");
838
839                         DataGridView dgv = new DataGridView ();
840                         dgv.Columns.Add ("hi", "there");
841
842                         DataGridViewRow row = new DataGridViewRow ();
843                         row.Cells.Add (c);
844                         dgv.Rows.Add (row);
845
846                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
847                 }
848
849                 [Test]
850                 public void OwningColumn ()
851                 {
852                         DataGridViewCell c = new BaseCell ();
853                         Assert.AreEqual (null, c.OwningColumn, "A1");
854
855                         DataGridView dgv = new DataGridView ();
856                         dgv.Columns.Add ("hi", "there");
857
858                         DataGridViewRow row = new DataGridViewRow ();
859                         row.Cells.Add (c);
860                         dgv.Rows.Add (row);
861
862                         Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
863                 }
864
865                 [Test]
866                 public void OwningRow ()
867                 {
868                         DataGridViewCell c = new BaseCell ();
869                         Assert.AreEqual (null, c.OwningRow, "A1");
870
871                         DataGridView dgv = new DataGridView ();
872                         dgv.Columns.Add ("hi", "there");
873
874                         DataGridViewRow row = new DataGridViewRow ();
875                         row.Cells.Add (c);
876                         dgv.Rows.Add (row);
877
878                         Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
879                 }
880
881                 [Test]
882                 public void PreferredSize ()
883                 {
884                         DataGridViewCell c = new BaseCell ();
885                         Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
886
887                         DataGridView dgv = new DataGridView ();
888                         dgv.Columns.Add ("hi", "there");
889
890                         DataGridViewRow row = new DataGridViewRow ();
891                         row.Cells.Add (c);
892                         dgv.Rows.Add (row);
893
894                         Assert.AreEqual (new Size (-1, -1), dgv.Rows[0].Cells[0].PreferredSize, "A2");
895                         
896                         // Always returns (-1, -1)
897                         dgv.Rows[0].Cells[0].Value = "bob";
898                         Assert.AreEqual (new Size (-1, -1), dgv.Rows[0].Cells[0].PreferredSize, "A3");
899                 }
900
901                 [Test]
902                 public void ReadOnly ()
903                 {
904                         DataGridViewCell c = new BaseCell ();
905                         Assert.AreEqual (false, c.ReadOnly, "A1");
906
907                         DataGridView dgv = new DataGridView ();
908                         dgv.Columns.Add ("hi", "there");
909
910                         DataGridViewRow row = new DataGridViewRow ();
911                         row.Cells.Add (c);
912                         dgv.Rows.Add (row);
913
914                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
915
916                         dgv.Rows[0].ReadOnly = true;
917                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
918
919                         dgv.Rows[0].Cells[0].ReadOnly = false;
920                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
921                 }
922
923                 [Test]
924                 public void Resizable ()
925                 {
926                         DataGridViewCell c = new BaseCell ();
927                         Assert.AreEqual (false, c.Resizable, "A1");
928
929                         DataGridView dgv = new DataGridView ();
930                         dgv.Columns.Add ("hi", "there");
931
932                         DataGridViewRow row = new DataGridViewRow ();
933                         row.Cells.Add (c);
934                         dgv.Rows.Add (row);
935
936                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
937
938                         dgv.Rows[0].Resizable = DataGridViewTriState.False;
939                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
940
941                         dgv.Columns[0].Resizable = DataGridViewTriState.False;
942                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
943
944                         dgv.Columns[0].Resizable = DataGridViewTriState.True;
945                         dgv.Rows[0].Resizable = DataGridViewTriState.True;
946                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
947
948                         dgv.AllowUserToResizeColumns = false;
949                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
950
951                         dgv.AllowUserToResizeRows = false;
952                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
953
954                         dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
955                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
956
957                         dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
958                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
959                 }
960
961                 [Test]
962                 public void RowIndex ()
963                 {
964                         DataGridViewCell c = new BaseCell ();
965                         Assert.AreEqual (-1, c.RowIndex, "A1");
966
967                         DataGridView dgv = new DataGridView ();
968                         dgv.Columns.Add ("hi", "there");
969
970                         DataGridViewRow row = new DataGridViewRow ();
971                         row.Cells.Add (c);
972                         dgv.Rows.Add (row);
973
974                         Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
975                 }
976
977                 [Test]
978                 public void Selected ()
979                 {
980                         DataGridViewCell c = new BaseCell ();
981                         Assert.AreEqual (false, c.Selected, "A1");
982
983                         DataGridView dgv = new DataGridView ();
984                         dgv.Columns.Add ("hi", "there");
985
986                         DataGridViewRow row = new DataGridViewRow ();
987                         row.Cells.Add (c);
988                         dgv.Rows.Add (row);
989
990                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
991
992                         dgv.Columns[0].Selected = true;
993                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
994
995                         dgv.Rows[0].Selected = true;
996                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
997
998                         dgv.Rows[0].Cells[0].Selected = false;
999                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
1000
1001                         dgv.Rows[0].Selected = false;
1002                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
1003
1004                         dgv.Rows[0].Cells[0].Selected = true;
1005                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
1006                 }
1007
1008                 /* The height of a cell (row) is based on Font
1009                 [Test]
1010                 public void Size ()
1011                 {
1012                         DataGridViewCell c = new BaseCell ();
1013                         Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
1014
1015                         DataGridView dgv = new DataGridView ();
1016                         dgv.Columns.Add ("hi", "there");
1017
1018                         DataGridViewRow row = new DataGridViewRow ();
1019                         row.Cells.Add (c);
1020                         dgv.Rows.Add (row);
1021
1022                         Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
1023                         
1024                         // Does not resize to content
1025                         dgv.Rows[0].Cells[0].Value = "bob";
1026                         Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
1027                 }
1028                 */
1029
1030                 [Test]
1031                 public void Style ()
1032                 {
1033                         DataGridViewCell c = new BaseCell ();
1034                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
1035                         Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
1036                         Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
1037                         Assert.AreEqual (null, c.Style.Font, "A4");
1038                         Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
1039                         Assert.AreEqual (string.Empty, c.Style.Format, "A6");
1040                         Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
1041                         Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
1042                         Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
1043                         Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
1044                         Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
1045                         Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
1046                         Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
1047                         Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
1048                         Assert.AreEqual (null, c.Style.Tag, "A15");
1049                         Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
1050
1051                         DataGridView dgv = new DataGridView ();
1052                         dgv.Columns.Add ("hi", "there");
1053
1054                         DataGridViewRow row = new DataGridViewRow ();
1055                         row.Cells.Add (c);
1056                         dgv.Rows.Add (row);
1057
1058                         // Style does not change based on parent
1059                         // (InheritedStyle does)
1060                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
1061                         Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
1062                         Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
1063                         Assert.AreEqual (null, c.Style.Font, "A20");
1064                         Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
1065                         Assert.AreEqual (string.Empty, c.Style.Format, "A22");
1066                         Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
1067                         Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
1068                         Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
1069                         Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
1070                         Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
1071                         Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
1072                         Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
1073                         Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
1074                         Assert.AreEqual (null, c.Style.Tag, "A31");
1075                         Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
1076                 }
1077
1078                 [Test]
1079                 public void Tag ()
1080                 {
1081                         DataGridViewCell c = new BaseCell ();
1082                         Assert.AreEqual (null, c.Tag, "A1");
1083
1084                         DataGridView dgv = new DataGridView ();
1085                         dgv.Columns.Add ("hi", "there");
1086
1087                         DataGridViewRow row = new DataGridViewRow ();
1088                         row.Cells.Add (c);
1089                         dgv.Rows.Add (row);
1090
1091                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
1092
1093                         dgv.Rows[0].Cells[0].Tag = "bob";
1094                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
1095                 }
1096
1097                 [Test]
1098                 public void ToolTipText ()
1099                 {
1100                         DataGridViewCell c = new BaseCell ();
1101                         Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
1102
1103                         DataGridView dgv = new DataGridView ();
1104                         dgv.Columns.Add ("hi", "there");
1105
1106                         DataGridViewRow row = new DataGridViewRow ();
1107                         row.Cells.Add (c);
1108                         dgv.Rows.Add (row);
1109
1110                         Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
1111
1112                         dgv.Rows[0].Cells[0].ToolTipText = "bob";
1113                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
1114                 }
1115
1116                 [Test]
1117                 public void Value ()
1118                 {
1119                         DataGridViewCell c = new BaseCell ();
1120                         Assert.AreEqual (null, c.Value, "A1");
1121
1122                         DataGridView dgv = new DataGridView ();
1123                         dgv.Columns.Add ("hi", "there");
1124
1125                         DataGridViewRow row = new DataGridViewRow ();
1126                         row.Cells.Add (c);
1127                         dgv.Rows.Add (row);
1128
1129                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
1130
1131                         dgv.Rows[0].Cells[0].Value = "bob";
1132                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
1133                 }
1134
1135                 [Test]
1136                 public void ValueType ()
1137                 {
1138                         DataGridViewCell c = new BaseCell ();
1139                         Assert.AreEqual (null, c.ValueType, "A1");
1140
1141                         DataGridView dgv = new DataGridView ();
1142                         dgv.Columns.Add ("hi", "there");
1143
1144                         DataGridViewRow row = new DataGridViewRow ();
1145                         row.Cells.Add (c);
1146                         dgv.Rows.Add (row);
1147
1148                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].ValueType, "A2");
1149
1150                         dgv.Rows[0].Cells[0].ValueType = typeof (bool);
1151                         Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
1152                 }
1153
1154                 [Test]
1155                 public void Visible ()
1156                 {
1157                         DataGridViewCell c = new BaseCell ();
1158                         Assert.AreEqual (false, c.Visible, "A1");
1159
1160                         DataGridView dgv = new DataGridView ();
1161                         dgv.Columns.Add ("hi", "there");
1162
1163                         DataGridViewRow row = new DataGridViewRow ();
1164                         row.Cells.Add (c);
1165                         dgv.Rows.Add (row);
1166
1167                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
1168
1169                         dgv.Columns[0].Visible = false;
1170                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
1171
1172                         dgv.Columns[0].Visible = true;
1173                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
1174
1175                         dgv.Rows[0].Visible = false;
1176                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
1177
1178                         dgv.Rows[0].Visible = true;
1179                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
1180                 }
1181
1182                 /* These can be used on windows to ensure the implementation
1183                  * is correct, but are font-dependent
1184                 [Test]
1185                 public void MeasureTextHeight ()
1186                 {
1187                         Bitmap b = new Bitmap (1, 1);
1188                         Graphics g = Graphics.FromImage (b);
1189
1190                         bool trunc = false;
1191                         int s = DataGridViewCell.MeasureTextHeight (g, "Text", Control.DefaultFont, 100, TextFormatFlags.Default, out trunc);
1192
1193                         //Assert.AreEqual (false, trunc, "A1");
1194                         Assert.AreEqual (13, s, "A2");
1195
1196                         trunc = false;
1197                         s = DataGridViewCell.MeasureTextHeight (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.Default, out trunc);
1198
1199                         //Assert.AreEqual (true, trunc, "A3");
1200                         Assert.AreEqual (13, s, "A4");
1201
1202                         trunc = false;
1203                         s = DataGridViewCell.MeasureTextHeight (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.HorizontalCenter, out trunc);
1204
1205                         //Assert.AreEqual (true, trunc, "A5");
1206                         Assert.AreEqual (13, s, "A6");
1207
1208                         g.Dispose ();
1209                         b.Dispose ();
1210                 }
1211
1212                 [Test]
1213                 public void MeasureTextWidth ()
1214                 {
1215                         Bitmap b = new Bitmap (1, 1);
1216                         Graphics g = Graphics.FromImage (b);
1217
1218                         int s = DataGridViewCell.MeasureTextWidth (g, "Text", Control.DefaultFont, 100, TextFormatFlags.Default);
1219
1220                         Assert.AreEqual (28, s, "A1");
1221
1222                         s = DataGridViewCell.MeasureTextWidth (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.Default);
1223
1224                         Assert.AreEqual (134, s, "A2");
1225
1226                         s = DataGridViewCell.MeasureTextWidth (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.HorizontalCenter);
1227
1228                         Assert.AreEqual (134, s, "A3");
1229
1230                         g.Dispose ();
1231                         b.Dispose ();
1232                 }
1233
1234                 [Test]
1235                 public void MeasureTextSize ()
1236                 {
1237                         Bitmap b = new Bitmap (1, 1);
1238                         Graphics g = Graphics.FromImage (b);
1239
1240                         Size s = DataGridViewCell.MeasureTextSize (g, "Text", Control.DefaultFont, TextFormatFlags.Default);
1241
1242                         Assert.AreEqual (new Size (28, 13), s, "A1");
1243
1244                         s = DataGridViewCell.MeasureTextSize (g, "Text Longer than the width", Control.DefaultFont, TextFormatFlags.Default);
1245
1246                         Assert.AreEqual (new Size (134, 13), s, "A2");
1247
1248                         s = DataGridViewCell.MeasureTextSize (g, "Text Longer than the width", Control.DefaultFont, TextFormatFlags.HorizontalCenter);
1249
1250                         Assert.AreEqual (new Size (134, 13), s, "A3");
1251                         
1252                         s = DataGridViewCell.MeasureTextSize (g, "Text Longer \nthan the width", Control.DefaultFont, TextFormatFlags.HorizontalCenter);
1253
1254                         Assert.AreEqual (new Size (74, 26), s, "A4");
1255
1256                         g.Dispose ();
1257                         b.Dispose ();
1258                 }
1259
1260                 [Test]
1261                 public void MeasureTextPreferredSize ()
1262                 {
1263                         Bitmap b = new Bitmap (1, 1);
1264                         Graphics g = Graphics.FromImage (b);
1265
1266                         Size s = DataGridViewCell.MeasureTextPreferredSize (g, "Text", Control.DefaultFont, 1.5f, TextFormatFlags.Default);
1267
1268                         Assert.AreEqual (new Size (28, 13), s, "A1");
1269
1270                         s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer than the width", Control.DefaultFont, 1.5f, TextFormatFlags.Default);
1271
1272                         Assert.AreEqual (new Size (134, 13), s, "A2");
1273
1274                         s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer than the width", Control.DefaultFont, 2.0f, TextFormatFlags.Default);
1275
1276                         Assert.AreEqual (new Size (134, 13), s, "A3");
1277
1278                         s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer \nthan the width", Control.DefaultFont, 0.5f, TextFormatFlags.Default);
1279
1280                         Assert.AreEqual (new Size (74, 26), s, "A4");
1281
1282                         g.Dispose ();
1283                         b.Dispose ();
1284                 }
1285         */
1286
1287                 [Test]
1288                 public void MethodBorderWidths ()
1289                 {
1290                         BaseCell c = new BaseCell ();
1291                         
1292                         DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
1293                         style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
1294                         style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
1295                         style.Top = DataGridViewAdvancedCellBorderStyle.None;
1296                         //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
1297                         
1298                         Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
1299
1300                         style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
1301                         style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
1302                         style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
1303                         style.Top = DataGridViewAdvancedCellBorderStyle.Single;
1304
1305                         Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
1306
1307                         DataGridView dgv = new DataGridView ();
1308                         dgv.Columns.Add ("hi", "there");
1309
1310                         DataGridViewRow row = new DataGridViewRow ();
1311                         row.Cells.Add (c);
1312                         dgv.Rows.Add (row);
1313
1314                         dgv.Rows[0].DividerHeight = 3;
1315                         dgv.Columns[0].DividerWidth = 5;
1316
1317                         Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
1318                 }
1319
1320                 [Test]
1321                 public void MethodGetContentBounds ()
1322                 {
1323                         DataGridViewCell c = new BaseCell ();
1324                         Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
1325
1326                         DataGridView dgv = new DataGridView ();
1327                         dgv.Columns.Add ("hi", "there");
1328
1329                         DataGridViewRow row = new DataGridViewRow ();
1330                         row.Cells.Add (c);
1331                         dgv.Rows.Add (row);
1332
1333                         Assert.AreEqual (Rectangle.Empty, dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
1334                 }
1335
1336                 [Test]
1337                 public void MethodGetContentBoundsOverload ()
1338                 {
1339                         Bitmap b = new Bitmap (1, 1);
1340                         Graphics g = Graphics.FromImage (b);
1341
1342                         BaseCell c = new BaseCell ();
1343                         Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
1344
1345                         DataGridView dgv = new DataGridView ();
1346                         dgv.Columns.Add ("hi", "there");
1347
1348                         DataGridViewRow row = new DataGridViewRow ();
1349                         row.Cells.Add (c);
1350                         dgv.Rows.Add (row);
1351
1352                         Assert.AreEqual (Rectangle.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
1353                         g.Dispose ();
1354                         b.Dispose ();
1355                 }
1356
1357                 [Test]
1358                 public void MethodGetErrorIconBounds ()
1359                 {
1360                         Bitmap b = new Bitmap (1, 1);
1361                         Graphics g = Graphics.FromImage (b);
1362
1363                         BaseCell c = new BaseCell ();
1364                         Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
1365
1366                         DataGridView dgv = new DataGridView ();
1367                         dgv.Columns.Add ("hi", "there");
1368
1369                         DataGridViewRow row = new DataGridViewRow ();
1370                         row.Cells.Add (c);
1371                         dgv.Rows.Add (row);
1372
1373                         Assert.AreEqual (Rectangle.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorIconBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
1374                         g.Dispose ();
1375                         b.Dispose ();
1376                 }
1377
1378                 [Test]
1379                 public void MethodGetErrorText ()
1380                 {
1381                         Bitmap b = new Bitmap (1, 1);
1382                         Graphics g = Graphics.FromImage (b);
1383
1384                         BaseCell c = new BaseCell ();
1385                         Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
1386
1387                         DataGridView dgv = new DataGridView ();
1388                         dgv.Columns.Add ("hi", "there");
1389
1390                         DataGridViewRow row = new DataGridViewRow ();
1391                         row.Cells.Add (c);
1392                         dgv.Rows.Add (row);
1393
1394                         Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
1395                         g.Dispose ();
1396                         b.Dispose ();
1397                 }
1398
1399                 [Test]
1400                 public void MethodKeyEntersEditMode ()
1401                 {
1402                         bool result = false;
1403                         DataGridViewCell c = new BaseCell ();
1404                         
1405                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
1406                                 result |= c.KeyEntersEditMode (new KeyEventArgs (k));
1407                         
1408                         Assert.AreEqual (false, result, "A1");
1409
1410                         DataGridView dgv = new DataGridView ();
1411                         dgv.Columns.Add ("hi", "there");
1412
1413                         DataGridViewRow row = new DataGridViewRow ();
1414                         row.Cells.Add (c);
1415                         dgv.Rows.Add (row);
1416
1417                         result = false;
1418
1419                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
1420                                 result |= dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k));
1421
1422                         Assert.AreEqual (false, result, "A2");
1423                 }
1424                 
1425                 [Test]
1426                 public void MethodParseFormattedValue ()
1427                 {
1428                         DataGridViewCell c = new FormattedBaseCell ();
1429                         c.ValueType = typeof (bool);
1430                         
1431                         BooleanConverter bc = new BooleanConverter ();
1432                         StringConverter sc = new StringConverter ();
1433                         
1434                         object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
1435                         Assert.AreEqual (true, (bool)o, "A1");
1436                 }
1437
1438                 [Test]
1439                 public void MethodGetInheritedContextMenuStrip ()
1440                 {
1441                         DataGridViewCell c = new BaseCell ();
1442                         Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
1443
1444                         DataGridView dgv = new DataGridView ();
1445                         dgv.Columns.Add ("hi", "there");
1446
1447                         DataGridViewRow row = new DataGridViewRow ();
1448                         row.Cells.Add (c);
1449                         dgv.Rows.Add (row);
1450
1451                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
1452
1453                         ContextMenuStrip cms1 = new ContextMenuStrip ();
1454                         cms1.Items.Add ("Moose");
1455                         dgv.ContextMenuStrip = cms1;
1456
1457                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
1458
1459                         ContextMenuStrip cms2 = new ContextMenuStrip ();
1460                         cms2.Items.Add ("Moose");
1461                         dgv.Columns[0].ContextMenuStrip = cms2;
1462
1463                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
1464
1465                         dgv.Rows[0].ContextMenuStrip = cms1;
1466                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
1467
1468                         dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
1469                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
1470                 }
1471
1472
1473                 [Test]
1474                 public void TestOnDataGridChangedMethod ()
1475                 {
1476                         DataGridView dataGridView1 = new DataGridView ();
1477                         DataGridView dataGridView2 = new DataGridView ();
1478
1479                         TestHeaderCell testCell = new TestHeaderCell ();
1480                         Assert.AreEqual (0, testCell.OnDataGridViewChangedInvokeCount, "#1");
1481
1482                         testCell.OnDataGridViewChangedInvokeCount = 0;
1483                         dataGridView1.TopLeftHeaderCell = testCell;
1484                         Assert.AreEqual (1, testCell.OnDataGridViewChangedInvokeCount, "#2");
1485
1486                         testCell.OnDataGridViewChangedInvokeCount = 0;
1487                         dataGridView1.TopLeftHeaderCell = null;
1488                         Assert.AreEqual (1, testCell.OnDataGridViewChangedInvokeCount, "#3");
1489
1490                         testCell.OnDataGridViewChangedInvokeCount = 0;
1491                         dataGridView2.TopLeftHeaderCell = testCell;
1492                         Assert.AreEqual (1, testCell.OnDataGridViewChangedInvokeCount, "#4");
1493
1494                         testCell.OnDataGridViewChangedInvokeCount = 0;
1495                         dataGridView1.TopLeftHeaderCell = testCell;
1496                         Assert.AreEqual (1, testCell.OnDataGridViewChangedInvokeCount, "#5");
1497
1498                         testCell.OnDataGridViewChangedInvokeCount = 0;
1499                         dataGridView1.TopLeftHeaderCell = testCell;
1500                         Assert.AreEqual (0, testCell.OnDataGridViewChangedInvokeCount, "#6");
1501                         
1502                 }
1503
1504                 private class TestHeaderCell : DataGridViewHeaderCell
1505                 {
1506                         public int OnDataGridViewChangedInvokeCount = 0;
1507
1508                         protected override void OnDataGridViewChanged ()
1509                         {
1510                                 OnDataGridViewChangedInvokeCount++;
1511                                 base.OnDataGridViewChanged ();
1512                         }
1513                 }
1514
1515                 private class FormattedBaseCell : DataGridViewCell
1516                 {
1517                         public override Type FormattedValueType { get { return typeof (string); } }
1518                 }
1519                 
1520                 private class BaseCell : DataGridViewCell
1521                 {
1522                         public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
1523                         { return GetContentBounds (graphics, cellStyle, rowIndex); }
1524                         public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
1525                         { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
1526                         public string PublicGetErrorText (int rowIndex)
1527                         { return GetErrorText (rowIndex); }
1528                         public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
1529                         { return BorderWidths (advancedBorderStyle); }
1530                 }
1531                 
1532                 class DataGridViewCellMockObject : DataGridViewCell
1533                 {
1534                         public DataGridViewCellMockObject ()
1535                         {
1536                         }
1537                 }
1538
1539                 public class DataGridViewClipboardCell : DataGridViewCell
1540                 {
1541                         public DataGridViewClipboardCell ()
1542                         {
1543                         }
1544
1545                         public object GetClipboardContentPublic (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format)
1546                         {
1547                                 return GetClipboardContent (rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format);
1548                         }
1549
1550                         public override Type FormattedValueType
1551                         {
1552                                 get
1553                                 {
1554                                         return typeof (string);
1555                                 }
1556                         }
1557                 }
1558         }
1559 }
1560
1561 #endif