ListViewEventTest.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. myform.Dispose ();
  41. }
  42. [Test]
  43. public void BeforeLabelEditTest ()
  44. {
  45. Form myform = new Form ();
  46. ListView mylistview = new ListView ();
  47. mylistview.LabelEdit = true ;
  48. mylistview.BeforeLabelEdit += new LabelEditEventHandler (LabelEdit_EventHandler);
  49. eventhandled = false;
  50. mylistview.View = View.Details;
  51. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  52. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  53. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  54. ListViewItem item1 = new ListViewItem ("A", -1);
  55. mylistview.Items.Add (item1);
  56. myform.Controls.Add (mylistview);
  57. myform.ShowDialog ();
  58. Assert.AreEqual (true, eventhandled, "#A2");
  59. myform.Dispose ();
  60. }
  61. }
  62. [TestFixture, Ignore ("Needs Manual Intervention")]
  63. public class ColumnClickEvent
  64. {
  65. static bool eventhandled = false;
  66. public void ColumnClickEventHandler (object sender, ColumnClickEventArgs e)
  67. {
  68. eventhandled = true;
  69. }
  70. [Test]
  71. public void ColumnClickTest ()
  72. {
  73. Form myform = new Form ();
  74. ListView mylistview = new ListView ();
  75. mylistview.LabelEdit = true ;
  76. mylistview.ColumnClick += new ColumnClickEventHandler (ColumnClickEventHandler);
  77. mylistview.View = View.Details;
  78. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  79. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  80. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  81. ListViewItem item1 = new ListViewItem ("A", -1);
  82. mylistview.Items.Add (item1);
  83. myform.Controls.Add (mylistview);
  84. myform.ShowDialog ();
  85. mylistview.Sort ();
  86. Assert.AreEqual (true, eventhandled, "#A3");
  87. myform.Dispose ();
  88. }
  89. }
  90. [TestFixture, Ignore ("Needs Manual Intervention")]
  91. public class MyEvent
  92. {
  93. static bool eventhandled = false;
  94. public void New_EventHandler (object sender, EventArgs e)
  95. {
  96. eventhandled = true;
  97. }
  98. [Test]
  99. public void ItemActivateTest ()
  100. {
  101. Form myform = new Form ();
  102. ListView mylistview = new ListView ();
  103. mylistview.Activation = ItemActivation.OneClick;
  104. mylistview.LabelEdit = true ;
  105. mylistview.ItemActivate += new EventHandler (New_EventHandler);
  106. mylistview.View = View.Details;
  107. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  108. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  109. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  110. ListViewItem item1 = new ListViewItem ("A", -1);
  111. mylistview.Items.Add (item1);
  112. myform.Controls.Add (mylistview);
  113. myform.ShowDialog ();
  114. Assert.AreEqual (true, eventhandled, "#A4");
  115. myform.Dispose ();
  116. }
  117. [Test]
  118. public void SelectedIndexChangedTest ()
  119. {
  120. Form myform = new Form ();
  121. ListView mylistview = new ListView ();
  122. mylistview.LabelEdit = true ;
  123. mylistview.SelectedIndexChanged += new EventHandler (New_EventHandler);
  124. eventhandled = false;
  125. mylistview.View = View.Details;
  126. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  127. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  128. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  129. ListViewItem item1 = new ListViewItem ("A", -1);
  130. mylistview.Items.Add (item1);
  131. myform.Controls.Add (mylistview);
  132. myform.ShowDialog ();
  133. Assert.AreEqual (true, eventhandled, "#A5");
  134. myform.Dispose ();
  135. }
  136. }
  137. [TestFixture, Ignore ("Needs Manual Intervention")]
  138. public class ItemCheckEvent
  139. {
  140. static bool eventhandled = false;
  141. public void ItemCheckEventHandler (object sender, ItemCheckEventArgs e)
  142. {
  143. eventhandled = true;
  144. }
  145. [Test]
  146. public void ItemCheckTest ()
  147. {
  148. Form myform = new Form ();
  149. ListView mylistview = new ListView ();
  150. mylistview.CheckBoxes = true;
  151. mylistview.LabelEdit = true ;
  152. mylistview.ItemCheck += new ItemCheckEventHandler (ItemCheckEventHandler);
  153. mylistview.View = View.Details;
  154. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  155. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  156. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  157. ListViewItem item1 = new ListViewItem ("A", -1);
  158. mylistview.Items.Add (item1);
  159. myform.Controls.Add (mylistview);
  160. myform.ShowDialog ();
  161. mylistview.Visible = true;
  162. Assert.AreEqual (true, eventhandled, "#A6");
  163. myform.Dispose ();
  164. }
  165. }
  166. [TestFixture, Ignore ("Needs Manual Intervention")]
  167. public class ItemDragEvent
  168. {
  169. static bool eventhandled = false;
  170. public void ItemDragEventHandler (object sender, ItemDragEventArgs e)
  171. {
  172. eventhandled = true;
  173. }
  174. [Test]
  175. public void ItemDragTest ()
  176. {
  177. Form myform = new Form ();
  178. ListView mylistview = new ListView ();
  179. mylistview.ItemDrag += new ItemDragEventHandler (ItemDragEventHandler);
  180. mylistview.View = View.Details;
  181. mylistview.SetBounds (10, 10, 200, 200, BoundsSpecified.All);
  182. mylistview.Columns.Add ("A", -2, HorizontalAlignment.Center);
  183. mylistview.Columns.Add ("B", -2, HorizontalAlignment.Center);
  184. ListViewItem item1 = new ListViewItem ("A", -1);
  185. mylistview.Items.Add (item1);
  186. myform.Controls.Add (mylistview);
  187. myform.ShowDialog ();
  188. mylistview.Visible = true;
  189. mylistview.DoDragDrop (mylistview.SelectedItems, DragDropEffects.Link);
  190. Assert.AreEqual (true, eventhandled, "#A7");
  191. myform.Dispose ();
  192. }
  193. }
  194. }