1 // MulticastDelegate.cs - NUnit Test Cases for MulticastDelegates (C# delegates)
\r
3 // Daniel Stodden (stodden@in.tum.de)
\r
5 // (C) Daniel Stodden
\r
8 // these are the standard namespaces you will need. You may need to add more
\r
9 // depending on your tests.
\r
10 using NUnit.Framework;
\r
13 // all test namespaces start with "MonoTests." Append the Namespace that
\r
14 // contains the class you are testing, e.g. MonoTests.System.Collections
\r
15 namespace MonoTests.System
\r
18 // the class name should end with "Test" and start with the name of the class
\r
19 // you are testing, e.g. CollectionBaseTest
\r
20 public class MulticastDelegateTest : TestCase {
\r
22 public MulticastDelegateTest() {}
\r
24 // this method is run before each Test* method is called. You can put
\r
25 // variable initialization, etc. here that is common to each test.
\r
26 // Just leave the method empty if you don't need to use it.
\r
27 protected override void SetUp() {}
\r
29 // this method is run after each Test* method is called. You can put
\r
30 // clean-up code, etc. here. Whatever needs to be done after each test.
\r
31 // Just leave the method empty if you don't need to use it.
\r
32 protected override void TearDown() {}
\r
34 private delegate char MyDelegate( ref string s );
\r
36 private char MethodA( ref string s )
\r
42 private char MethodB( ref string s )
\r
48 private char MethodC( ref string s )
\r
54 private char MethodD( ref string s )
\r
60 public void TestEquals()
\r
62 MyDelegate dela = new MyDelegate( MethodA );
\r
63 MyDelegate delb = new MyDelegate( MethodB );
\r
64 MyDelegate delc = new MyDelegate( MethodC );
\r
66 AssertEquals( "#A01", false, dela == delb );
\r
68 MyDelegate del1, del2;
\r
72 AssertEquals( "#A02", false, del1 == del2 );
\r
76 AssertEquals( "#A03", true, del1 == del2 );
\r
78 object o = new object ();
\r
80 AssertEquals ("#A04", false, dela.Equals (o));
\r
84 public void TestCombineRemove()
\r
86 MyDelegate dela = new MyDelegate( MethodA );
\r
87 MyDelegate delb = new MyDelegate( MethodB );
\r
88 MyDelegate delc = new MyDelegate( MethodC );
\r
89 MyDelegate deld = new MyDelegate( MethodD );
\r
95 MyDelegate del1, del2;
\r
96 del1 = dela + delb + delb + delc + delb + delb + deld;
\r
98 res = del1( ref val );
\r
99 AssertEquals( "#A01", "abbcbbd", val );
\r
100 AssertEquals( "#A02", 'd', res );
\r
103 del2 = del1 - ( delb + delb );
\r
105 res = del2( ref val );
\r
106 AssertEquals( "#A03", "abbcd", val );
\r
107 AssertEquals( "#A04", 'd', res );
\r
109 // we did not affect del1, did we?
\r
111 res = del1( ref val );
\r
112 AssertEquals( "#A05", "abbcbbd", val );
\r