New test for ListView.Dispose firing extra Layout events.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewCheckBoxCellTest.cs
1 //
2 // DataGridViewCheckBoxCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewCheckBoxCellTest
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
7 //
8 // Copyright (C) 2007 Gert Driesen
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31
32 using System;
33 using System.Windows.Forms;
34
35 using NUnit.Framework;
36 using System.Drawing;
37 using System.Threading;
38 using System.ComponentModel;
39
40 namespace MonoTests.System.Windows.Forms
41 {
42         [TestFixture]
43         public class DataGridViewCheckBoxCellTest : TestHelper
44         {
45                 [Test]
46                 public void Defaults ()
47                 {
48                         DataGridViewCheckBoxCell cell = new DataGridViewCheckBoxCell ();
49
50                         Assert.AreEqual (null, cell.EditedFormattedValue, "A1");
51                         Assert.AreEqual (false, cell.EditingCellValueChanged, "A2");
52                         Assert.AreEqual (null, cell.EditType, "A3");
53                         Assert.AreEqual (null, cell.FalseValue, "A4");
54                         Assert.AreEqual (typeof (bool), cell.FormattedValueType, "A5");
55                         Assert.AreEqual (null, cell.IndeterminateValue, "A6");
56                         Assert.AreEqual (false, cell.ThreeState, "A7");
57                         Assert.AreEqual (null, cell.TrueValue, "A8");
58                         Assert.AreEqual (typeof (bool), cell.ValueType, "A9");
59
60                         Assert.AreEqual ("DataGridViewCheckBoxCell { ColumnIndex=-1, RowIndex=-1 }", cell.ToString (), "A10");
61                         
62                         cell.ThreeState = true;
63
64                         Assert.AreEqual (null, cell.EditedFormattedValue, "A11");
65                         Assert.AreEqual (false, cell.EditingCellValueChanged, "A12");
66                         Assert.AreEqual (null, cell.EditType, "A13");
67                         Assert.AreEqual (null, cell.FalseValue, "A14");
68                         Assert.AreEqual (typeof (CheckState), cell.FormattedValueType, "A15");
69                         Assert.AreEqual (null, cell.IndeterminateValue, "A16");
70                         Assert.AreEqual (true, cell.ThreeState, "A17");
71                         Assert.AreEqual (null, cell.TrueValue, "A18");
72                         Assert.AreEqual (typeof (CheckState), cell.ValueType, "A19");
73                 }
74
75                 [Test]
76                 public void Value ()
77                 {
78                         DataGridViewCheckBoxCell tbc = new DataGridViewCheckBoxCell ();
79                         Assert.IsNull (tbc.Value, "#1");
80                         tbc.Value = string.Empty;
81                         Assert.AreEqual (string.Empty, tbc.Value, "#2");
82                         tbc.Value = 5;
83                         Assert.AreEqual (5, tbc.Value, "#3");
84                         tbc.Value = null;
85                         Assert.IsNull (tbc.Value, "#4");
86                 }
87
88                 [Test]
89                 public void ColumnIndex ()
90                 {
91                         DataGridViewCell c = new BaseCell ();
92                         Assert.AreEqual (-1, c.ColumnIndex, "A1");
93
94                         DataGridView dgv = new DataGridView ();
95                         dgv.Columns.Add ("hi", "there");
96
97                         DataGridViewRow row = new DataGridViewRow ();
98                         row.Cells.Add (c);
99                         dgv.Rows.Add (row);
100
101                         Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
102                 }
103
104                 /* font measurement dependent
105                 [Test]
106                 public void ContentBounds ()
107                 {
108                         DataGridViewCell c = new BaseCell ();
109                         Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
110
111                         DataGridView dgv = new DataGridView ();
112                         dgv.Columns.Add ("hi", "there");
113
114                         DataGridViewRow row = new DataGridViewRow ();
115                         row.Cells.Add (c);
116                         dgv.Rows.Add (row);
117
118                         Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].ContentBounds, "A2");
119                 }
120                 */
121
122                 [Test]
123                 public void ContextMenuStrip ()
124                 {
125                         DataGridViewCell c = new BaseCell ();
126                         Assert.AreEqual (null, c.ContextMenuStrip, "A1");
127
128                         DataGridView dgv = new DataGridView ();
129                         dgv.Columns.Add ("hi", "there");
130
131                         DataGridViewRow row = new DataGridViewRow ();
132                         row.Cells.Add (c);
133                         dgv.Rows.Add (row);
134
135                         ContextMenuStrip cms1 = new ContextMenuStrip ();
136                         cms1.Items.Add ("hey");
137
138                         ContextMenuStrip cms2 = new ContextMenuStrip ();
139                         cms2.Items.Add ("yo");
140
141                         dgv.Rows[0].ContextMenuStrip = cms1;
142                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
143
144                         dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
145                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
146                 }
147
148                 [Test]
149                 public void DataGridView ()
150                 {
151                         DataGridViewCell c = new BaseCell ();
152                         Assert.AreEqual (null, c.DataGridView, "A1");
153
154                         DataGridView dgv = new DataGridView ();
155                         dgv.Columns.Add ("hi", "there");
156
157                         DataGridViewRow row = new DataGridViewRow ();
158                         row.Cells.Add (c);
159                         dgv.Rows.Add (row);
160
161                         Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
162                 }
163
164                 [Test]
165                 public void DefaultNewRowValue ()
166                 {
167                         DataGridViewCell c = new BaseCell ();
168                         Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
169
170                         DataGridView dgv = new DataGridView ();
171                         dgv.Columns.Add ("hi", "there");
172
173                         DataGridViewRow row = new DataGridViewRow ();
174                         row.Cells.Add (c);
175                         dgv.Rows.Add (row);
176
177                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
178                 }
179
180                 [Test]
181                 public void Displayed ()
182                 {
183                         DataGridViewCell c = new BaseCell ();
184                         Assert.AreEqual (false, c.Displayed, "A1");
185
186                         DataGridView dgv = new DataGridView ();
187                         dgv.Columns.Add ("hi", "there");
188
189                         DataGridViewRow row = new DataGridViewRow ();
190                         row.Cells.Add (c);
191                         dgv.Rows.Add (row);
192
193                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
194                 }
195
196                 [Test]
197                 public void EditedFormattedValue ()
198                 {
199                         DataGridViewCell c = new BaseCell ();
200                         Assert.AreEqual (null, c.EditedFormattedValue, "A1");
201                 }
202
203                 [Test]
204                 public void FormattedValueType ()
205                 {
206                         BaseCell c = new BaseCell ();
207                         Assert.AreEqual (typeof (bool), c.FormattedValueType, "A1");
208                         
209                         c.ThreeState = true;
210                         Assert.AreEqual (typeof (CheckState), c.FormattedValueType, "A2");
211                 }
212
213                 [Test]
214                 public void Frozen ()
215                 {
216                         DataGridViewCell c = new BaseCell ();
217                         Assert.AreEqual (false, c.Frozen, "A1");
218
219                         DataGridView dgv = new DataGridView ();
220                         dgv.Columns.Add ("hi", "there");
221
222                         DataGridViewRow row = new DataGridViewRow ();
223                         row.Cells.Add (c);
224                         dgv.Rows.Add (row);
225
226                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
227
228                         dgv.Columns[0].Frozen = true;
229                         dgv.Rows[0].Frozen = true;
230                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
231                 }
232
233                 [Test]
234                 public void HasStyle ()
235                 {
236                         DataGridViewCell c = new BaseCell ();
237                         Assert.AreEqual (false, c.HasStyle, "A1");
238
239                         DataGridView dgv = new DataGridView ();
240                         dgv.Columns.Add ("hi", "there");
241
242                         DataGridViewRow row = new DataGridViewRow ();
243                         row.Cells.Add (c);
244                         dgv.Rows.Add (row);
245
246                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
247
248                         dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
249                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
250                 }
251
252                 [Test]
253                 public void InheritedState ()
254                 {
255                         DataGridViewCell c = new BaseCell ();
256                         Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
257
258                         DataGridView dgv = new DataGridView ();
259                         dgv.Columns.Add ("hi", "there");
260
261                         DataGridViewRow row = new DataGridViewRow ();
262                         row.Cells.Add (c);
263                         dgv.Rows.Add (row);
264
265                         Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
266
267                         dgv.Rows[0].Selected = true;
268                         Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
269
270                         dgv.Rows[0].Selected = false;
271                         dgv.Columns[0].Selected = true;
272                         Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
273                 }
274
275                 [Test]
276                 public void InheritedStyle ()
277                 {
278                         DataGridViewCell c = new BaseCell ();
279                         DataGridView dgv = new DataGridView ();
280                         dgv.Columns.Add ("hi", "there");
281
282                         DataGridViewRow row = new DataGridViewRow ();
283                         row.Cells.Add (c);
284                         dgv.Rows.Add (row);
285
286                         Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
287
288                         dgv.DefaultCellStyle.BackColor = Color.Firebrick;
289                         Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
290
291                         dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
292                         Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
293
294                         dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
295                         Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
296
297                         dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
298                         Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
299
300                         dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
301                         Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
302                 }
303
304                 [Test]
305                 public void IsInEditMode ()
306                 {
307                         DataGridViewCell c = new BaseCell ();
308                         Assert.AreEqual (false, c.IsInEditMode, "A1");
309
310                         DataGridView dgv = new DataGridView ();
311                         dgv.Columns.Add ("hi", "there");
312
313                         DataGridViewRow row = new DataGridViewRow ();
314                         row.Cells.Add (c);
315                         dgv.Rows.Add (row);
316
317                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
318                 }
319
320                 [Test]
321                 public void OwningColumn ()
322                 {
323                         DataGridViewCell c = new BaseCell ();
324                         Assert.AreEqual (null, c.OwningColumn, "A1");
325
326                         DataGridView dgv = new DataGridView ();
327                         dgv.Columns.Add ("hi", "there");
328
329                         DataGridViewRow row = new DataGridViewRow ();
330                         row.Cells.Add (c);
331                         dgv.Rows.Add (row);
332
333                         Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
334                 }
335
336                 [Test]
337                 public void OwningRow ()
338                 {
339                         DataGridViewCell c = new BaseCell ();
340                         Assert.AreEqual (null, c.OwningRow, "A1");
341
342                         DataGridView dgv = new DataGridView ();
343                         dgv.Columns.Add ("hi", "there");
344
345                         DataGridViewRow row = new DataGridViewRow ();
346                         row.Cells.Add (c);
347                         dgv.Rows.Add (row);
348
349                         Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
350                 }
351
352                 /* Font measurement dependent *
353                 [Test]
354                 public void PreferredSize ()
355                 {
356                         BaseCell c = new BaseCell ();
357                         Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
358
359                         DataGridView dgv = new DataGridView ();
360                         dgv.Columns.Add ("hi", "there");
361
362                         DataGridViewRow row = new DataGridViewRow ();
363                         row.Cells.Add (c);
364                         dgv.Rows.Add (row);
365
366                         Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A2");
367
368                         dgv.Rows[0].Cells[0].Value = "bob";
369                         Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
370
371                         dgv.Rows[0].Cells[0].Value = "roasted quail";
372                         Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
373                 }
374                  */
375
376                 [Test]
377                 public void ReadOnly ()
378                 {
379                         DataGridViewCell c = new BaseCell ();
380                         Assert.AreEqual (false, c.ReadOnly, "A1");
381
382                         DataGridView dgv = new DataGridView ();
383                         dgv.Columns.Add ("hi", "there");
384
385                         DataGridViewRow row = new DataGridViewRow ();
386                         row.Cells.Add (c);
387                         dgv.Rows.Add (row);
388
389                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
390
391                         dgv.Rows[0].ReadOnly = true;
392                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
393
394                         dgv.Rows[0].Cells[0].ReadOnly = false;
395                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
396                 }
397
398                 [Test]
399                 public void Resizable ()
400                 {
401                         DataGridViewCell c = new BaseCell ();
402                         Assert.AreEqual (false, c.Resizable, "A1");
403
404                         DataGridView dgv = new DataGridView ();
405                         dgv.Columns.Add ("hi", "there");
406
407                         DataGridViewRow row = new DataGridViewRow ();
408                         row.Cells.Add (c);
409                         dgv.Rows.Add (row);
410
411                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
412
413                         dgv.Rows[0].Resizable = DataGridViewTriState.False;
414                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
415
416                         dgv.Columns[0].Resizable = DataGridViewTriState.False;
417                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
418
419                         dgv.Columns[0].Resizable = DataGridViewTriState.True;
420                         dgv.Rows[0].Resizable = DataGridViewTriState.True;
421                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
422
423                         dgv.AllowUserToResizeColumns = false;
424                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
425
426                         dgv.AllowUserToResizeRows = false;
427                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
428
429                         dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
430                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
431
432                         dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
433                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
434                 }
435
436                 [Test]
437                 public void RowIndex ()
438                 {
439                         DataGridViewCell c = new BaseCell ();
440                         Assert.AreEqual (-1, c.RowIndex, "A1");
441
442                         DataGridView dgv = new DataGridView ();
443                         dgv.Columns.Add ("hi", "there");
444
445                         DataGridViewRow row = new DataGridViewRow ();
446                         row.Cells.Add (c);
447                         dgv.Rows.Add (row);
448
449                         Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
450                 }
451
452                 [Test]
453                 public void Selected ()
454                 {
455                         DataGridViewCell c = new BaseCell ();
456                         Assert.AreEqual (false, c.Selected, "A1");
457
458                         DataGridView dgv = new DataGridView ();
459                         dgv.Columns.Add ("hi", "there");
460
461                         DataGridViewRow row = new DataGridViewRow ();
462                         row.Cells.Add (c);
463                         dgv.Rows.Add (row);
464
465                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
466
467                         dgv.Columns[0].Selected = true;
468                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
469
470                         dgv.Rows[0].Selected = true;
471                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
472
473                         dgv.Rows[0].Cells[0].Selected = false;
474                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
475
476                         dgv.Rows[0].Selected = false;
477                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
478
479                         dgv.Rows[0].Cells[0].Selected = true;
480                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
481                 }
482
483                 /* The height of a cell (row) is based on Font
484                 [Test]
485                 public void Size ()
486                 {
487                         DataGridViewCell c = new BaseCell ();
488                         Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
489
490                         DataGridView dgv = new DataGridView ();
491                         dgv.Columns.Add ("hi", "there");
492
493                         DataGridViewRow row = new DataGridViewRow ();
494                         row.Cells.Add (c);
495                         dgv.Rows.Add (row);
496
497                         Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
498                         
499                         // Does not resize to content
500                         dgv.Rows[0].Cells[0].Value = "bob";
501                         Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
502                 }
503                 */
504
505                 [Test]
506                 public void Style ()
507                 {
508                         DataGridViewCell c = new BaseCell ();
509                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
510                         Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
511                         Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
512                         Assert.AreEqual (null, c.Style.Font, "A4");
513                         Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
514                         Assert.AreEqual (string.Empty, c.Style.Format, "A6");
515                         Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
516                         Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
517                         Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
518                         Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
519                         Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
520                         Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
521                         Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
522                         Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
523                         Assert.AreEqual (null, c.Style.Tag, "A15");
524                         Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
525
526                         DataGridView dgv = new DataGridView ();
527                         dgv.Columns.Add ("hi", "there");
528
529                         DataGridViewRow row = new DataGridViewRow ();
530                         row.Cells.Add (c);
531                         dgv.Rows.Add (row);
532
533                         // Style does not change based on parent
534                         // (InheritedStyle does)
535                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
536                         Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
537                         Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
538                         Assert.AreEqual (null, c.Style.Font, "A20");
539                         Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
540                         Assert.AreEqual (string.Empty, c.Style.Format, "A22");
541                         Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
542                         Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
543                         Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
544                         Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
545                         Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
546                         Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
547                         Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
548                         Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
549                         Assert.AreEqual (null, c.Style.Tag, "A31");
550                         Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
551                 }
552
553                 [Test]
554                 public void Tag ()
555                 {
556                         DataGridViewCell c = new BaseCell ();
557                         Assert.AreEqual (null, c.Tag, "A1");
558
559                         DataGridView dgv = new DataGridView ();
560                         dgv.Columns.Add ("hi", "there");
561
562                         DataGridViewRow row = new DataGridViewRow ();
563                         row.Cells.Add (c);
564                         dgv.Rows.Add (row);
565
566                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
567
568                         dgv.Rows[0].Cells[0].Tag = "bob";
569                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
570                 }
571
572                 [Test]
573                 public void ToolTipText ()
574                 {
575                         DataGridViewCell c = new BaseCell ();
576                         Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
577
578                         DataGridView dgv = new DataGridView ();
579                         dgv.Columns.Add ("hi", "there");
580
581                         DataGridViewRow row = new DataGridViewRow ();
582                         row.Cells.Add (c);
583                         dgv.Rows.Add (row);
584
585                         Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
586
587                         dgv.Rows[0].Cells[0].ToolTipText = "bob";
588                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
589                 }
590
591                 [Test]
592                 public void Value2 ()
593                 {
594                         DataGridViewCell c = new BaseCell ();
595                         Assert.AreEqual (null, c.Value, "A1");
596
597                         DataGridView dgv = new DataGridView ();
598                         dgv.Columns.Add ("hi", "there");
599
600                         DataGridViewRow row = new DataGridViewRow ();
601                         row.Cells.Add (c);
602                         dgv.Rows.Add (row);
603
604                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
605
606                         dgv.Rows[0].Cells[0].Value = "bob";
607                         Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
608                 }
609
610                 [Test]
611                 public void ValueType ()
612                 {
613                         DataGridViewCell c = new BaseCell ();
614                         Assert.AreEqual (typeof (bool), c.ValueType, "A1");
615
616                         DataGridView dgv = new DataGridView ();
617                         dgv.Columns.Add ("hi", "there");
618
619                         DataGridViewRow row = new DataGridViewRow ();
620                         row.Cells.Add (c);
621                         dgv.Rows.Add (row);
622
623                         Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A2");
624
625                         dgv.Rows[0].Cells[0].ValueType = typeof (bool);
626                         Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
627                 }
628
629                 [Test]
630                 public void Visible ()
631                 {
632                         DataGridViewCell c = new BaseCell ();
633                         Assert.AreEqual (false, c.Visible, "A1");
634
635                         DataGridView dgv = new DataGridView ();
636                         dgv.Columns.Add ("hi", "there");
637
638                         DataGridViewRow row = new DataGridViewRow ();
639                         row.Cells.Add (c);
640                         dgv.Rows.Add (row);
641
642                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
643
644                         dgv.Columns[0].Visible = false;
645                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
646
647                         dgv.Columns[0].Visible = true;
648                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
649
650                         dgv.Rows[0].Visible = false;
651                         Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
652
653                         dgv.Rows[0].Visible = true;
654                         Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
655                 }
656
657                 [Test]
658                 public void MethodBorderWidths ()
659                 {
660                         BaseCell c = new BaseCell ();
661
662                         DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
663                         style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
664                         style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
665                         style.Top = DataGridViewAdvancedCellBorderStyle.None;
666                         //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
667
668                         Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
669
670                         style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
671                         style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
672                         style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
673                         style.Top = DataGridViewAdvancedCellBorderStyle.Single;
674
675                         Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
676
677                         DataGridView dgv = new DataGridView ();
678                         dgv.Columns.Add ("hi", "there");
679
680                         DataGridViewRow row = new DataGridViewRow ();
681                         row.Cells.Add (c);
682                         dgv.Rows.Add (row);
683
684                         dgv.Rows[0].DividerHeight = 3;
685                         dgv.Columns[0].DividerWidth = 5;
686
687                         Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
688                 }
689
690                 /* Font measurement dependent
691                 [Test]
692                 public void MethodGetContentBounds ()
693                 {
694                         DataGridViewCell c = new BaseCell ();
695                         Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
696                         c.Value = "hello there";
697                         
698                         DataGridView dgv = new DataGridView ();
699                         dgv.Columns.Add ("hi", "there");
700
701                         DataGridViewRow row = new DataGridViewRow ();
702                         row.Cells.Add (c);
703                         dgv.Rows.Add (row);
704
705                         Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
706
707                         dgv.Rows[0].Cells[0].Value = "whoa whoa whoa whoa whoa whoa";
708                         Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
709                 }
710                 
711                 [Test]
712                 public void MethodGetContentBoundsOverload ()
713                 {
714                         Bitmap b = new Bitmap (1, 1);
715                         Graphics g = Graphics.FromImage (b);
716
717                         BaseCell c = new BaseCell ();
718                         Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
719
720                         DataGridView dgv = new DataGridView ();
721                         dgv.Columns.Add ("hi", "there");
722
723                         DataGridViewRow row = new DataGridViewRow ();
724                         row.Cells.Add (c);
725                         dgv.Rows.Add (row);
726
727                         Assert.AreEqual (new Rectangle (2, 4, 13, 13), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
728                         g.Dispose ();
729                         b.Dispose ();
730                 }
731                 */
732                 
733                 [Test]
734                 public void MethodGetErrorIconBounds ()
735                 {
736                         Bitmap b = new Bitmap (1, 1);
737                         Graphics g = Graphics.FromImage (b);
738
739                         BaseCell c = new BaseCell ();
740                         Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
741
742                         DataGridView dgv = new DataGridView ();
743                         dgv.Columns.Add ("hi", "there");
744
745                         DataGridViewRow row = new DataGridViewRow ();
746                         row.Cells.Add (c);
747                         dgv.Rows.Add (row);
748
749                         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");
750                         g.Dispose ();
751                         b.Dispose ();
752                 }
753
754                 [Test]
755                 public void MethodGetErrorText ()
756                 {
757                         Bitmap b = new Bitmap (1, 1);
758                         Graphics g = Graphics.FromImage (b);
759
760                         BaseCell c = new BaseCell ();
761                         Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
762
763                         DataGridView dgv = new DataGridView ();
764                         dgv.Columns.Add ("hi", "there");
765
766                         DataGridViewRow row = new DataGridViewRow ();
767                         row.Cells.Add (c);
768                         dgv.Rows.Add (row);
769
770                         Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
771                         g.Dispose ();
772                         b.Dispose ();
773                 }
774
775                 [Test]
776                 public void MethodKeyEntersEditMode ()
777                 {
778                         string result = string.Empty;
779                         string expected = string.Empty;
780                         
781                         DataGridViewCell c = new BaseCell ();
782
783                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
784                                 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
785                                         result += ((int)k).ToString () + ";";
786
787                         Assert.AreEqual (expected, result, "A1");
788
789                         DataGridView dgv = new DataGridView ();
790                         dgv.Columns.Add ("hi", "there");
791
792                         DataGridViewRow row = new DataGridViewRow ();
793                         row.Cells.Add (c);
794                         dgv.Rows.Add (row);
795
796                         result = string.Empty;
797
798                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
799                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
800                                         result += ((int)k).ToString () + ";";
801
802                         Assert.AreEqual (expected, result, "A2");
803
804                         result = string.Empty;
805                         dgv.EditMode = DataGridViewEditMode.EditOnEnter;
806
807                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
808                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
809                                         result += ((int)k).ToString () + ";";
810
811                         Assert.AreEqual (expected, result, "A3");
812
813                         result = string.Empty;
814                         dgv.EditMode = DataGridViewEditMode.EditOnF2;
815
816                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
817                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
818                                         result += ((int)k).ToString () + ";";
819
820                         Assert.AreEqual (expected, result, "A4");
821
822                         result = string.Empty;
823                         dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
824
825                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
826                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
827                                         result += ((int)k).ToString () + ";";
828
829                         Assert.AreEqual (expected, result, "A5");
830
831                         result = string.Empty;
832                         dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
833
834                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
835                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
836                                         result += ((int)k).ToString () + ";";
837
838                         Assert.AreEqual (expected, result, "A6");
839                 }
840
841                 [Test]
842                 public void MethodParseFormattedValue ()
843                 {
844                         DataGridViewCell c = new FormattedBaseCell ();
845                         c.ValueType = typeof (bool);
846
847                         BooleanConverter bc = new BooleanConverter ();
848                         StringConverter sc = new StringConverter ();
849
850                         object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
851                         Assert.AreEqual (true, (bool)o, "A1");
852                 }
853
854                 [Test]
855                 public void MethodGetInheritedContextMenuStrip ()
856                 {
857                         DataGridViewCell c = new BaseCell ();
858                         Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
859
860                         DataGridView dgv = new DataGridView ();
861                         dgv.Columns.Add ("hi", "there");
862
863                         DataGridViewRow row = new DataGridViewRow ();
864                         row.Cells.Add (c);
865                         dgv.Rows.Add (row);
866
867                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
868
869                         ContextMenuStrip cms1 = new ContextMenuStrip ();
870                         cms1.Items.Add ("Moose");
871                         dgv.ContextMenuStrip = cms1;
872
873                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
874
875                         ContextMenuStrip cms2 = new ContextMenuStrip ();
876                         cms2.Items.Add ("Moose");
877                         dgv.Columns[0].ContextMenuStrip = cms2;
878
879                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
880
881                         dgv.Rows[0].ContextMenuStrip = cms1;
882                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
883
884                         dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
885                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
886                 }
887
888                 private class FormattedBaseCell : DataGridViewCheckBoxCell
889                 {
890                         public override Type FormattedValueType { get { return typeof (string); } }
891                 }
892
893                 private class BaseCell : DataGridViewCheckBoxCell
894                 {
895                         public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
896                         { return GetContentBounds (graphics, cellStyle, rowIndex); }
897                         public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
898                         { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
899                         public string PublicGetErrorText (int rowIndex)
900                         { return GetErrorText (rowIndex); }
901                         public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
902                         { return BorderWidths (advancedBorderStyle); }
903                 }
904
905         }
906 }
907 #endif