2 // DataGridViewLinkCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewLinkCellTest
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2007 Gert Driesen
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Windows.Forms;
35 using NUnit.Framework;
37 using System.Threading;
38 using System.ComponentModel;
40 namespace MonoTests.System.Windows.Forms
43 public class DataGridViewLinkCellTest : TestHelper
46 public void Defaults ()
48 DataGridViewLinkCell cell = new DataGridViewLinkCell ();
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");
58 Assert.AreEqual ("DataGridViewLinkCell { ColumnIndex=-1, RowIndex=-1 }", cell.ToString (), "A8");
64 DataGridViewTextBoxCell tbc = new DataGridViewTextBoxCell ();
65 Assert.IsNull (tbc.Value, "#1");
66 tbc.Value = string.Empty;
67 Assert.AreEqual (string.Empty, tbc.Value, "#2");
69 Assert.AreEqual (5, tbc.Value, "#3");
71 Assert.IsNull (tbc.Value, "#4");
75 public void ColumnIndex ()
77 DataGridViewCell c = new BaseCell ();
78 Assert.AreEqual (-1, c.ColumnIndex, "A1");
80 DataGridView dgv = new DataGridView ();
81 dgv.Columns.Add ("hi", "there");
83 DataGridViewRow row = new DataGridViewRow ();
87 Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
90 /* font measurement dependent
92 public void ContentBounds ()
94 DataGridViewCell c = new BaseCell ();
95 Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
97 DataGridView dgv = new DataGridView ();
98 dgv.Columns.Add ("hi", "there");
100 DataGridViewRow row = new DataGridViewRow ();
104 Assert.AreEqual (new Rectangle (1, 10, 0, 0), dgv.Rows[0].Cells[0].ContentBounds, "A2");
109 public void ContextMenuStrip ()
111 DataGridViewCell c = new BaseCell ();
112 Assert.AreEqual (null, c.ContextMenuStrip, "A1");
114 DataGridView dgv = new DataGridView ();
115 dgv.Columns.Add ("hi", "there");
117 DataGridViewRow row = new DataGridViewRow ();
121 ContextMenuStrip cms1 = new ContextMenuStrip ();
122 cms1.Items.Add ("hey");
124 ContextMenuStrip cms2 = new ContextMenuStrip ();
125 cms2.Items.Add ("yo");
127 dgv.Rows[0].ContextMenuStrip = cms1;
128 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
130 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
131 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
135 public void DataGridView ()
137 DataGridViewCell c = new BaseCell ();
138 Assert.AreEqual (null, c.DataGridView, "A1");
140 DataGridView dgv = new DataGridView ();
141 dgv.Columns.Add ("hi", "there");
143 DataGridViewRow row = new DataGridViewRow ();
147 Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
151 public void DefaultNewRowValue ()
153 DataGridViewCell c = new BaseCell ();
154 Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
156 DataGridView dgv = new DataGridView ();
157 dgv.Columns.Add ("hi", "there");
159 DataGridViewRow row = new DataGridViewRow ();
163 Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
167 public void Displayed ()
169 DataGridViewCell c = new BaseCell ();
170 Assert.AreEqual (false, c.Displayed, "A1");
172 DataGridView dgv = new DataGridView ();
173 dgv.Columns.Add ("hi", "there");
175 DataGridViewRow row = new DataGridViewRow ();
179 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
183 public void EditedFormattedValue ()
185 DataGridViewCell c = new BaseCell ();
186 Assert.AreEqual (null, c.EditedFormattedValue, "A1");
190 public void FormattedValueType ()
192 DataGridViewCell c = new BaseCell ();
193 Assert.AreEqual (typeof (string), c.FormattedValueType, "A1");
197 public void Frozen ()
199 DataGridViewCell c = new BaseCell ();
200 Assert.AreEqual (false, c.Frozen, "A1");
202 DataGridView dgv = new DataGridView ();
203 dgv.Columns.Add ("hi", "there");
205 DataGridViewRow row = new DataGridViewRow ();
209 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
211 dgv.Columns[0].Frozen = true;
212 dgv.Rows[0].Frozen = true;
213 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
217 public void HasStyle ()
219 DataGridViewCell c = new BaseCell ();
220 Assert.AreEqual (false, c.HasStyle, "A1");
222 DataGridView dgv = new DataGridView ();
223 dgv.Columns.Add ("hi", "there");
225 DataGridViewRow row = new DataGridViewRow ();
229 Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
231 dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
232 Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
236 public void InheritedState ()
238 DataGridViewCell c = new BaseCell ();
239 Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
241 DataGridView dgv = new DataGridView ();
242 dgv.Columns.Add ("hi", "there");
244 DataGridViewRow row = new DataGridViewRow ();
248 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
250 dgv.Rows[0].Selected = true;
251 Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
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");
259 public void InheritedStyle ()
261 DataGridViewCell c = new BaseCell ();
262 DataGridView dgv = new DataGridView ();
263 dgv.Columns.Add ("hi", "there");
265 DataGridViewRow row = new DataGridViewRow ();
269 Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
271 dgv.DefaultCellStyle.BackColor = Color.Firebrick;
272 Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
274 dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
275 Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
277 dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
278 Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
280 dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
281 Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
283 dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
284 Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
288 public void IsInEditMode ()
290 DataGridViewCell c = new BaseCell ();
291 Assert.AreEqual (false, c.IsInEditMode, "A1");
293 DataGridView dgv = new DataGridView ();
294 dgv.Columns.Add ("hi", "there");
296 DataGridViewRow row = new DataGridViewRow ();
300 Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
304 public void OwningColumn ()
306 DataGridViewCell c = new BaseCell ();
307 Assert.AreEqual (null, c.OwningColumn, "A1");
309 DataGridView dgv = new DataGridView ();
310 dgv.Columns.Add ("hi", "there");
312 DataGridViewRow row = new DataGridViewRow ();
316 Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
320 public void OwningRow ()
322 DataGridViewCell c = new BaseCell ();
323 Assert.AreEqual (null, c.OwningRow, "A1");
325 DataGridView dgv = new DataGridView ();
326 dgv.Columns.Add ("hi", "there");
328 DataGridViewRow row = new DataGridViewRow ();
332 Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
335 /* Font measurement dependent
337 public void PreferredSize ()
339 DataGridViewCell c = new BaseCell ();
340 Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
342 DataGridView dgv = new DataGridView ();
343 dgv.Columns.Add ("hi", "there");
345 DataGridViewRow row = new DataGridViewRow ();
349 Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A2");
351 dgv.Rows[0].Cells[0].Value = "bob";
352 Assert.AreEqual (new Size (29, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
354 dgv.Rows[0].Cells[0].Value = "roasted quail";
355 Assert.AreEqual (new Size (71, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
359 public void ReadOnly ()
361 DataGridViewCell c = new BaseCell ();
362 Assert.AreEqual (false, c.ReadOnly, "A1");
364 DataGridView dgv = new DataGridView ();
365 dgv.Columns.Add ("hi", "there");
367 DataGridViewRow row = new DataGridViewRow ();
371 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
373 dgv.Rows[0].ReadOnly = true;
374 Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
376 dgv.Rows[0].Cells[0].ReadOnly = false;
377 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
381 public void Resizable ()
383 DataGridViewCell c = new BaseCell ();
384 Assert.AreEqual (false, c.Resizable, "A1");
386 DataGridView dgv = new DataGridView ();
387 dgv.Columns.Add ("hi", "there");
389 DataGridViewRow row = new DataGridViewRow ();
393 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
395 dgv.Rows[0].Resizable = DataGridViewTriState.False;
396 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
398 dgv.Columns[0].Resizable = DataGridViewTriState.False;
399 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
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");
405 dgv.AllowUserToResizeColumns = false;
406 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
408 dgv.AllowUserToResizeRows = false;
409 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
411 dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
412 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
414 dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
415 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
419 public void RowIndex ()
421 DataGridViewCell c = new BaseCell ();
422 Assert.AreEqual (-1, c.RowIndex, "A1");
424 DataGridView dgv = new DataGridView ();
425 dgv.Columns.Add ("hi", "there");
427 DataGridViewRow row = new DataGridViewRow ();
431 Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
435 public void Selected ()
437 DataGridViewCell c = new BaseCell ();
438 Assert.AreEqual (false, c.Selected, "A1");
440 DataGridView dgv = new DataGridView ();
441 dgv.Columns.Add ("hi", "there");
443 DataGridViewRow row = new DataGridViewRow ();
447 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
449 dgv.Columns[0].Selected = true;
450 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
452 dgv.Rows[0].Selected = true;
453 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
455 dgv.Rows[0].Cells[0].Selected = false;
456 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
458 dgv.Rows[0].Selected = false;
459 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
461 dgv.Rows[0].Cells[0].Selected = true;
462 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
465 /* The height of a cell (row) is based on Font
469 DataGridViewCell c = new BaseCell ();
470 Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
472 DataGridView dgv = new DataGridView ();
473 dgv.Columns.Add ("hi", "there");
475 DataGridViewRow row = new DataGridViewRow ();
479 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
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");
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");
508 DataGridView dgv = new DataGridView ();
509 dgv.Columns.Add ("hi", "there");
511 DataGridViewRow row = new DataGridViewRow ();
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");
538 DataGridViewCell c = new BaseCell ();
539 Assert.AreEqual (null, c.Tag, "A1");
541 DataGridView dgv = new DataGridView ();
542 dgv.Columns.Add ("hi", "there");
544 DataGridViewRow row = new DataGridViewRow ();
548 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
550 dgv.Rows[0].Cells[0].Tag = "bob";
551 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
555 public void ToolTipText ()
557 DataGridViewCell c = new BaseCell ();
558 Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
560 DataGridView dgv = new DataGridView ();
561 dgv.Columns.Add ("hi", "there");
563 DataGridViewRow row = new DataGridViewRow ();
567 Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
569 dgv.Rows[0].Cells[0].ToolTipText = "bob";
570 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
574 public void Value2 ()
576 DataGridViewCell c = new BaseCell ();
577 Assert.AreEqual (null, c.Value, "A1");
579 DataGridView dgv = new DataGridView ();
580 dgv.Columns.Add ("hi", "there");
582 DataGridViewRow row = new DataGridViewRow ();
586 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
588 dgv.Rows[0].Cells[0].Value = "bob";
589 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
593 public void ValueType ()
595 DataGridViewCell c = new BaseCell ();
596 Assert.AreEqual (typeof (object), c.ValueType, "A1");
598 DataGridView dgv = new DataGridView ();
599 dgv.Columns.Add ("hi", "there");
601 DataGridViewRow row = new DataGridViewRow ();
605 Assert.AreEqual (typeof (object), dgv.Rows[0].Cells[0].ValueType, "A2");
607 dgv.Rows[0].Cells[0].ValueType = typeof (bool);
608 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
612 public void Visible ()
614 DataGridViewCell c = new BaseCell ();
615 Assert.AreEqual (false, c.Visible, "A1");
617 DataGridView dgv = new DataGridView ();
618 dgv.Columns.Add ("hi", "there");
620 DataGridViewRow row = new DataGridViewRow ();
624 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
626 dgv.Columns[0].Visible = false;
627 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
629 dgv.Columns[0].Visible = true;
630 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
632 dgv.Rows[0].Visible = false;
633 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
635 dgv.Rows[0].Visible = true;
636 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
640 public void MethodBorderWidths ()
642 BaseCell c = new BaseCell ();
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;
650 Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
652 style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
653 style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
654 style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
655 style.Top = DataGridViewAdvancedCellBorderStyle.Single;
657 Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
659 DataGridView dgv = new DataGridView ();
660 dgv.Columns.Add ("hi", "there");
662 DataGridViewRow row = new DataGridViewRow ();
666 dgv.Rows[0].DividerHeight = 3;
667 dgv.Columns[0].DividerWidth = 5;
669 Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
672 /* Font measurement dependent
674 public void MethodGetContentBounds ()
676 DataGridViewCell c = new BaseCell ();
677 Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
678 c.Value = "hello there";
680 DataGridView dgv = new DataGridView ();
681 dgv.Columns.Add ("hi", "there");
683 DataGridViewRow row = new DataGridViewRow ();
687 Assert.AreEqual (new Rectangle (1, 2, 56, 16), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
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");
694 public void MethodGetContentBoundsOverload ()
696 Bitmap b = new Bitmap (1, 1);
697 Graphics g = Graphics.FromImage (b);
699 BaseCell c = new BaseCell ();
700 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
702 DataGridView dgv = new DataGridView ();
703 dgv.Columns.Add ("hi", "there");
705 DataGridViewRow row = new DataGridViewRow ();
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");
716 public void MethodGetErrorIconBounds ()
718 Bitmap b = new Bitmap (1, 1);
719 Graphics g = Graphics.FromImage (b);
721 BaseCell c = new BaseCell ();
722 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
724 DataGridView dgv = new DataGridView ();
725 dgv.Columns.Add ("hi", "there");
727 DataGridViewRow row = new DataGridViewRow ();
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");
737 public void MethodGetErrorText ()
739 Bitmap b = new Bitmap (1, 1);
740 Graphics g = Graphics.FromImage (b);
742 BaseCell c = new BaseCell ();
743 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
745 DataGridView dgv = new DataGridView ();
746 dgv.Columns.Add ("hi", "there");
748 DataGridViewRow row = new DataGridViewRow ();
752 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
758 public void MethodKeyEntersEditMode ()
760 string result = string.Empty;
761 string expected = string.Empty;
763 DataGridViewCell c = new BaseCell ();
765 foreach (Keys k in Enum.GetValues (typeof (Keys)))
766 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
767 result += ((int)k).ToString () + ";";
769 Assert.AreEqual (expected, result, "A1");
771 DataGridView dgv = new DataGridView ();
772 dgv.Columns.Add ("hi", "there");
774 DataGridViewRow row = new DataGridViewRow ();
778 result = string.Empty;
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 () + ";";
784 Assert.AreEqual (expected, result, "A2");
786 result = string.Empty;
787 dgv.EditMode = DataGridViewEditMode.EditOnEnter;
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 () + ";";
793 Assert.AreEqual (expected, result, "A3");
795 result = string.Empty;
796 dgv.EditMode = DataGridViewEditMode.EditOnF2;
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 () + ";";
802 Assert.AreEqual (expected, result, "A4");
804 result = string.Empty;
805 dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
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 () + ";";
811 Assert.AreEqual (expected, result, "A5");
813 result = string.Empty;
814 dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
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 () + ";";
820 Assert.AreEqual (expected, result, "A6");
824 public void MethodParseFormattedValue ()
826 DataGridViewCell c = new FormattedBaseCell ();
827 c.ValueType = typeof (bool);
829 BooleanConverter bc = new BooleanConverter ();
830 StringConverter sc = new StringConverter ();
832 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
833 Assert.AreEqual (true, (bool)o, "A1");
837 public void MethodGetInheritedContextMenuStrip ()
839 DataGridViewCell c = new BaseCell ();
840 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
842 DataGridView dgv = new DataGridView ();
843 dgv.Columns.Add ("hi", "there");
845 DataGridViewRow row = new DataGridViewRow ();
849 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
851 ContextMenuStrip cms1 = new ContextMenuStrip ();
852 cms1.Items.Add ("Moose");
853 dgv.ContextMenuStrip = cms1;
855 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
857 ContextMenuStrip cms2 = new ContextMenuStrip ();
858 cms2.Items.Add ("Moose");
859 dgv.Columns[0].ContextMenuStrip = cms2;
861 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
863 dgv.Rows[0].ContextMenuStrip = cms1;
864 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
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");
870 private class FormattedBaseCell : DataGridViewLinkCell
872 public override Type FormattedValueType { get { return typeof (string); } }
875 private class BaseCell : DataGridViewLinkCell
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); }