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

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

・デリゲートの共変戻り値、反変引数に対応した。
・core.libで定義されたデリゲートがアプリケーションプロジェクトで利用できないバグを修正。

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