* Test/System.Windows.Forms/TestHelper.cs: Inconsistent eol fixes and
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ListViewTest.cs
index e6baa1ef92e66eca98d03e8ef1032918acdfb48f..53571cd0f29c9bb08909bbca3cc0f15bd5d8ea7e 100644 (file)
@@ -18,7 +18,7 @@ using NUnit.Framework;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ListViewTest
+       public class ListViewTest : TestHelper
        {
                [Test]
                public void ListViewPropertyTest ()
@@ -57,6 +57,10 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (View.LargeIcon, mylistview.View, "#29");
                        mylistview.View = View.List;
                        Assert.AreEqual (false, mylistview.TopItem.Checked, "#30");
+#if NET_2_0
+                       Assert.AreEqual (false, mylistview.ShowItemToolTips, "#31");
+                       Assert.AreEqual (false, mylistview.HotTracking, "#31");
+#endif
                }
 
                [Test]
@@ -73,6 +77,7 @@ namespace MonoTests.System.Windows.Forms
                        myform.Dispose ();
                }
 
+               // Hey
                [Test]
                public void BeginEndUpdateTest ()
                {
@@ -157,6 +162,14 @@ namespace MonoTests.System.Windows.Forms
                        myform.Dispose ();
                }
 
+               [Test] // bug #80620
+               public void ClientRectangle_Borders ()
+               {
+                       ListView lv = new ListView ();
+                       lv.CreateControl ();
+                       Assert.AreEqual (lv.ClientRectangle, new ListView ().ClientRectangle);
+               }
+
                [Test]
                public void DisposeTest ()
                {
@@ -182,7 +195,8 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsNull(lv.StateImageList, "#B3");
                }
 
-               [Test]
+               // Hey
+               //[Test]
                public void EnsureVisibleTest ()
                {
                        Form myform = new Form ();
@@ -314,6 +328,65 @@ namespace MonoTests.System.Windows.Forms
                        form.Dispose ();
                }
 
