importing messaging-2008 branch to trunk.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewImageCellTest.cs
1 //
2 // DataGridViewImageCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewImageCellTest
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 DataGridViewImageCellTest : TestHelper
44         {
45                 [Test]
46                 public void Value ()
47                 {
48                         DataGridViewImageCell tbc = new DataGridViewImageCell ();
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, 2, 14, 16), 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 ("System.Drawing.Bitmap", c.DefaultNewRowValue.GetType ().ToString (), "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 ("System.Drawing.Bitmap", dgv.Rows[0].Cells[0].DefaultNewRowValue.GetType ().ToString (), "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 (Image), 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, 20), dgv.Rows[0].Cells[0].PreferredSize, "A2");
334
335                         dgv.Rows[0].Cells[0].Value = new Bitmap (20, 20);
336                         Assert.AreEqual (new Size (21, 21), dgv.Rows[0].Cells[0].PreferredSize, "A3");
337
338                         dgv.Rows[0].Cells[0].Value = new Bitmap (32, 32);
339                         Assert.AreEqual (new Size (33, 33), dgv.Rows[0].Cells[0].PreferredSize, "A4");
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 (Image), 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 (Image), 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, 2, 14, 16), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
673
674                         dgv.Rows[0].Cells[0].Value = new Bitmap (20, 20);
675                         Assert.AreEqual (new Rectangle (0, 0, 20, 20), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
676
677                         dgv.Rows[0].Cells[0].Value = new Bitmap (32, 32);
678                         Assert.AreEqual (new Rectangle (0, -5, 32, 32), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
679                 }
680                 
681                 [Test]
682                 public void MethodGetContentBoundsOverload ()
683                 {
684                         Bitmap b = new Bitmap (1, 1);
685                         Graphics g = Graphics.FromImage (b);
686
687                         BaseCell c = new BaseCell ();
688                         Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
689
690                         DataGridView dgv = new DataGridView ();
691                         dgv.Columns.Add ("hi", "there");
692
693                         DataGridViewRow row = new DataGridViewRow ();
694                         row.Cells.Add (c);
695                         dgv.Rows.Add (row);
696
697                         Assert.AreEqual (new Rectangle (0, 2, 14, 16), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
698                         g.Dispose ();
699                         b.Dispose ();
700                 }
701                 */
702
703                 [Test]
704                 public void MethodGetErrorIconBounds ()
705                 {
706                         Bitmap b = new Bitmap (1, 1);
707                         Graphics g = Graphics.FromImage (b);
708
709                         BaseCell c = new BaseCell ();
710                         Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
711
712                         DataGridView dgv = new DataGridView ();
713                         dgv.Columns.Add ("hi", "there");
714
715                         DataGridViewRow row = new DataGridViewRow ();
716                         row.Cells.Add (c);
717                         dgv.Rows.Add (row);
718
719                         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");
720                         g.Dispose ();
721                         b.Dispose ();
722                 }
723
724                 [Test]
725                 public void MethodGetErrorText ()
726                 {
727                         Bitmap b = new Bitmap (1, 1);
728                         Graphics g = Graphics.FromImage (b);
729
730                         BaseCell c = new BaseCell ();
731                         Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
732
733                         DataGridView dgv = new DataGridView ();
734                         dgv.Columns.Add ("hi", "there");
735
736                         DataGridViewRow row = new DataGridViewRow ();
737                         row.Cells.Add (c);
738                         dgv.Rows.Add (row);
739
740                         Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
741                         g.Dispose ();
742                         b.Dispose ();
743                 }
744
745                 [Test]
746                 public void MethodKeyEntersEditMode ()
747                 {
748                         string result = string.Empty;
749                         string expected = string.Empty;
750                         
751                         DataGridViewCell c = new BaseCell ();
752
753                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
754                                 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
755                                         result += ((int)k).ToString () + ";";
756
757                         Assert.AreEqual (expected, result, "A1");
758
759                         DataGridView dgv = new DataGridView ();
760                         dgv.Columns.Add ("hi", "there");
761
762                         DataGridViewRow row = new DataGridViewRow ();
763                         row.Cells.Add (c);
764                         dgv.Rows.Add (row);
765
766                         result = string.Empty;
767
768                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
769                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
770                                         result += ((int)k).ToString () + ";";
771
772                         Assert.AreEqual (expected, result, "A2");
773
774                         result = string.Empty;
775                         dgv.EditMode = DataGridViewEditMode.EditOnEnter;
776
777                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
778                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
779                                         result += ((int)k).ToString () + ";";
780
781                         Assert.AreEqual (expected, result, "A3");
782
783                         result = string.Empty;
784                         dgv.EditMode = DataGridViewEditMode.EditOnF2;
785
786                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
787                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
788                                         result += ((int)k).ToString () + ";";
789
790                         Assert.AreEqual (expected, result, "A4");
791
792                         result = string.Empty;
793                         dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
794
795                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
796                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
797                                         result += ((int)k).ToString () + ";";
798
799                         Assert.AreEqual (expected, result, "A5");
800
801                         result = string.Empty;
802                         dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
803
804                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
805                                 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
806                                         result += ((int)k).ToString () + ";";
807
808                         Assert.AreEqual (expected, result, "A6");
809                 }
810
811                 [Test]
812                 public void MethodParseFormattedValue ()
813                 {
814                         DataGridViewCell c = new FormattedBaseCell ();
815                         c.ValueType = typeof (bool);
816
817                         BooleanConverter bc = new BooleanConverter ();
818                         StringConverter sc = new StringConverter ();
819
820                         object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
821                         Assert.AreEqual (true, (bool)o, "A1");
822                 }
823
824                 [Test]
825                 public void MethodGetInheritedContextMenuStrip ()
826                 {
827                         DataGridViewCell c = new BaseCell ();
828                         Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
829
830                         DataGridView dgv = new DataGridView ();
831                         dgv.Columns.Add ("hi", "there");
832
833                         DataGridViewRow row = new DataGridViewRow ();
834                         row.Cells.Add (c);
835                         dgv.Rows.Add (row);
836
837                         Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
838
839                         ContextMenuStrip cms1 = new ContextMenuStrip ();
840                         cms1.Items.Add ("Moose");
841                         dgv.ContextMenuStrip = cms1;
842
843                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
844
845                         ContextMenuStrip cms2 = new ContextMenuStrip ();
846                         cms2.Items.Add ("Moose");
847                         dgv.Columns[0].ContextMenuStrip = cms2;
848
849                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
850
851                         dgv.Rows[0].ContextMenuStrip = cms1;
852                         Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
853
854                         dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
855                         Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
856                 }
857
858                 private class FormattedBaseCell : DataGridViewImageCell
859                 {
860                         public override Type FormattedValueType { get { return typeof (string); } }
861                 }
862
863                 private class BaseCell : DataGridViewImageCell
864                 {
865                         public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
866                         { return GetContentBounds (graphics, cellStyle, rowIndex); }
867                         public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
868                         { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
869                         public string PublicGetErrorText (int rowIndex)
870                         { return GetErrorText (rowIndex); }
871                         public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
872                         { return BorderWidths (advancedBorderStyle); }
873                 }
874
875         }
876 }
877 #endif