* Test/System.Windows.Forms/TestHelper.cs: Inconsistent eol fixes and
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ListViewTest.cs
index 9b3209ee5fa60f68b30f8ba43e218874ab922a30..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];
 
@@ -440,9 +642,6 @@ namespace MonoTests.System.Windows.Forms
                        lvw.VirtualMode = true;
 
                        CreateListViewItems (item_count);
-                       items [0].Name = "A";
-                       items [1].Name = "B";
-                       items [2].Name = "C";
 
                        Assert.AreEqual (item_count, lvw.Items.Count, "#A1");
                        Assert.AreEqual (true, lvw.VirtualMode, "#A2");
@@ -450,12 +649,31 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (items [0], lvw.Items [0], "#B1");
                        Assert.AreEqual (items [1], lvw.Items [1], "#B2");
                        Assert.AreEqual (items [2], lvw.Items [2], "#B3");
+                       Assert.AreEqual (0, lvw.Items [0].Index, "#B4");
+                       Assert.AreEqual (1, lvw.Items [1].Index, "#B5");
+                       Assert.AreEqual (2, lvw.Items [2].Index, "#B6");
+                       Assert.AreEqual (lvw, lvw.Items [0].ListView, "#B7");
+                       Assert.AreEqual (lvw, lvw.Items [1].ListView, "#B8");
+                       Assert.AreEqual (lvw, lvw.Items [2].ListView, "#B9");
+
+                       // force to re-create the items, because we need a blank state
+                       // for our items
+                       CreateListViewItems (item_count);
+                       items [0].Name = "A";
+                       items [1].Name = "B";
+                       items [2].Name = "C";
 
                        Assert.AreEqual (items [0], lvw.Items ["A"], "#C1");
                        Assert.AreEqual (items [1], lvw.Items ["B"], "#C2");
                        Assert.AreEqual (items [2], lvw.Items ["C"], "#C3");
-                       Assert.IsNull (lvw.Items ["Invalid key"], "#C4");
-                       Assert.IsNull (lvw.Items [String.Empty], "#C5");
+                       Assert.AreEqual (0, lvw.Items ["A"].Index, "#C4");
+                       Assert.AreEqual (1, lvw.Items ["B"].Index, "#C5");
+                       Assert.AreEqual (2, lvw.Items ["C"].Index, "#C6");
+                       Assert.AreEqual (lvw, lvw.Items ["A"].ListView, "#C7");
+                       Assert.AreEqual (lvw, lvw.Items ["B"].ListView, "#C8");
+                       Assert.AreEqual (lvw, lvw.Items ["C"].ListView, "#C9");
+                       Assert.IsNull (lvw.Items ["Invalid key"], "#C10");
+                       Assert.IsNull (lvw.Items [String.Empty], "#C11");
 
                        Assert.AreEqual (false, lvw.Items.ContainsKey (String.Empty), "#D1");
                        Assert.AreEqual (false, lvw.Items.ContainsKey (null), "#D2");
@@ -1841,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);
+                       }
+               }
        }
 }