ColumnHeaderTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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) 2007 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Carlos Alberto Cortez <[email protected]>
  24. //
  25. using System;
  26. using System.Drawing;
  27. using System.Windows.Forms;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Windows.Forms
  30. {
  31. [TestFixture]
  32. public class ColumnHeaderTest
  33. {
  34. [Test]
  35. public void DefaultValuesTest ()
  36. {
  37. ColumnHeader col = new ColumnHeader ();
  38. Assert.IsNull (col.ListView, "1");
  39. Assert.AreEqual (-1, col.Index, "2");
  40. Assert.AreEqual ("ColumnHeader", col.Text, "3");
  41. Assert.AreEqual (HorizontalAlignment.Left, col.TextAlign, "4");
  42. #if NET_2_0
  43. Assert.AreEqual (-1, col.DisplayIndex, "5");
  44. Assert.AreEqual (-1, col.ImageIndex, "6");
  45. Assert.AreEqual (String.Empty, col.ImageKey, "7");
  46. Assert.IsNull (col.ImageList, "8");
  47. Assert.AreEqual (String.Empty, col.Name, "9");
  48. Assert.IsNull (col.Tag, "10");
  49. #endif
  50. }
  51. #if NET_2_0
  52. [Test]
  53. public void DisplayIndexTest ()
  54. {
  55. ColumnHeader col = new ColumnHeader ();
  56. col.DisplayIndex = -66;
  57. col.DisplayIndex = 66;
  58. ListView lv = new ListView ();
  59. lv.Columns.Add (col);
  60. try {
  61. col.DisplayIndex = -1;
  62. Assert.Fail ("1");
  63. } catch (ArgumentOutOfRangeException) {
  64. }
  65. try {
  66. col.DisplayIndex = lv.Columns.Count;
  67. Assert.Fail ("2");
  68. } catch (ArgumentOutOfRangeException) {
  69. }
  70. Assert.AreEqual (0, col.DisplayIndex, "3");
  71. }
  72. #endif
  73. [Test]
  74. public void WidthTest ()
  75. {
  76. ColumnHeader col = new ColumnHeader ();
  77. col.Text = "Column text";
  78. ListView lv = new ListView ();
  79. lv.Items.Add ("Item text");
  80. lv.View = View.Details;
  81. lv.Columns.Add (col);
  82. lv.CreateControl ();
  83. col.Width = -1;
  84. Assert.IsTrue (col.Width > 0, "1");
  85. col.Width = -2;
  86. Assert.IsTrue (col.Width > 0, "2");
  87. }
  88. }
  89. }