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