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