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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
//
// PropertyGridTest.cs: Test cases for PropertyGrid.
//
// Author:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) 2006 Novell, Inc. (http://www.novell.com)
//
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;
using NUnit.Framework;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
public class PropertyGridTest : TestHelper
{
[Test]
public void PropertySort_Valid ()
{
PropertyGrid pg;
EventLogger eventLogger;
pg = new PropertyGrid ();
eventLogger = new EventLogger (pg);
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#A1");
Assert.AreEqual (0, eventLogger.EventsRaised, "#A2");
pg.PropertySort = PropertySort.Alphabetical;
Assert.AreEqual (PropertySort.Alphabetical, pg.PropertySort, "#A3");
Assert.AreEqual (1, eventLogger.EventsRaised, "#A4");
Assert.AreEqual (1, eventLogger.CountEvents ("PropertySortChanged"), "#A5");
pg.PropertySort = PropertySort.NoSort;
Assert.AreEqual (PropertySort.NoSort, pg.PropertySort, "#A6");
Assert.AreEqual (2, eventLogger.EventsRaised, "#A7");
Assert.AreEqual (2, eventLogger.CountEvents ("PropertySortChanged"), "#A8");
pg.PropertySort = PropertySort.NoSort;
Assert.AreEqual (PropertySort.NoSort, pg.PropertySort, "#A9");
Assert.AreEqual (2, eventLogger.EventsRaised, "#A10");
Assert.AreEqual (2, eventLogger.CountEvents ("PropertySortChanged"), "#A11");
pg.PropertySort = PropertySort.CategorizedAlphabetical;
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#A12");
Assert.AreEqual (3, eventLogger.EventsRaised, "#A13");
Assert.AreEqual (3, eventLogger.CountEvents ("PropertySortChanged"), "#A14");
pg.PropertySort = PropertySort.Categorized;
Assert.AreEqual (PropertySort.Categorized, pg.PropertySort, "#A14");
Assert.AreEqual (3, eventLogger.EventsRaised, "#A15");
Assert.AreEqual (3, eventLogger.CountEvents ("PropertySortChanged"), "#A16");
pg = new PropertyGrid ();
eventLogger = new EventLogger (pg);
pg.SelectedObject = new Button ();
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#B1");
Assert.AreEqual (0, eventLogger.CountEvents ("PropertySortChanged"), "#B2");
pg.PropertySort = PropertySort.Alphabetical;
Assert.AreEqual (PropertySort.Alphabetical, pg.PropertySort, "#B3");
Assert.AreEqual (1, eventLogger.CountEvents ("PropertySortChanged"), "#B4");
pg.PropertySort = PropertySort.NoSort;
Assert.AreEqual (PropertySort.NoSort, pg.PropertySort, "#B5");
Assert.AreEqual (2, eventLogger.CountEvents ("PropertySortChanged"), "#B6");
pg.PropertySort = PropertySort.CategorizedAlphabetical;
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#B7");
Assert.AreEqual (3, eventLogger.CountEvents ("PropertySortChanged"), "#B8");
pg.PropertySort = PropertySort.CategorizedAlphabetical;
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#B9");
Assert.AreEqual (3, eventLogger.CountEvents ("PropertySortChanged"), "#B10");
pg.SelectedObject = null;
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#C1");
Assert.AreEqual (3, eventLogger.CountEvents ("PropertySortChanged"), "#C2");
pg.PropertySort = PropertySort.Alphabetical;
Assert.AreEqual (PropertySort.Alphabetical, pg.PropertySort, "#C3");
Assert.AreEqual (4, eventLogger.CountEvents ("PropertySortChanged"), "#C4");
pg.PropertySort = PropertySort.NoSort;
Assert.AreEqual (PropertySort.NoSort, pg.PropertySort, "#C5");
Assert.AreEqual (5, eventLogger.CountEvents ("PropertySortChanged"), "#C6");
pg.SelectedObject = new Button ();
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (pg);
form.Show ();
Assert.AreEqual (PropertySort.NoSort, pg.PropertySort, "#D1");
Assert.AreEqual (5, eventLogger.CountEvents ("PropertySortChanged"), "#D2");
pg.PropertySort = PropertySort.Alphabetical;
Assert.AreEqual (PropertySort.Alphabetical, pg.PropertySort, "#D3");
Assert.AreEqual (6, eventLogger.CountEvents ("PropertySortChanged"), "#D4");
pg.PropertySort = PropertySort.Categorized;
Assert.AreEqual (PropertySort.Categorized, pg.PropertySort, "#D5");
Assert.AreEqual (7, eventLogger.CountEvents ("PropertySortChanged"), "#D6");
pg.PropertySort = PropertySort.CategorizedAlphabetical;
Assert.AreEqual (PropertySort.CategorizedAlphabetical, pg.PropertySort, "#D7");
Assert.AreEqual (7, eventLogger.CountEvents ("PropertySortChanged"), "#D8");
form.Dispose ();
}
[Test]
public void PropertySort_Invalid ()
{
PropertyGrid pg = new PropertyGrid ();
EventLogger eventLogger = new EventLogger (pg);
try {
pg.PropertySort = (PropertySort) 666;
Assert.Fail ("#1");
} catch (InvalidEnumArgumentException ex) {
// The value of argument 'value' (666) is invalid
// for Enum type 'PropertySort'
Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf ("'value'") != -1, "#5");
Assert.IsTrue (ex.Message.IndexOf ("(" + 666.ToString (CultureInfo.CurrentCulture) + ")") != -1, "#6");
Assert.IsTrue (ex.Message.IndexOf ("'PropertySort'") != -1, "#7");
Assert.IsNotNull (ex.ParamName, "#8");
Assert.AreEqual ("value", ex.ParamName, "#9");
Assert.AreEqual (0, eventLogger.EventsRaised, "#10");
}
}
[Test]
public void SelectedObject ()
{
PropertyGrid pg = new PropertyGrid ();
Button button1 = new Button ();
Assert.IsNull (pg.SelectedObject, "#A1");
Assert.IsNotNull (pg.SelectedObjects, "#A2");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#A3");
pg.SelectedObject = button1;
Assert.IsNotNull (pg.SelectedObject, "#B1");
Assert.AreSame (button1, pg.SelectedObject, "#B2");
Assert.IsNotNull (pg.SelectedObjects, "#B3");
Assert.AreEqual (1, pg.SelectedObjects.Length, "#B4");
Assert.AreSame (button1, pg.SelectedObjects [0], "#B5");
Assert.IsNotNull (pg.SelectedGridItem, "#B6");
}
[Test] // bug #81796
public void SelectedObject_NoProperties ()
{
PropertyGrid propertyGrid = new PropertyGrid ();
propertyGrid.SelectedObject = new Button ();
propertyGrid.SelectedObject = new object ();
propertyGrid.SelectedObject = new Button ();
}
[Test]
public void SelectedObject_Null ()
{
PropertyGrid pg = new PropertyGrid ();
Assert.IsNull (pg.SelectedObject, "#A1");
Assert.IsNotNull (pg.SelectedObjects, "#A2");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#A3");
pg.SelectedObject = null;
Assert.IsNull (pg.SelectedObject, "#B1");
Assert.IsNotNull (pg.SelectedObjects, "#B2");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#B3");
}
[Test]
public void SelectedObject_Null2 ()
{
PropertyGrid pg = new PropertyGrid ();
EventLogger log = new EventLogger (pg);
Assert.IsNull (pg.SelectedObject, "#A1");
Assert.IsNotNull (pg.SelectedObjects, "#A2");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#A3");
Assert.IsNull (pg.SelectedGridItem, "A4");
pg.SelectedObject = new TextBox ();
Assert.IsNotNull (pg.SelectedObject, "#B1");
Assert.IsNotNull (pg.SelectedObjects, "#B2");
Assert.AreEqual (1, pg.SelectedObjects.Length, "#B3");
Assert.IsNotNull (pg.SelectedGridItem, "B4");
Assert.AreEqual (1, log.EventsRaised, "B5");
Assert.AreEqual ("SelectedObjectsChanged", log.EventsJoined (";"), "B6");
pg.SelectedObject = null;
Assert.IsNull (pg.SelectedObject, "#C1");
Assert.IsNotNull (pg.SelectedObjects, "#C2");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#C3");
Assert.IsNull (pg.SelectedGridItem, "C4");
Assert.AreEqual (2, log.EventsRaised, "C5");
Assert.AreEqual ("SelectedObjectsChanged;SelectedObjectsChanged", log.EventsJoined (";"), "C6");
}
[Test]
public void SelectedGridItem_Null ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = new TextBox ();
Assert.IsNotNull (pg.SelectedGridItem, "#1");
try {
pg.SelectedGridItem = null;
Assert.Fail ("#2");
} catch (ArgumentException ex) {
// GridItem specified to PropertyGrid.SelectedGridItem must be
// a valid GridItem
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#3");
Assert.IsNull (ex.InnerException, "#4");
Assert.IsNotNull (ex.Message, "#5");
Assert.IsNull (ex.ParamName, "#6");
}
}
[Test] // bug #79615
public void SelectedObjects_Multiple ()
{
Button button1 = new Button ();
Button button2 = new Button ();
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObjects = new object [] { button1, button2 };
Assert.IsNotNull (pg.SelectedObjects, "#1");
Assert.AreEqual (2, pg.SelectedObjects.Length, "#2");
Assert.AreSame (button1, pg.SelectedObjects [0], "#3");
Assert.AreSame (button2, pg.SelectedObjects [1], "#4");
Assert.IsNotNull (pg.SelectedObject, "#5");
Assert.AreSame (button1, pg.SelectedObject, "#6");
}
[Test]
public void SelectedObjects_Null ()
{
PropertyGrid pg = new PropertyGrid ();
Button button1 = new Button ();
pg.SelectedObjects = new object [] { button1 };
Assert.IsNotNull (pg.SelectedObjects, "#A1");
Assert.AreEqual (1, pg.SelectedObjects.Length, "#A2");
Assert.AreSame (button1, pg.SelectedObjects [0], "#A3");
Assert.AreSame (button1, pg.SelectedObject, "#A4");
pg.SelectedObjects = null;
Assert.IsNotNull (pg.SelectedObjects, "#B1");
Assert.AreEqual (0, pg.SelectedObjects.Length, "#B2");
Assert.IsNull (pg.SelectedObject, "#B3");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void SelectedObjects_Null_Item ()
{
PropertyGrid pg = new PropertyGrid ();
Button button1 = new Button ();
pg.SelectedObjects = new object [] { button1, null };
}
[Test]
[Category ("NotWorking")]
public void PropertyGrid_MergedTest ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObjects = new object[] { new Button (), new Label () };
Assert.IsNotNull (pg.SelectedGridItem, "1");
Assert.AreEqual ("Accessibility", pg.SelectedGridItem.Label, "2");
Assert.AreEqual (GridItemType.Category, pg.SelectedGridItem.GridItemType, "3");
}
[Test]
[Category ("NotWorking")]
public void PropertyGrid_MergedRootTest ()
{
object[] selected_objects = new object[] { new Button (), new Label () };
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObjects = selected_objects;
Assert.IsNotNull (pg.SelectedGridItem.Parent, "1");
Assert.AreEqual ("System.Object[]", pg.SelectedGridItem.Parent.Label, "2");
Assert.AreEqual (GridItemType.Root, pg.SelectedGridItem.Parent.GridItemType, "3");
Assert.AreEqual (selected_objects, pg.SelectedGridItem.Parent.Value, "4");
Assert.IsNull (pg.SelectedGridItem.Parent.Parent, "5");
}
class ArrayTest_object
{
int[] array;
public ArrayTest_object ()
{
array = new int[10];
for (int i = 0; i < array.Length; i ++)
array[i] = array.Length - i;
}
public int[] Array {
get { return array; }
}
}
[Test]
public void PropertyGrid_ArrayTest ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = new ArrayTest_object ();
// selected object
Assert.AreEqual ("Array", pg.SelectedGridItem.Label, "1");
Assert.IsTrue (pg.SelectedGridItem.Value is Array, "2");
Assert.AreEqual (10, pg.SelectedGridItem.GridItems.Count, "3");
Assert.AreEqual (GridItemType.Property, pg.SelectedGridItem.GridItemType, "4");
}
[Test]
public void PropertyGrid_ArrayParentTest ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = new ArrayTest_object ();
// parent
Assert.IsNotNull (pg.SelectedGridItem.Parent, "1");
Assert.AreEqual ("Misc", pg.SelectedGridItem.Parent.Label, "2");
Assert.AreEqual (GridItemType.Category, pg.SelectedGridItem.Parent.GridItemType, "3");
Assert.AreEqual (1, pg.SelectedGridItem.Parent.GridItems.Count, "4");
}
[Test]
public void PropertyGrid_ArrayRootTest ()
{
ArrayTest_object obj = new ArrayTest_object ();
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = obj;
// grandparent
Assert.IsNotNull (pg.SelectedGridItem.Parent.Parent, "1");
Assert.AreEqual (typeof(ArrayTest_object).ToString(), pg.SelectedGridItem.Parent.Parent.Label, "2");
Assert.AreEqual (GridItemType.Root, pg.SelectedGridItem.Parent.Parent.GridItemType, "3");
Assert.AreEqual (1, pg.SelectedGridItem.Parent.Parent.GridItems.Count, "4");
Assert.AreEqual (obj, pg.SelectedGridItem.Parent.Parent.Value, "5");
Assert.IsNull (pg.SelectedGridItem.Parent.Parent.Parent, "6");
}
[Test]
public void PropertyGrid_ArrayChildrenTest ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = new ArrayTest_object ();
// children
Assert.AreEqual ("[0]", pg.SelectedGridItem.GridItems[0].Label, "1");
Assert.AreEqual (GridItemType.Property, pg.SelectedGridItem.GridItems[0].GridItemType, "2");
Assert.AreEqual (10, pg.SelectedGridItem.GridItems[0].Value, "3");
Assert.AreEqual (0, pg.SelectedGridItem.GridItems[0].GridItems.Count, "4");
}
[Test]
public void PropertyGrid_ItemSelectTest ()
{
PropertyGrid pg = new PropertyGrid ();
pg.SelectedObject = new ArrayTest_object ();
// the selected grid item is the "Array" property item.
GridItem array_item = pg.SelectedGridItem;
GridItem misc_item = array_item.Parent;
GridItem root_item = misc_item.Parent;
Assert.AreEqual (array_item, pg.SelectedGridItem, "1");
Assert.IsTrue (misc_item.Select (), "2");
Assert.AreEqual (misc_item, pg.SelectedGridItem, "3");
Assert.IsTrue (array_item.Select (), "4");
Assert.AreEqual (array_item, pg.SelectedGridItem, "5");
Assert.IsFalse (root_item.Select (), "6");
Assert.AreEqual (array_item, pg.SelectedGridItem, "7");
}
}
}
|