+#if NET_2_0
+               [Test]
+               public void TopItem ()
+               {
+                       ListView lvw = CreateListView (View.List);
+
+                       lvw.TopItem = null;
+                       Assert.AreEqual (lvw.Items [0], lvw.TopItem, "#A1");
+
+                       lvw.TopItem = new ListViewItem ();
+                       Assert.AreEqual (lvw.Items [0], lvw.TopItem, "#A2");
+               }
+
+               [Test]
+               public void TopItem_Exceptions ()
+               {
+                       ListView lvw = CreateListView (View.LargeIcon);
+                       ListViewItem item = null;
+
+                       try {
+                               lvw.TopItem = lvw.Items [2];
+                               Assert.Fail ("#A1");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       try {
+                               item = lvw.TopItem;
+                               Assert.Fail ("#A2");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       lvw.View = View.SmallIcon;
+                       try {
+                               lvw.TopItem = lvw.Items [2];
+                               Assert.Fail ("#A3");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       try {
+                               item = lvw.TopItem;
+                               Assert.Fail ("#A4");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       lvw.View = View.Tile;
+                       try {
+                               lvw.TopItem = lvw.Items [2];
+                               Assert.Fail ("#A5");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       try {
+                               item = lvw.TopItem;
+                               Assert.Fail ("#A6");
+                       } catch (InvalidOperationException) {
+                       }
+               }
+#endif
+
                [Test]
                public void Selected ()
                {
@@ -428,6 +501,135 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
 
+               [Test]
+               public void FindNearestItem_Exceptions ()
+               {
+                       ListView lvw = new ListView ();
+                       lvw.Items.Add ("A");
+                       lvw.Items.Add ("B");
+
+                       lvw.View = View.Details;
+                       try {
+                               lvw.FindNearestItem (SearchDirectionHint.Down, 0, 0);
+                               Assert.Fail ("#A1");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       lvw.View = View.List;
+                       try {
+                               lvw.FindNearestItem (SearchDirectionHint.Down, 0, 0);
+                               Assert.Fail ("#A2");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       lvw.View = View.Tile;
+                       try {
+                               lvw.FindNearestItem (SearchDirectionHint.Down, 0, 0);
+                               Assert.Fail ("#A3");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       lvw.View = View.LargeIcon;
+                       try {
+                               lvw.FindNearestItem ((SearchDirectionHint)666, 0, 0);
+                       } catch (ArgumentOutOfRangeException) {
+                       }
+               }
+
+               [Test]
+               public void FocusedItem ()
+               {
+                       ListView lvw = CreateListView (View.LargeIcon);
+                       Form form = new Form ();
+                       lvw.Parent = form;
+
+                       // FocusedItem setter ignores the value until form is shown
+                       lvw.FocusedItem = lvw.Items [2];
+                       Assert.AreEqual (null, lvw.FocusedItem, "#A1");
+
+                       // It's not enough to create the ListView control
+                       form.Show ();
+
+                       lvw.FocusedItem = lvw.Items [2];
+                       Assert.AreEqual (lvw.Items [2], lvw.FocusedItem, "#A2");
+
+                       lvw.FocusedItem = new ListViewItem ();
+                       Assert.AreEqual (lvw.Items [2], lvw.FocusedItem, "#A3");
+
+                       lvw.FocusedItem = null;
+                       Assert.AreEqual (lvw.Items [2], lvw.FocusedItem, "#A4");
+
+                       form.Dispose ();
+               }
+
+               [Test]
+               public void HotTracking ()
+               {
+                       ListView lvw = new ListView ();
+
+                       lvw.HotTracking = true;
+                       Assert.AreEqual (true, lvw.HotTracking, "#A1");
+                       Assert.AreEqual (true, lvw.HoverSelection, "#A2");
+                       Assert.AreEqual (ItemActivation.OneClick, lvw.Activation, "#A3");
+
+                       // HoverSelection and Activation keep the previous value
+                       lvw.HotTracking = false;
+                       Assert.AreEqual (false, lvw.HotTracking, "#B1");
+                       Assert.AreEqual (true, lvw.HoverSelection, "#B2");
+                       Assert.AreEqual (ItemActivation.OneClick, lvw.Activation, "#B3");
+
+                       lvw.HotTracking = true;
+                       try {
+                               lvw.HoverSelection = false;
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException) {
+                       }
+
+                       try {
+                               lvw.Activation = ItemActivation.Standard;
+                               Assert.Fail ("#C2");
+                       } catch (ArgumentException) {
+                       }
+               }
+
+               [Test]
+               public void RedrawItems_Exceptions ()
+               {
+                       ListView lvw = new ListView ();
+                       lvw.Items.Add ("A");
+                       lvw.Items.Add ("B");
+
+                       try {
+                               lvw.RedrawItems (-1, 1, true);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentOutOfRangeException) {
+                       }
+
+                       try {
+                               lvw.RedrawItems (0, -1, true);
+                               Assert.Fail ("#A2");
+                       } catch (ArgumentOutOfRangeException) {
+                       }
+
+                       try {
+                               lvw.RedrawItems (lvw.Items.Count, 1, true);
+                               Assert.Fail ("#A3");
+                       } catch (ArgumentOutOfRangeException) {
+                       }
+
+                       try {
+                               lvw.RedrawItems (0, lvw.Items.Count, true);
+                               Assert.Fail ("#A4");
+                       } catch (ArgumentOutOfRangeException) {
+                       }
+
+                       try {
+                               lvw.RedrawItems (1, 0, true);
+                               Assert.Fail ("#A5");
+                       } catch (ArgumentException) {
+                       }
+               }
+
                const int item_count = 3;
                ListViewItem [] items = new ListViewItem [item_count];
 
@@ -1857,5 +2059,26 @@ namespace MonoTests.System.Windows.Forms
                                        return String.Compare (item_x.Text, item_y.Text);
                        }
                }
+
+               [Test]
+               public void MethodIsInputChar ()
+               {
+                       // Basically, show that this method always returns true
+                       InputCharControl m = new InputCharControl ();
+                       bool result = true;
+
+                       for (int i = 0; i < 256; i++)
+                               result &= m.PublicIsInputChar ((char)i);
+
+                       Assert.AreEqual (true, result, "I1");
+               }
+
+               private class InputCharControl : ListView
+               {
+                       public bool PublicIsInputChar (char charCode)
+                       {
+                               return base.IsInputChar (charCode);
+                       }
+               }
        }
 }