ListViewEventTest.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // ListViewEventTest.cs: Test cases for ListView events.
  3. //
  4. // Author:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using NUnit.Framework;
  11. using System.Windows.Forms;
  12. using System.Drawing;
  13. using System.Collections;
  14. namespace MonoTests.System.Windows.Forms
  15. {
  16. [TestFixture, Ignore ("Needs Manual Intervention")]
  17. public class ListViewEvent
  18. {
  19. static bool eventhandled = false;
  20. public void LabelEdit_EventHandler (object sender,LabelEditEventArgs e)
  21. {
  22. eventhandled = true;
  23. }
  24. [Test]
  25. public void AfterLabelEditTest ()
  26. {
  27. Form myform = new Form ();
  28. ListView mylistview = new ListView ();
  29. mylistview.LabelEdit = true ;
  30. mylistview.AfterLabelEdit += new LabelEditEventHandler (LabelEdit_EventHandler);
  31. mylistview.View = View.Details;
  32. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  33. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  34. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  35. ListViewItem item1 = new ListViewItem ("A", -1);
  36. mylistview.Items.Add (item1);
  37. myform.Controls.Add (mylistview);
  38. myform.ShowDialog ();
  39. Assert.AreEqual (true, eventhandled, "#A1");
  40. }
  41. [Test]
  42. public void BeforeLabelEditTest ()
  43. {
  44. Form myform = new Form ();
  45. ListView mylistview = new ListView ();
  46. mylistview.LabelEdit = true ;
  47. mylistview.BeforeLabelEdit += new LabelEditEventHandler (LabelEdit_EventHandler);
  48. eventhandled = false;
  49. mylistview.View = View.Details;
  50. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  51. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  52. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  53. ListViewItem item1 = new ListViewItem ("A", -1);
  54. mylistview.Items.Add (item1);
  55. myform.Controls.Add (mylistview);
  56. myform.ShowDialog ();
  57. Assert.AreEqual (true, eventhandled, "#A2");
  58. }
  59. }
  60. [TestFixture, Ignore ("Needs Manual Intervention")]
  61. public class ColumnClickEvent
  62. {
  63. static bool eventhandled = false;
  64. public void ColumnClickEventHandler (object sender, ColumnClickEventArgs e)
  65. {
  66. eventhandled = true;
  67. }
  68. [Test]
  69. public void ColumnClickTest ()
  70. {
  71. Form myform = new Form ();
  72. ListView mylistview = new ListView ();
  73. mylistview.LabelEdit = true ;
  74. mylistview.ColumnClick += new ColumnClickEventHandler (ColumnClickEventHandler);
  75. mylistview.View = View.Details;
  76. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  77. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  78. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  79. ListViewItem item1 = new ListViewItem ("A", -1);
  80. mylistview.Items.Add (item1);
  81. myform.Controls.Add (mylistview);
  82. myform.ShowDialog ();
  83. mylistview.Sort ();
  84. Assert.AreEqual (true, eventhandled, "#A3");
  85. }
  86. }
  87. [TestFixture, Ignore ("Needs Manual Intervention")]
  88. public class MyEvent
  89. {
  90. static bool eventhandled = false;
  91. public void New_EventHandler (object sender, EventArgs e)
  92. {
  93. eventhandled = true;
  94. }
  95. [Test]
  96. public void ItemActivateTest ()
  97. {
  98. Form myform = new Form ();
  99. ListView mylistview = new ListView ();
  100. mylistview.Activation = ItemActivation.OneClick;
  101. mylistview.LabelEdit = true ;
  102. mylistview.ItemActivate += new EventHandler (New_EventHandler);
  103. mylistview.View = View.Details;
  104. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  105. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  106. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  107. ListViewItem item1 = new ListViewItem ("A", -1);
  108. mylistview.Items.Add (item1);
  109. myform.Controls.Add (mylistview);
  110. myform.ShowDialog ();
  111. Assert.AreEqual (true, eventhandled, "#A4");
  112. }
  113. [Test]
  114. public void SelectedIndexChangedTest ()
  115. {
  116. Form myform = new Form ();
  117. ListView mylistview = new ListView ();
  118. mylistview.LabelEdit = true ;
  119. mylistview.SelectedIndexChanged += new EventHandler (New_EventHandler);
  120. eventhandled = false;
  121. mylistview.View = View.Details;
  122. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  123. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  124. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  125. ListViewItem item1 = new ListViewItem ("A", -1);
  126. mylistview.Items.Add (item1);
  127. myform.Controls.Add (mylistview);
  128. myform.ShowDialog ();
  129. Assert.AreEqual (true, eventhandled, "#A5");
  130. }
  131. }
  132. [TestFixture, Ignore ("Needs Manual Intervention")]
  133. public class ItemCheckEvent
  134. {
  135. static bool eventhandled = false;
  136. public void ItemCheckEventHandler (object sender, ItemCheckEventArgs e)
  137. {
  138. eventhandled = true;
  139. }
  140. [Test]
  141. public void ItemCheckTest ()
  142. {
  143. Form myform = new Form ();
  144. ListView mylistview = new ListView ();
  145. mylistview.CheckBoxes = true;
  146. mylistview.LabelEdit = true ;
  147. mylistview.ItemCheck += new ItemCheckEventHandler (ItemCheckEventHandler);
  148. mylistview.View = View.Details;
  149. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  150. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  151. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  152. ListViewItem item1 = new ListViewItem ("A", -1);
  153. mylistview.Items.Add (item1);
  154. myform.Controls.Add (mylistview);
  155. myform.ShowDialog ();
  156. mylistview.Visible = true;
  157. Assert.AreEqual (true, eventhandled, "#A6");
  158. }
  159. }
  160. [TestFixture, Ignore ("Needs Manual Intervention")]
  161. public class ItemDragEvent
  162. {
  163. static bool eventhandled = false;
  164. public void ItemDragEventHandler (object sender, ItemDragEventArgs e)
  165. {
  166. eventhandled = true;
  167. }
  168. [Test]
  169. public void ItemDragTest ()
  170. {
  171. Form myform = new Form ();
  172. ListView mylistview = new ListView ();
  173. mylistview.ItemDrag += new ItemDragEventHandler (ItemDragEventHandler);
  174. mylistview.View = View.Details;
  175. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  176. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  177. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  178. ListViewItem item1 = new ListViewItem ("A", -1);
  179. mylistview.Items.Add (item1);
  180. myform.Controls.Add (mylistview);
  181. myform.ShowDialog ();
  182. mylistview.Visible = true;
  183. mylistview.DoDragDrop (mylistview.SelectedItems, DragDropEffects.Link);
  184. Assert.AreEqual (true, eventhandled, "#A7");
  185. }
  186. }
  187. }