1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
//
// Copyright (c) 2005 Novell, Inc.
//
// Authors:
// Ritvik Mayank (mritvik@novell.com)
//
using System;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using NUnit.Framework;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
public class CheckedListBoxTest
{
[Test]
public void CheckedListBoxPropertyTest ()
{
Form myform = new Form ();
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
ArrayList checked_items = new ArrayList (2);
ArrayList checked_pos = new ArrayList (2);
mychklistbox.Items.Add ("test1", true);
checked_items.Add ("test1"); checked_pos.Add (0);
mychklistbox.Items.Add ("test2");
mychklistbox.Items.Add ("test3", true);
checked_items.Add ("test3"); checked_pos.Add (2);
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
Assert.AreEqual (checked_items.Count, mychklistbox.CheckedIndices.Count, "#1");
Assert.AreEqual (checked_items.Count, mychklistbox.CheckedItems.Count, "#2");
foreach (object o in mychklistbox.CheckedItems)
{
Assert.IsTrue (checked_items.Contains (o),"#3");
checked_items.Remove (o);
}
Assert.AreEqual (0, checked_items.Count);
for (int i = 0; i < mychklistbox.Items.Count; ++i)
{
if (checked_pos.Contains (i))
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (i),"#4");
else
Assert.IsFalse (CheckState.Checked == mychklistbox.GetItemCheckState (i),"#5");
}
Assert.AreEqual (false, mychklistbox.CheckOnClick, "#6");
Assert.AreEqual (3, mychklistbox.Items.Count, "#7");
Assert.AreEqual (SelectionMode.One, mychklistbox.SelectionMode, "#8");
Assert.AreEqual (false , mychklistbox.ThreeDCheckBoxes, "#9");
}
[Test]
public void GetItemCheckedTest ()
{
Form f = new Form ();
f.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1",true);
mychklistbox.Items.Add ("test2",CheckState.Indeterminate);
mychklistbox.Items.Add ("test3");
mychklistbox.Visible = true;
f.Controls.Add (mychklistbox);
Assert.AreEqual (true, mychklistbox.GetItemChecked (0), "#10");
Assert.AreEqual (true, mychklistbox.GetItemChecked (1), "#11");
Assert.AreEqual (false, mychklistbox.GetItemChecked (2), "#12");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException) )]
public void GetItemCheckedExceptionTest ()
{
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1",true);
Assert.AreEqual (true, mychklistbox.GetItemChecked (1), "#13");
}
[Test]
public void GetItemCheckStateTest ()
{
Form f = new Form ();
f.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1",true);
mychklistbox.Items.Add ("test2",CheckState.Indeterminate);
mychklistbox.Items.Add ("test3");
mychklistbox.Visible = true;
f.Controls.Add (mychklistbox);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#14");
Assert.AreEqual (CheckState.Indeterminate, mychklistbox.GetItemCheckState (1), "#15");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (2), "#16");
}
[Test]
public void SetItemCheckedTest ()
{
Form myform = new Form ();
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1");
mychklistbox.Items.Add ("test2");
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
mychklistbox.SetItemChecked (0,true);
mychklistbox.SetItemChecked (1,false);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#17");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (1), "#18");
}
[Test]
public void SetItemCheckStateTest ()
{
Form myform = new Form ();
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1");
mychklistbox.Items.Add ("test2");
mychklistbox.Items.Add ("test3");
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
mychklistbox.SetItemCheckState (0,CheckState.Checked);
mychklistbox.SetItemCheckState (1,CheckState.Indeterminate);
mychklistbox.SetItemCheckState (2,CheckState.Unchecked);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#19");
Assert.AreEqual (CheckState.Indeterminate, mychklistbox.GetItemCheckState (1), "#20");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (2), "#21");
}
}
}
|