source: trunk/TestCase/SimpleTestCase/DelegateTest.ab@ 358

Last change on this file since 358 was 356, checked in by dai, 17 years ago

インターフェイス機構の実装が完了。テストケースも用意した。

File size: 2.1 KB
Line 
1Namespace DelegateTest
2
3Delegate Sub Callback1()
4Delegate Function Callback2() As Long
5Delegate Sub Callback3( a As Long )
6Delegate Sub Callback4( a As String )
7Delegate Function Callback7( str As String ) As String
8
9
10Class TestClass
11 proc1Flag As Boolean
12 proc2Flag As Boolean
13 proc3Flag As Boolean
14 proc4Flag As Boolean
15 proc5Flag As Boolean
16 proc6Flag As Boolean
17 proc8Flag As Boolean
18
19 Static staticProc1Flag = False As Boolean
20
21Public
22 Sub TestClass()
23 ClearFlags()
24 End Sub
25
26 Sub ClearFlags()
27 proc1Flag = False
28 proc2Flag = False
29 proc3Flag = False
30 proc4Flag = False
31 proc5Flag = False
32 proc6Flag = False
33 proc8Flag = True
34 End Sub
35 Function CheckFlags() As Boolean
36 Return proc1Flag and proc2Flag and proc3Flag and proc4Flag and proc5Flag and proc6Flag and proc8Flag
37 End Function
38
39 Sub Proc1()
40 proc1Flag = True
41 End Sub
42
43 Function Proc2() As Long
44 proc2Flag = True
45 End Function
46
47 Sub Proc3or4( a As Long )
48 proc3Flag = (a=100)
49 End Sub
50
51 Sub Proc3or4( a As String )
52 proc4Flag = (a="Proc4 calling")
53 End Sub
54
55 Sub Proc5( a As String )
56 proc5Flag = (a="Proc4 calling")
57 End Sub
58
59 Sub Proc6( a As String )
60 proc6Flag = (a="Proc4 calling")
61 End Sub
62
63 Static Function Proc7( str As String ) As String
64 Return "Proc7 result[" + str + "]"
65 End Function
66
67 Sub Proc8( a As String )
68 proc8Flag = False
69 End Sub
70End Class
71
72Sub TestMain()
73 Dim testObj As TestClass
74 Dim dg1 = New Callback1( AddressOf(testObj.Proc1) )
75 Dim dg2 = New Callback2( AddressOf(testObj.Proc2) )
76 Dim dg3 = New Callback3( AddressOf(testObj.Proc3or4) )
77 Dim dg4 = New Callback4( AddressOf(testObj.Proc3or4) )
78 dg4 += AddressOf(testObj.Proc5)
79 dg4 += AddressOf(testObj.Proc6)
80 dg4 += AddressOf(testObj.Proc8)
81 dg4 -= AddressOf(testObj.Proc8)
82
83 dg1()
84 dg2()
85 dg3( 100 )
86 dg4( "Proc4 calling" )
87
88 UnitTest( "Delegate1", testObj.CheckFlags() )
89
90 Dim dg7 = New Callback7( AddressOf(TestClass.Proc7) )
91 UnitTest( "Delegate2", dg7( "test value" ) = "Proc7 result[test value]" )
92
93End Sub
94
95End Namespace
96
97DelegateTest.TestMain()
Note: See TracBrowser for help on using the repository browser.