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