public void SetUp()
		{
			listView = new ListView();
			sorter = new SequencePointListViewSorter(listView);
			
			listView.Columns.Add("Visit Count");
			listView.Columns.Add("Line");
			listView.Columns.Add("Column");
			listView.Columns.Add("End Line");
			listView.Columns.Add("End Column");
			
			// Add first sequence point.
			firstSequencePoint = new CodeCoverageSequencePoint(String.Empty, 1, 5, 1, 5, 10);
			ListViewItem item = new ListViewItem("First");
			item.Tag = firstSequencePoint;
			listView.Items.Add(item);
			
			// Add second sequence point.
			secondSequencePoint = new CodeCoverageSequencePoint(String.Empty, 0, 10, 2, 10, 8);
			item = new ListViewItem("Second");
			item.Tag = secondSequencePoint;
			listView.Items.Add(item);
			
			// Need to create the control's handle otherwise
			// the list view will not sort.
			listView.CreateControl();
		}
 public void Setup()
 {
     lv = new ListView();
     lv.CreateControl();
     interactor = new TestDiagnosticsInteractor();
     interactor.Attach(lv);
     svc = interactor;
     mr = new MockRepository();
 }
Esempio n. 3
0
		[Test] // bug #80620
		public void ClientRectangle_Borders ()
		{
			ListView lv = new ListView ();
			lv.CreateControl ();
			Assert.AreEqual (lv.ClientRectangle, new ListView ().ClientRectangle);
		}
		public void SelectedItemCollectionTest_Indexer2 ()
		{
			ListView lvw = new ListView ();
			ListViewItem lvi1 = new ListViewItem ("A");
			lvi1.Name = "A name";
			lvi1.Selected = true;
			ListViewItem lvi2 = new ListViewItem ("B");
			lvi2.Name = "Same name";
			lvi2.Selected = false;
			ListViewItem lvi3 = new ListViewItem ("C");
			lvi3.Name = "Same name";
			lvi3.Selected = true;
			ListViewItem lvi4 = new ListViewItem ("D");
			lvi4.Name = String.Empty;
			lvi4.Selected = true;
			ListViewItem lvi5 = new ListViewItem ("E");
			lvi5.Name = "E name";
			lvi5.Selected = false;
			lvw.Items.AddRange (new ListViewItem [] { lvi1, lvi2, lvi3, lvi4, lvi5 });

			// Force to create the control
			lvw.CreateControl ();

			Assert.AreEqual (3, lvw.SelectedItems.Count, "#A1");
			Assert.AreEqual (null, lvw.SelectedItems [String.Empty], "#A2");
			Assert.AreEqual (null, lvw.SelectedItems [null], "#A3");
			Assert.AreEqual (lvi1, lvw.SelectedItems ["A name"], "#A4");
			Assert.AreEqual (lvi1, lvw.SelectedItems ["a NAME"], "#A5");
			Assert.AreEqual (lvi3, lvw.SelectedItems ["Same name"], "#A6");
			Assert.AreEqual (null, lvw.SelectedItems ["E name"], "#A7");

			ListViewItem lvi6 = new ListViewItem ("F");
			lvw.Items.Add (lvi6);
			lvi6.Selected = true;
			lvi6.Name = "F name";

			Assert.AreEqual (4, lvw.SelectedItems.Count, "#B1");
			Assert.AreEqual (lvi6, lvw.SelectedItems ["F name"], "#B2");
			lvw.Dispose ();
		}
		public void SelectedIndexCollectionTest_RemoveTest_VirtualMode ()
		{
			ListView listview = new ListView ();
			listview.VirtualListSize = 5;
			listview.RetrieveVirtualItem += ListViewRetrieveVirtualItemHandler;
			listview.VirtualMode = true;
			CreateVirtualItems (5);

			// Force to create the handle
			listview.CreateControl ();

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Add (2);
			listview.SelectedIndices.Add (4);

			Assert.AreEqual (3, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#1");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_RemoveTest#2");
			Assert.AreEqual (true, listview.Items [2].Selected, "SelectedIndexCollectionTest_RemoveTest#3");
			Assert.AreEqual (true, listview.Items [4].Selected, "SelectedIndexCollectionTest_RemoveTest#4");
			Assert.AreEqual (0, listview.SelectedIndices [0], "SelectedIndexCollectionTest_RemoveTest#5");
			Assert.AreEqual (2, listview.SelectedIndices [1], "SelectedIndexCollectionTest_RemoveTest#6");
			Assert.AreEqual (4, listview.SelectedIndices [2], "SelectedIndexCollectionTest_RemoveTest#7");

			listview.SelectedIndices.Remove (2);
			Assert.AreEqual (2, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#8");
			Assert.AreEqual (false, listview.Items [2].Selected, "SelectedIndexCollectionTest_RemoveTest#9");
			Assert.AreEqual (0, listview.SelectedIndices [0], "SelectedIndexCollectionTest_RemoveTest#10");
			Assert.AreEqual (4, listview.SelectedIndices [1], "SelectedIndexCollectionTest_RemoveTest#11");

			listview.SelectedIndices.Remove (0);
			Assert.AreEqual (1, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#12");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_RemoveTest#13");
			Assert.AreEqual (4, listview.SelectedIndices [0], "SelectedIndexCollectionTest_RemoveTest#14");

			listview.SelectedIndices.Remove (4);
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#15");
			Assert.AreEqual (false, listview.Items [4].Selected, "SelectedIndexCollectionTest_RemoveTest#16");

			// Remove an already removed index
			listview.SelectedIndices.Remove (0);
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#17");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_RemoveTest#18");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_RemoveTest ()
		{
			ListView listview = new ListView ();
			listview.Items.Add ("A");

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Remove (0);
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#1");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_RemoveTest#2");

			// Force to create the handle
			listview.CreateControl ();

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Remove (0);
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_RemoveTest#3");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_RemoveTest#4");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_IndexOfTest_VirtualMode ()
		{
			ListView listview = new ListView ();
			listview.VirtualListSize = 4;
			listview.RetrieveVirtualItem += ListViewRetrieveVirtualItemHandler;
			listview.VirtualMode = true;
			CreateVirtualItems (4);

			// Force to create the handle
			listview.CreateControl ();

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Add (3);
			listview.SelectedIndices.Add (2);

			Assert.AreEqual (3, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_IndexOfTest#1");
			Assert.AreEqual (0, listview.SelectedIndices.IndexOf (0), "SelectedIndexCollectionTest_IndexOfTest#2");
			Assert.AreEqual (1, listview.SelectedIndices.IndexOf (2), "SelectedIndexCollectionTest_IndexOfTest#3");
			Assert.AreEqual (2, listview.SelectedIndices.IndexOf (3), "SelectedIndexCollectionTest_IndexOfTest#4");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (1), "SelectedIndexCollectionTest_IndexOfTest#5");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (99), "SelectedIndexCollectionTest_IndexOfTest#6");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (-1), "SelectedIndexCollectionTest_IndexOfTest#7");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_IndexOfTest ()
		{
			ListView listview = new ListView ();
			ListViewItem item1 = listview.Items.Add ("A");
			ListViewItem item2 = listview.Items.Add ("B");
			ListViewItem item3 = listview.Items.Add ("C");
			ListViewItem item4 = listview.Items.Add ("D");

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Add (3);
			listview.SelectedIndices.Add (2);

			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_IndexOfTest#1");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (item1.Index), "SelectedIndexCollectionTest_IndexOfTest#2");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (item3.Index), "SelectedIndexCollectionTest_IndexOfTest#3");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (item4.Index), "SelectedIndexCollectionTest_IndexOfTest#4");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (item2.Index), "SelectedIndexCollectionTest_IndexOfTest#5");

			// Force to create the control
			listview.CreateControl ();

			Assert.AreEqual (3, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_IndexOfTest#6");
			Assert.AreEqual (0, listview.SelectedIndices.IndexOf (item1.Index), "SelectedIndexCollectionTest_IndexOfTest#7");
			Assert.AreEqual (1, listview.SelectedIndices.IndexOf (item3.Index), "SelectedIndexCollectionTest_IndexOfTest#8");
			Assert.AreEqual (2, listview.SelectedIndices.IndexOf (item4.Index), "SelectedIndexCollectionTest_IndexOfTest#9");
			Assert.AreEqual (-1, listview.SelectedIndices.IndexOf (item2.Index), "SelectedIndexCollectionTest_IndexOfTest#10");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_ClearTest_VirtualMode ()
		{
			ListView listview = new ListView ();
			listview.VirtualListSize = 3;
			listview.RetrieveVirtualItem += ListViewRetrieveVirtualItemHandler;
			listview.VirtualMode = true;
			CreateVirtualItems (3);

			// Force to create the handle
			listview.CreateControl ();

			listview.SelectedIndices.Add (2);
			listview.SelectedIndices.Add (0);

			Assert.AreEqual (2, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_ClearTest#1");
			Assert.AreEqual (0, listview.SelectedIndices [0], "SelectedIndexCollectionTest_ClearTest#2");
			Assert.AreEqual (2, listview.SelectedIndices [1], "SelectedIndexCollectionTest_ClearTest#3");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_ClearTest#4");
			Assert.AreEqual (false, listview.Items [1].Selected, "SelectedIndexCollectionTest_ClearTest#5");
			Assert.AreEqual (true, listview.Items [2].Selected, "SelectedIndexCollectionTest_ClearTest#6");

			listview.SelectedIndices.Clear ();
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_ClearTest#5");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_ClearTest#6");
			Assert.AreEqual (false, listview.Items [1].Selected, "SelectedIndexCollectionTest_ClearTest#7");
			Assert.AreEqual (false, listview.Items [2].Selected, "SelectedIndexCollectionTest_ClearTest#8");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_ClearTest ()
		{
			ListView listview = new ListView ();
			listview.Items.Add ("A");
			listview.Items.Add ("B");
			listview.Items.Add ("C");

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Add (2);

			// Nothing if handle hasn't been created
			listview.SelectedIndices.Clear (); 
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_ClearTest#2");
			Assert.AreEqual (false, listview.Items [1].Selected, "SelectedIndexCollectionTest_ClearTest#3");
			Assert.AreEqual (true, listview.Items [2].Selected, "SelectedIndexCollectionTest_ClearTest#4");

			// Force to create the handle
			listview.CreateControl ();

			listview.SelectedIndices.Add (0);
			listview.SelectedIndices.Add (2);

			listview.SelectedIndices.Clear ();
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_ClearTest#5");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_ClearTest#6");
			Assert.AreEqual (false, listview.Items [1].Selected, "SelectedIndexCollectionTest_ClearTest#7");
			Assert.AreEqual (false, listview.Items [2].Selected, "SelectedIndexCollectionTest_ClearTest#8");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_AddTest_VirtualMode ()
		{
			ListView listview = new ListView ();
			listview.VirtualListSize = 5;
			listview.RetrieveVirtualItem += ListViewRetrieveVirtualItemHandler;
			listview.VirtualMode = true;
			CreateVirtualItems (5);

			int n = listview.SelectedIndices.Add (0);
			Assert.AreEqual (-1, n, "SelectedIndexCollectionTest_AddTest#1");
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#2");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#3");

			// Force to create the handle
			// Selection state should remain empty
			listview.CreateControl ();
			Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#4");
			Assert.AreEqual (false, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#5");

			n = listview.SelectedIndices.Add (0);
			Assert.AreEqual (1, n, "SelectedIndexCollectionTest_AddTest#5");
			Assert.AreEqual (1, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#6");
			Assert.AreEqual (0, listview.SelectedIndices [0], "SelectedIndexCollectionTest_AddTest#7");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#8");

			// Make sure the collection keeps them sorted
			listview.SelectedIndices.Add (4);
			n = listview.SelectedIndices.Add (2);
			Assert.AreEqual (3, n, "SelectedIndexCollectionTest_AddTest#9");
			Assert.AreEqual (3, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#10");
			Assert.AreEqual (0, listview.SelectedIndices [0], "SelectedIndexCollectionTest_AddTest#11");
			Assert.AreEqual (2, listview.SelectedIndices [1], "SelectedIndexCollectionTest_AddTest#12");
			Assert.AreEqual (4, listview.SelectedIndices [2], "SelectedIndexCollectionTest_AddTest#13");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#14");
			Assert.AreEqual (true, listview.Items [2].Selected, "SelectedIndexCollectionTest_AddTest#15");
			Assert.AreEqual (true, listview.Items [4].Selected, "SelectedIndexCollectionTest_AddTest#16");

			// Add the item twice
			n = listview.SelectedIndices.Add (0);
			Assert.AreEqual (3, n, "SelectedIndexCollectionTest_AddTest#17");
			Assert.AreEqual (3, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#18");
			listview.Dispose ();
		}
		public void SelectedIndexCollectionTest_AddTest ()
		{
			ListView listview = new ListView ();
			listview.Items.Add ("A");

			int n = listview.SelectedIndices.Add (0);
			Assert.AreEqual (0, n, "SelectedIndexCollectionTest_AddTest#1");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#2");

			// Force to create the handle
			listview.CreateControl ();
			Assert.AreEqual (1, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#4");

			n = listview.SelectedIndices.Add (0);
			Assert.AreEqual (1, n, "SelectedIndexCollectionTest_AddTest#5");
			Assert.AreEqual (1, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_AddTest#6");
			Assert.AreEqual (true, listview.Items [0].Selected, "SelectedIndexCollectionTest_AddTest#7");
			listview.Dispose ();
		}
Esempio n. 13
0
		public void ListViewItemPosition ()
		{
			ListViewItem itemA = new ListViewItem ();
			ListViewItem itemB = new ListViewItem ();
			Point initial_pos = new Point (-1, -1);

			Assert.AreEqual (itemA.Position, initial_pos, "#A1");
			Assert.AreEqual (itemB.Position, initial_pos, "#A2");

			ListView lvw = new ListView ();
			lvw.Items.AddRange (new ListViewItem [] { itemA, itemB });

			Assert.AreEqual (itemA.Position, initial_pos, "#B1");
			Assert.AreEqual (itemB.Position, initial_pos, "#B2");

			// Create handle for lvw
			lvw.CreateControl ();

			Point itemA_pos = itemA.Position;
			Point itemB_pos = itemB.Position;

			Assert.IsTrue (itemA_pos != initial_pos, "#C1");
			Assert.IsTrue (itemB_pos != initial_pos, "#C2");

			// Now remove
			lvw.Items.Clear ();

			Assert.AreEqual (itemA_pos, itemA.Position, "#D1");
			Assert.AreEqual (itemB_pos, itemB.Position, "#D2");

			// Add in reverse order
			lvw.Items.AddRange (new ListViewItem [] { itemB, itemA });

			Assert.IsTrue (itemA_pos != itemA.Position, "#E1");
			Assert.IsTrue (itemB_pos != itemB.Position, "#E2");

			// Remove from ListView
			lvw.Items.Clear ();
			Assert.IsTrue (initial_pos != itemA.Position, "#F1");
			Assert.IsTrue (initial_pos != itemB.Position, "#F2");

			//
			// Now add them in other view (no effect)
			//
			lvw.Items.AddRange (new ListViewItem [] { itemA, itemB });
			lvw.Columns.Add ("Column A");
			lvw.View = View.Details;

			itemB_pos = itemB.Position;
			Assert.IsTrue (Point.Empty != itemB_pos, "#G1");
			Assert.IsTrue (initial_pos != itemB_pos, "#G2");

			itemB.Position = Point.Empty;
			Assert.AreEqual (itemB_pos, itemB.Position, "#H1");
		}
Esempio n. 14
0
		public void Constructor_Serializable ()
		{
			ListViewItem item = new ListViewItem ("A");
			ListView lvw = new ListView ();
			lvw.Items.Add (item);
			lvw.CreateControl (); // Need to calculate layout

			item.SubItems.Add ("B");
			item.SubItems.Add ("C");
			item.SubItems.Add ("D");
			item.BackColor = Color.AliceBlue;
			item.Checked = true;
			item.Font = new Font (item.Font, FontStyle.Bold);
			item.ForeColor = Color.AntiqueWhite;
			item.ImageIndex = 1;
			item.Selected = true;
			item.Tag = "Tag";
			item.UseItemStyleForSubItems = false;

			ListViewGroup group = lvw.Groups.Add ("GroupKey", "MyGroup");
			group.Items.Add (item);

			item.ImageKey = "MyKey";
			item.IndentCount = 2;
			item.Name = "MyName";
			item.ToolTipText = "MyTooltipText";

			MemoryStream ms = new MemoryStream ();
			BinaryFormatter formatter = new BinaryFormatter ();
			formatter.Serialize (ms, item);

			ListViewItem item2 = null;
			ms.Position = 0;

			item2 = (ListViewItem) formatter.Deserialize (ms);
			Assert.AreEqual ("A", item2.Text, "#A1");
			Assert.AreEqual ("A", item2.SubItems [0].Text, "#A2");
			Assert.AreEqual ("B", item2.SubItems [1].Text, "#A3");
			Assert.AreEqual ("C", item2.SubItems [2].Text, "#A4");
			Assert.AreEqual (Color.AliceBlue, item2.BackColor, "#A4");
			Assert.AreEqual (null, item2.ListView, "#A5");
			Assert.AreEqual (Rectangle.Empty, item2.Bounds, "#A6");
			Assert.AreEqual (item.Checked, item2.Checked, "#A7");
			Assert.AreEqual (item.Font, item2.Font, "#A8");
			Assert.AreEqual (item.ForeColor, item2.ForeColor, "#A9");
			Assert.AreEqual (item.ImageIndex, item2.ImageIndex, "#A10");
			Assert.AreEqual (-1, item2.Index, "#A11");
			Assert.AreEqual (false, item2.Selected, "#A12");
			Assert.AreEqual (null, item2.Tag, "#A13");
			Assert.AreEqual (item.UseItemStyleForSubItems, item2.UseItemStyleForSubItems, "#A14");
			Assert.AreEqual (item.ImageKey, item2.ImageKey, "#A15");
			Assert.AreEqual (0, item2.IndentCount, "#A16");
			Assert.AreEqual (String.Empty, item2.Name, "#A17");
			Assert.AreEqual (new Point (-1, -1), item2.Position, "#A18");
			Assert.AreEqual (String.Empty, item2.ToolTipText, "#A19");
			Assert.AreEqual (item.Group.Header, item2.Group.Header, "#A20");
		}
Esempio n. 15
0
		public void Width_AutoResize_Expand ()
		{
			ListView lv = new ListView ();
			lv.BeginUpdate ();
			lv.View = View.Details;
			ColumnHeader col1 = new ColumnHeader ("One");
			ColumnHeader col2 = new ColumnHeader ("Two");
			lv.Columns.AddRange (new ColumnHeader [] { col1, col2 });
			lv.EndUpdate ();

			col1.Width = 10;
			col2.Width = 10;
			Assert.AreEqual (10, col1.Width, "#A1");
			Assert.AreEqual (10, col2.Width, "#A2");

			// Need to create the handle in order to actually use the auto size feature
			lv.CreateControl ();

			col2.Width = -2;
			Assert.AreEqual (true, col2.Width == lv.ClientRectangle.Width - col1.Width, "#B1");
		}
Esempio n. 16
0
		public void WidthTest ()
		{
			ColumnHeader col = new ColumnHeader ();
			col.Text = "Column text";

			ListView lv = new ListView ();
			lv.Items.Add ("Item text");
			lv.View = View.Details;
			lv.Columns.Add (col);
			lv.CreateControl ();

			col.Width = -1;
			Assert.IsTrue (col.Width > 0, "#1");

			col.Width = -2;
			Assert.IsTrue (col.Width > 0, "#2");

			bool eventRaised = false;
			lv.ColumnWidthChanged += delegate (object sender, ColumnWidthChangedEventArgs e) {
				Assert.AreEqual (e.ColumnIndex, 0, "#3");
				eventRaised = true;
			};
			col.Width = 100;
			Assert.IsTrue (eventRaised, "#4");
		}