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