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