ListViewItemTest.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Jordi Mas i Hernandez <[email protected]>
  24. //
  25. //
  26. using System;
  27. using System.Windows.Forms;
  28. using System.Drawing;
  29. using System.Reflection;
  30. using NUnit.Framework;
  31. namespace MonoTests.System.Windows.Forms
  32. {
  33. [TestFixture]
  34. public class ListViewItemTest
  35. {
  36. [Test]
  37. public void ListViewItemConstructors ()
  38. {
  39. Font fnt = new Font ("Arial", 12);
  40. ListViewItem item1 = new ListViewItem ("Hello folks");
  41. Assert.AreEqual ("Hello folks", item1.Text, "Constructor#1");
  42. ListViewItem item2 = new ListViewItem (new string [] {"Element1", "Element2"},
  43. -1, Color.Blue, Color.Red, fnt);
  44. Assert.AreEqual (item2.ForeColor, Color.Blue, "Constructor#2");
  45. Assert.AreEqual (item2.BackColor, Color.Red, "Constructor#3");
  46. Assert.AreEqual (2, item2.SubItems.Count,"Constructor#4");
  47. Assert.AreEqual (Color.Blue, item2.SubItems[0].ForeColor,"Constructor#5");
  48. Assert.AreEqual (Color.Red, item2.SubItems[0].BackColor, "Constructor#6");
  49. Assert.AreEqual (fnt, item2.SubItems[0].Font, "Constructor#7");
  50. Assert.AreEqual ("Element1", item2.SubItems[0].Text, "Constructor#8");
  51. Assert.AreEqual ("Element2", item2.SubItems[1].Text, "Constructor#12");
  52. }
  53. [Test]
  54. public void ListViewItemDefaultValues ()
  55. {
  56. ListViewItem item = new ListViewItem ();
  57. Assert.AreEqual (false, item.Focused, "DefaultValues#3");
  58. Assert.AreEqual (false, item.Checked, "DefaultValues#4");
  59. Assert.AreEqual (string.Empty, item.Text, "DefaultValues#5");
  60. Assert.AreEqual (true, item.UseItemStyleForSubItems, "DefaultValues#6");
  61. }
  62. [Test]
  63. public void ListViewItemTestClone ()
  64. {
  65. ListViewItem item1 = new ListViewItem ("Hello");
  66. item1.ForeColor = Color.Blue;
  67. item1.BackColor = Color.Red;
  68. item1.Font = new Font ("Arial", 14);
  69. item1.SubItems.Add ("Element2");
  70. ListViewItem item2 = (ListViewItem) item1.Clone ();
  71. Assert.AreEqual (item2.ForeColor, Color.Blue, "Clone#1");
  72. Assert.AreEqual (item2.BackColor, Color.Red, "Clone#2");
  73. Assert.AreEqual (item2.Text, "Hello", "Clone#3");
  74. Assert.AreEqual (item2.Font, item1.Font, "Clone#4");
  75. Assert.AreEqual (2, item2.SubItems.Count, "Clone#5");
  76. Assert.AreEqual (item2.SubItems[1].Text, "Element2", "Clone#6");
  77. }
  78. }
  79. }