4 using System
.Windows
.Controls
;
5 using System
.Windows
.Documents
;
6 using System
.Windows
.Ink
;
7 using System
.Windows
.Input
;
8 using System
.Windows
.Media
;
9 using System
.Windows
.Media
.Animation
;
10 using System
.Windows
.Shapes
;
11 using System
.Collections
.Generic
;
12 using Mono
.Moonlight
.UnitTesting
;
13 using Microsoft
.VisualStudio
.TestTools
.UnitTesting
;
14 using System
.Threading
;
16 #pragma warning disable 414
17 #pragma warning disable 219
19 namespace MoonTest
.System
.Windows
22 public class DependencyPropertyAttachedTest
25 * Declaring Type _ Property Name _ [index, not included in property name _] _ Property Type
27 private DependencyPropertyInfo Canvas_Custom_double
;
28 private DependencyPropertyInfo Canvas_Custom_Canvas
;
29 private DependencyPropertyInfo Canvas_Custom_CustomClass
;
30 private DependencyPropertyInfo Canvas_Custom_CustomCanvasType
;
32 private DependencyPropertyInfo Canvas_Height_int
;
33 private DependencyPropertyInfo Canvas_Height_double
;
34 private DependencyPropertyInfo Canvas_Height_CustomClass
;
35 private DependencyPropertyInfo Canvas_Height_CustomCanvasType
;
37 private DependencyPropertyInfo CustomClass_Height_int
;
38 private DependencyPropertyInfo CustomClass_Height_double
;
39 private DependencyPropertyInfo CustomClass_Height_CustomClass
;
40 private DependencyPropertyInfo CustomClass_Height_CustomCanvasType
;
42 private DependencyPropertyInfo CustomCanvasType_Height_int
;
43 private DependencyPropertyInfo CustomCanvasType_Height_double
;
44 private DependencyPropertyInfo CustomCanvasType_Height_void
;
45 private DependencyPropertyInfo CustomCanvasType_Height_Canvas
;
46 private DependencyPropertyInfo CustomCanvasType_Height_CustomClass
;
47 private DependencyPropertyInfo CustomCanvasType_Height_CustomCanvasType
;
48 private DependencyPropertyInfo CustomCanvasType_Height_CustomInterface
;
49 private DependencyPropertyInfo CustomCanvasType_Height_CustomStruct
;
50 private DependencyPropertyInfo CustomCanvasType_Height_CustomEnum
;
51 private DependencyPropertyInfo CustomCanvasType_Height_CustomDelegate
;
52 private DependencyPropertyInfo CustomCanvasType_Height_CustomClassCtorA
;
53 private DependencyPropertyInfo CustomCanvasType_Height_CustomClassCtorB
;
55 private DependencyPropertyInfo CustomCanvasType2_Height_double
;
57 // These are interesting because Height is already defined on FrameworkElement
58 private DependencyPropertyInfo FrameworkElement_Height_int
;
59 private DependencyPropertyInfo FrameworkElement_Height_double
;
60 private DependencyPropertyInfo FrameworkElement_Height_CustomClass
;
63 public void Register_NullParametersTest ()
65 Assert
.Throws (delegate { DependencyProperty.RegisterAttached (null, typeof (int), typeof (Canvas), new PropertyMetadata (null)); }
, typeof (ArgumentNullException
));
66 Assert
.Throws (delegate { DependencyProperty.RegisterAttached (string.Empty, typeof (int), typeof (Canvas), new PropertyMetadata (null)); }
, typeof (ArgumentException
));
67 Assert
.Throws (delegate { DependencyProperty.RegisterAttached ("a", null, typeof (Canvas), new PropertyMetadata (null)); }
, typeof (ArgumentNullException
));
68 Assert
.Throws (delegate { DependencyProperty.RegisterAttached ("a", typeof (int), null, new PropertyMetadata (null)); }
, typeof (ArgumentNullException
));
69 // null PropertyMetadata shouldn't throw.
70 DependencyProperty
.RegisterAttached ("a", typeof (int), typeof (Canvas
), null);
74 public void Register_HuhTest1 ()
76 DependencyPropertyInfo info
= new DependencyPropertyInfo ("Custom", typeof (InkPresenter
), typeof (int), true);
77 DependencyProperty property
= info
.Property
;
78 Canvas canvas
= new Canvas ();
80 canvas
.GetValue (property
); // This should throw, the property doesn't exist on the canvas.
82 Assert
.Throws (delegate { canvas.GetValue (InkPresenter.StrokesProperty); }
, typeof (Exception
)); // And this throws a catastrophic error.
86 public void Check_Default ()
88 DependencyProperty property
= DependencyProperty
.Register ("MyProp", typeof (int), typeof(Rectangle
), new PropertyMetadata (100));
89 Rectangle r
= new Rectangle ();
90 r
.SetValue (property
, 10);
91 Assert
.AreEqual (10, r
.GetValue (property
), "#1");
92 r
.ClearValue (property
);
93 Assert
.AreEqual (100, r
.GetValue (property
), "#2");
98 public void Register_Callback()
100 ManualResetEvent handle
= new ManualResetEvent(false);
101 DependencyProperty prop
= DependencyProperty
.Register("Callback", typeof(int), typeof(Rectangle
),
102 new PropertyMetadata((PropertyChangedCallback
)delegate { triggered = new object(); }
));
103 Rectangle r
= new Rectangle();
105 Assert
.IsNotNull(triggered
);
109 public void Check_Default_Nullable ()
111 DependencyProperty property
= DependencyProperty
.Register ("MyPropNullable", typeof (int?), typeof(Rectangle
), null);
112 Rectangle r
= new Rectangle ();
113 r
.SetValue (property
, 10);
114 Assert
.AreEqual (10, r
.GetValue (property
), "#1");
115 r
.ClearValue (property
);
116 Assert
.AreEqual (null, r
.GetValue (property
), "#2");
119 #region Canvas Custom
121 public void Register_Canvas_Custom_double ()
123 Canvas canvas
= new Canvas ();
124 CustomCanvasType custom_canvas
= new CustomCanvasType ();
125 DependencyProperty property
;
126 DependencyPropertyInfo info
;
127 DependencyPropertyInfo
.ChangedInfo changed_info
;
128 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
130 object previous_expected_value
= (double) 0;
134 Canvas_Custom_double
= new DependencyPropertyInfo ("Custom", typeof (Canvas
), typeof (double), true);
135 info
= Canvas_Custom_double
;
137 property
= info
.Property
;
139 Assert
.AreEqual (0.0, (double) canvas
.GetValue (property
));
141 Assert
.AreEqual (0.0, (double) ink
.GetValue (property
));
143 Assert
.Throws (delegate { canvas.SetValue (property, 1); }
, typeof (ArgumentException
));
144 Assert
.Throws (delegate { canvas.SetValue (property, ""); }
, typeof (ArgumentException
));
145 Assert
.Throws (delegate { canvas.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
146 Assert
.Throws (delegate { canvas.SetValue (property, null); }
, typeof (ArgumentException
));
147 Assert
.Throws (delegate { canvas.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
149 foreach (object expected_value
in new object [] { 1.1 }
) {
152 canvas
.SetValue (property
, expected_value
);
153 actual_value
= canvas
.GetValue (property
);
155 if ((double) expected_value
!= (double) previous_expected_value
) {
157 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
158 Assert
.AreEqual ((double) changed_info
.args
.OldValue
, (double) previous_expected_value
);
159 Assert
.AreEqual ((double) changed_info
.args
.NewValue
, (double) expected_value
);
160 Assert
.AreSame (changed_info
.obj
, canvas
);
163 previous_expected_value
= expected_value
;
165 Assert
.AreEqual ((double) expected_value
, (double) actual_value
, "Iteration #{0}", iterations
);
166 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
171 public void Register_Canvas_Custom_CustomClass ()
173 Canvas_Custom_CustomClass
= new DependencyPropertyInfo ("Custom", typeof (Canvas
), typeof (CustomClass
), true);
177 public void Register_Canvas_Custom_Canvas ()
179 Canvas canvas
= new Canvas ();
180 CustomCanvasType custom_canvas
= new CustomCanvasType ();
181 DependencyProperty property
;
182 DependencyPropertyInfo info
;
183 DependencyPropertyInfo
.ChangedInfo changed_info
;
184 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
186 object previous_expected_value
= null;
190 Canvas_Custom_Canvas
= new DependencyPropertyInfo ("Custom", typeof (Canvas
), typeof (Canvas
), true);
191 info
= Canvas_Custom_Canvas
;
193 property
= info
.Property
;
195 Assert
.IsNull (canvas
.GetValue (property
));
196 Assert
.IsNull (ink
.GetValue (property
));
198 Assert
.Throws (delegate { canvas.SetValue (property, 1); }
, typeof (ArgumentException
));
199 Assert
.Throws (delegate { canvas.SetValue (property, ""); }
, typeof (ArgumentException
));
200 Assert
.Throws (delegate { canvas.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
202 foreach (object expected_value
in new object [] { null, new Canvas (), null, canvas, canvas, null, new CustomCanvasType (), custom_canvas, custom_canvas, ink }
) {
205 canvas
.SetValue (property
, expected_value
);
206 actual_value
= canvas
.GetValue (property
);
208 if (expected_value
!= previous_expected_value
) {
210 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
211 Assert
.AreSame (changed_info
.args
.OldValue
, previous_expected_value
);
212 Assert
.AreSame (changed_info
.args
.NewValue
, expected_value
);
213 Assert
.AreSame (changed_info
.obj
, canvas
);
216 previous_expected_value
= expected_value
;
218 Assert
.AreSame (expected_value
, actual_value
, "Iteration #{0}", iterations
);
219 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
224 public void Register_Canvas_Custom_CustomCanvasType ()
226 Canvas_Custom_CustomCanvasType
= new DependencyPropertyInfo ("Custom", typeof (Canvas
), typeof (CustomCanvasType
), true);
229 #region Canvas Height
231 public void Register_Canvas_Height_int ()
233 // Register a custom property with the same name and type as an existing builtin property
234 Canvas_Height_int
= new DependencyPropertyInfo ("Height", typeof (Canvas
), typeof (int), true);
238 public void Register_Canvas_Height_double ()
240 // Register a custom property with the same name and type as an existing builtin property
241 Canvas_Height_double
= new DependencyPropertyInfo ("Height", typeof (Canvas
), typeof (double), true);
245 public void Register_Canvas_Height_CustomClass ()
247 // Register a custom property with the same name (but not type) as an existing builtin AND another custom property
248 Canvas_Height_CustomClass
= new DependencyPropertyInfo ("Height", typeof (Canvas
), typeof (CustomClass
), true);
252 public void Register_Canvas_Height_CustomCanvasType ()
254 // Register a custom property with the same name (but not type) as an existing builtin AND another custom property
255 Canvas_Height_CustomCanvasType
= new DependencyPropertyInfo ("Height", typeof (Canvas
), typeof (CustomCanvasType
), true);
258 #region CustomClass Height
260 public void Register_CustomClass_Height_int ()
262 CustomClass_Height_int
= new DependencyPropertyInfo ("Height", typeof (CustomClass
), typeof (int), true);
266 public void Register_CustomClass_Height_double ()
268 CustomClass_Height_double
= new DependencyPropertyInfo ("Height", typeof (CustomClass
), typeof (double), true);
272 public void Register_CustomClass_Height_CustomClass ()
274 CustomClass_Height_CustomClass
= new DependencyPropertyInfo ("Height", typeof (CustomClass
), typeof (CustomClass
), true);
278 public void Register_CustomClass_Height_CustomCanvasType ()
280 CustomClass_Height_CustomCanvasType
= new DependencyPropertyInfo ("Height", typeof (CustomClass
), typeof (CustomCanvasType
), true);
283 #region CustomCanvasType Height
285 public void Register_CustomCanvasType_Height_int ()
287 CustomCanvasType the_object
= new CustomCanvasType ();
288 CustomCanvasType custom_canvas
= new CustomCanvasType ();
289 Canvas canvas
= new Canvas ();
290 DependencyProperty property
;
291 DependencyPropertyInfo info
;
292 DependencyPropertyInfo
.ChangedInfo changed_info
;
293 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
295 object previous_expected_value
= (int) 0;
299 CustomCanvasType_Height_int
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (int), true);
300 info
= CustomCanvasType_Height_int
;
302 property
= info
.Property
;
304 Assert
.AreEqual (0, (int) the_object
.GetValue (property
));
305 Assert
.AreEqual (0, (int) ink
.GetValue (property
));
307 Assert
.Throws (delegate { the_object.SetValue (property, 1.1); }
, typeof (ArgumentException
));
308 Assert
.Throws (delegate { the_object.SetValue (property, "1"); }
, typeof (ArgumentException
));
309 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
310 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
311 Assert
.Throws (delegate { the_object.SetValue (property, null); }
, typeof (ArgumentException
));
312 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
314 foreach (object expected_value
in new object [] { 1, 1, 2 }
) {
317 the_object
.SetValue (property
, expected_value
);
318 actual_value
= the_object
.GetValue (property
);
320 if ((int) expected_value
!= (int) previous_expected_value
) {
322 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
323 Assert
.AreEqual ((int) changed_info
.args
.OldValue
, (int) previous_expected_value
);
324 Assert
.AreEqual ((int) changed_info
.args
.NewValue
, (int) expected_value
);
325 Assert
.AreSame (changed_info
.obj
, the_object
);
328 previous_expected_value
= expected_value
;
330 Assert
.AreEqual ((int) expected_value
, (int) actual_value
, "Iteration #{0}", iterations
);
331 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
336 public void Register_CustomCanvasType_Height_double ()
338 CustomCanvasType the_object
= new CustomCanvasType ();
339 CustomCanvasType custom_canvas
= new CustomCanvasType ();
340 Canvas canvas
= new Canvas ();
341 DependencyProperty property
;
342 DependencyPropertyInfo info
;
343 DependencyPropertyInfo
.ChangedInfo changed_info
;
344 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
346 object previous_expected_value
= (double) 0;
350 CustomCanvasType_Height_double
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (double), true);
351 info
= CustomCanvasType_Height_double
;
353 property
= info
.Property
;
355 Assert
.AreEqual (0.0, (double) the_object
.GetValue (property
));
356 Assert
.AreEqual (0.0, (double) ink
.GetValue (property
));
358 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
359 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
360 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
361 Assert
.Throws (delegate { the_object.SetValue (property, null); }
, typeof (ArgumentException
));
362 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
364 foreach (object expected_value
in new object [] { 1.1, 1.1, 2.2 }
) {
367 the_object
.SetValue (property
, expected_value
);
368 actual_value
= the_object
.GetValue (property
);
370 if ((double) expected_value
!= (double) previous_expected_value
) {
372 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
373 Assert
.AreEqual ((double) changed_info
.args
.OldValue
, (double) previous_expected_value
);
374 Assert
.AreEqual ((double) changed_info
.args
.NewValue
, (double) expected_value
);
375 Assert
.AreSame (changed_info
.obj
, the_object
);
378 previous_expected_value
= expected_value
;
380 Assert
.AreEqual ((double) expected_value
, (double) actual_value
, "Iteration #{0}", iterations
);
381 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
386 public void Register_CustomCanvasType_Height_void ()
388 Assert
.Throws (delegate { CustomCanvasType_Height_void = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (void), true); }
, typeof (NotSupportedException
));
392 public void Register_CustomCanvasType_Height_Canvas ()
394 CustomCanvasType_Height_Canvas
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (Canvas
), true);
398 public void Register_CustomCanvasType_Height_CustomClass ()
400 CustomCanvasType_Height_CustomClass
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomClass
), true);
404 public void Register_CustomCanvasType_Height_CustomCanvasType ()
406 CustomCanvasType_Height_CustomCanvasType
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomCanvasType
), true);
410 public void Register_CustomCanvasType_Height_CustomInterface ()
412 CustomCanvasType the_object
= new CustomCanvasType ();
413 CustomCanvasType custom_canvas
= new CustomCanvasType ();
414 Canvas canvas
= new Canvas ();
415 CustomStruct custom_struct_1
= new CustomStruct (1);
416 CustomEnum custom_enum
= CustomEnum
.EnumValue1
;
417 CustomDelegate custom_delegate
= delegate { }
;
418 CustomInterface custom_interface_a
= new CustomInterfaceImplA ();
419 CustomInterface custom_interface_b
= new CustomInterfaceImplB ();
420 DependencyProperty property
;
421 DependencyPropertyInfo info
;
422 DependencyPropertyInfo
.ChangedInfo changed_info
;
423 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
425 object previous_expected_value
= null;
429 CustomCanvasType_Height_CustomInterface
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomInterface
), true);
430 info
= CustomCanvasType_Height_CustomInterface
;
432 property
= info
.Property
;
434 Assert
.AreEqual (null, the_object
.GetValue (property
), "Default value 1");
435 Assert
.AreEqual (null, ink
.GetValue (property
), "Default value 2");
437 Assert
.Throws (delegate { the_object.SetValue (property, 0); }
, typeof (ArgumentException
));
438 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
439 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
440 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
441 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
442 Assert
.Throws (delegate { the_object.SetValue (property, custom_enum); }
, typeof (ArgumentException
));
444 foreach (object expected_value
in new object [] { null, custom_interface_a, null, custom_interface_b, custom_interface_b, null }
) {
447 the_object
.SetValue (property
, expected_value
);
448 actual_value
= the_object
.GetValue (property
);
450 if (!object.Equals (expected_value
, previous_expected_value
)) {
452 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
453 Assert
.AreEqual (changed_info
.args
.OldValue
, previous_expected_value
, "OldValue");
454 Assert
.AreEqual (changed_info
.args
.NewValue
, expected_value
, "NewValue");
455 Assert
.AreSame (changed_info
.obj
, the_object
);
458 previous_expected_value
= expected_value
;
460 Assert
.AreEqual (expected_value
, actual_value
, "Iteration #{0}", iterations
);
461 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
466 public void Register_CustomCanvasType_Height_CustomStruct ()
468 CustomCanvasType the_object
= new CustomCanvasType ();
469 CustomCanvasType custom_canvas
= new CustomCanvasType ();
470 Canvas canvas
= new Canvas ();
471 CustomStruct custom_struct_1
= new CustomStruct (1);
472 DependencyProperty property
;
473 DependencyPropertyInfo info
;
474 DependencyPropertyInfo
.ChangedInfo changed_info
;
475 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
477 object previous_expected_value
= new CustomStruct ();
481 CustomCanvasType_Height_CustomStruct
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomStruct
), true);
482 info
= CustomCanvasType_Height_CustomStruct
;
484 property
= info
.Property
;
486 Assert
.AreEqual (new CustomStruct (), (CustomStruct
) the_object
.GetValue (property
));
487 Assert
.AreEqual (new CustomStruct (), (CustomStruct
) ink
.GetValue (property
));
489 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
490 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
491 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
492 Assert
.Throws (delegate { the_object.SetValue (property, null); }
, typeof (ArgumentException
));
493 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
495 foreach (object expected_value
in new object [] { custom_struct_1, custom_struct_1, new CustomStruct (), new CustomStruct () }
) {
498 the_object
.SetValue (property
, expected_value
);
499 actual_value
= the_object
.GetValue (property
);
501 if (!object.Equals (expected_value
, previous_expected_value
)) {
503 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
504 Assert
.AreEqual (changed_info
.args
.OldValue
, previous_expected_value
);
505 Assert
.AreEqual (changed_info
.args
.NewValue
, expected_value
);
506 Assert
.AreSame (changed_info
.obj
, the_object
);
509 previous_expected_value
= expected_value
;
511 Assert
.AreEqual (expected_value
, actual_value
, "Iteration #{0}", iterations
);
512 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
517 public void Register_CustomCanvasType_Height_CustomEnum ()
519 CustomCanvasType the_object
= new CustomCanvasType ();
520 CustomCanvasType custom_canvas
= new CustomCanvasType ();
521 Canvas canvas
= new Canvas ();
522 CustomStruct custom_struct_1
= new CustomStruct (1);
523 CustomEnum custom_enum
= CustomEnum
.EnumValue1
;
524 DependencyProperty property
;
525 DependencyPropertyInfo info
;
526 DependencyPropertyInfo
.ChangedInfo changed_info
;
527 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
529 object previous_expected_value
= (CustomEnum
) 0;
533 CustomCanvasType_Height_CustomEnum
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomEnum
), true);
534 info
= CustomCanvasType_Height_CustomEnum
;
536 property
= info
.Property
;
538 Assert
.AreEqual ((CustomEnum
) 0, the_object
.GetValue (property
), "Default value 1");
539 Assert
.AreEqual ((CustomEnum
) 0, ink
.GetValue (property
), "Default value 2");
541 Assert
.Throws (delegate { the_object.SetValue (property, 0); }
, typeof (ArgumentException
));
542 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
543 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
544 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
545 Assert
.Throws (delegate { the_object.SetValue (property, null); }
, typeof (ArgumentException
));
546 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
548 foreach (object expected_value
in new object [] { CustomEnum.EnumValue1, CustomEnum.EnumValue1, CustomEnum.EnumValue2, (CustomEnum) 0, custom_enum, custom_enum }
) {
551 the_object
.SetValue (property
, expected_value
);
552 actual_value
= the_object
.GetValue (property
);
554 if (!object.Equals (expected_value
, previous_expected_value
)) {
556 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
557 Assert
.AreEqual (changed_info
.args
.OldValue
, previous_expected_value
, "OldValue");
558 Assert
.AreEqual (changed_info
.args
.NewValue
, expected_value
, "NewValue");
559 Assert
.AreSame (changed_info
.obj
, the_object
);
562 previous_expected_value
= expected_value
;
564 Assert
.AreEqual (expected_value
, actual_value
, "Iteration #{0}", iterations
);
565 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
570 public void Register_CustomCanvasType_Height_CustomDelegate ()
572 CustomCanvasType the_object
= new CustomCanvasType ();
573 CustomCanvasType custom_canvas
= new CustomCanvasType ();
574 Canvas canvas
= new Canvas ();
575 CustomStruct custom_struct_1
= new CustomStruct (1);
576 CustomEnum custom_enum
= CustomEnum
.EnumValue1
;
577 CustomDelegate custom_delegate
= delegate { }
;
578 DependencyProperty property
;
579 DependencyPropertyInfo info
;
580 DependencyPropertyInfo
.ChangedInfo changed_info
;
581 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
583 object previous_expected_value
= null;
587 CustomCanvasType_Height_CustomDelegate
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomDelegate
), true);
588 info
= CustomCanvasType_Height_CustomDelegate
;
590 property
= info
.Property
;
592 Assert
.AreEqual (null, the_object
.GetValue (property
), "Default value 1");
593 Assert
.AreEqual (null, ink
.GetValue (property
), "Default value 2");
595 Assert
.Throws (delegate { the_object.SetValue (property, 0); }
, typeof (ArgumentException
));
596 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
597 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
598 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
599 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
601 foreach (object expected_value
in new CustomDelegate
[] { null, delegate { }
, delegate { }
, custom_delegate
, custom_delegate
}) {
604 the_object
.SetValue (property
, expected_value
);
605 actual_value
= the_object
.GetValue (property
);
607 if (!object.Equals (expected_value
, previous_expected_value
)) {
609 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
610 Assert
.AreEqual (changed_info
.args
.OldValue
, previous_expected_value
, "OldValue");
611 Assert
.AreEqual (changed_info
.args
.NewValue
, expected_value
, "NewValue");
612 Assert
.AreSame (changed_info
.obj
, the_object
);
615 previous_expected_value
= expected_value
;
617 Assert
.AreEqual (expected_value
, actual_value
, "Iteration #{0}", iterations
);
618 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
623 public void Register_CustomCanvasType_Height_CustomClassCtorA ()
625 CustomCanvasType_Height_CustomClassCtorA
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomClassCtorA
), true);
629 public void Register_CustomCanvasType_Height_CustomClassCtorB ()
631 CustomCanvasType_Height_CustomClassCtorB
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType
), typeof (CustomClassCtorB
), true);
634 ///////////////////////////////////////////////////////
637 #region CustomCanvasType2 Height
640 public void Register_CustomCanvasType2_Height_double ()
642 CustomCanvasType2 the_object
= new CustomCanvasType2 ();
643 CustomCanvasType custom_canvas
= new CustomCanvasType ();
644 Canvas canvas
= new Canvas ();
645 DependencyProperty property
;
646 DependencyPropertyInfo info
;
647 DependencyPropertyInfo
.ChangedInfo changed_info
;
648 InkPresenter ink
= new InkPresenter (); // The only builtin type derived from Canvas
650 object previous_expected_value
= (double) 0;
654 CustomCanvasType2_Height_double
= new DependencyPropertyInfo ("Height", typeof (CustomCanvasType2
), typeof (double), true);
655 info
= CustomCanvasType2_Height_double
;
657 property
= info
.Property
;
659 Assert
.AreEqual (0.0, (double) the_object
.GetValue (property
));
660 Assert
.AreEqual (0.0, (double) ink
.GetValue (property
));
661 Assert
.AreEqual (0.0, (double) custom_canvas
.GetValue (property
));
663 Assert
.Throws (delegate { the_object.SetValue (property, 1); }
, typeof (ArgumentException
));
664 Assert
.Throws (delegate { the_object.SetValue (property, ""); }
, typeof (ArgumentException
));
665 Assert
.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }
, typeof (ArgumentException
));
666 Assert
.Throws (delegate { the_object.SetValue (property, null); }
, typeof (ArgumentException
));
667 Assert
.Throws (delegate { the_object.SetValue (property, new Canvas ()); }
, typeof (ArgumentException
));
669 //Assert.Throws (delegate { custom_canvas.SetValue (property, 1.1); }, typeof (ArgumentException));
671 foreach (object expected_value
in new object [] { 1.1 }
) {
674 the_object
.SetValue (property
, expected_value
);
675 actual_value
= the_object
.GetValue (property
);
677 if ((double) expected_value
!= (double) previous_expected_value
) {
679 changed_info
= info
.Changes
[info
.Changes
.Count
- 1];
680 Assert
.AreEqual ((double) changed_info
.args
.OldValue
, (double) previous_expected_value
);
681 Assert
.AreEqual ((double) changed_info
.args
.NewValue
, (double) expected_value
);
682 Assert
.AreSame (changed_info
.obj
, the_object
);
685 previous_expected_value
= expected_value
;
687 Assert
.AreEqual ((double) expected_value
, (double) actual_value
, "Iteration #{0}", iterations
);
688 Assert
.AreEqual (changes
, info
.Changes
.Count
, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations
, changes
, info
.Changes
.Count
);
692 #region FrameworkElement Height
694 public void Register_FrameworkElement_Height_int ()
696 FrameworkElement_Height_int
= new DependencyPropertyInfo ("Height", typeof (FrameworkElement
), typeof (int), true);
700 public void Register_FrameworkElement_Height_double ()
702 FrameworkElement_Height_double
= new DependencyPropertyInfo ("Height", typeof (FrameworkElement
), typeof (double), true);
706 public void Register_FrameworkElement_Height_CustomClass ()
708 FrameworkElement_Height_CustomClass
= new DependencyPropertyInfo ("Height", typeof (FrameworkElement
), typeof (CustomClass
), true);
712 #region Custom types, etc
713 public class CustomCanvasType
: Canvas
716 public class CustomCanvasType2
: Canvas
719 public class CustomDerivedClass
: CustomClass
723 public class CustomClass
726 public struct CustomStruct
730 public CustomStruct (int v
) { this.value = v; }
732 public override string ToString ()
734 return "<CustomStruct (" + value.ToString () + ")>";
737 public interface CustomInterface
741 public class CustomInterfaceImplA
: CustomInterface
743 public void Method ()
745 throw new NotImplementedException ();
748 public class CustomInterfaceImplB
: CustomInterface
750 public void Method ()
752 throw new NotImplementedException ();
756 public delegate void CustomDelegate ();
757 public enum CustomEnum
762 // A class with no default ctor
763 public class CustomClassCtorA
765 public CustomClassCtorA (string an_argument
) { }
767 // A class with a private default ctor
768 public class CustomClassCtorB
770 private CustomClassCtorB () { }