source: trunk/TestCase/SimpleTestCase/InterfaceTest.ab@ 397

Last change on this file since 397 was 397, checked in by dai, 16 years ago

Foreachステートメントの区切り文字として、カンマを廃止し、Inを採用した。
ジェネリクスインターフェイス実装時のオーバーロード解決ロジックを改良。(型パラメータを戻り値またはパラメータに持つメソッドのオーバーロードをミスしてしまうバグを修正)

File size: 3.8 KB
Line 
1Namespace InterfaceTest
2
3Interface ITest1
4 Function Proc1() As String
5 Function Proc2( value As String ) As Boolean
6End Interface
7
8Interface ITest2
9 Function Proc5() As String
10 Function Proc6( value As String ) As Boolean
11End Interface
12
13Interface IGenericTest<T>
14 Function GenericProc1() As T
15 Function GenericProc2( value As T ) As Boolean
16End Interface
17
18Class Test1
19 Implements ITest1
20
21 a As Long
22
23Public
24 Sub Test1( initValue As Long )
25 a = initValue
26 End Sub
27
28 Override Function Proc1() As String
29 Return "Proc1 result" + a.ToString()
30 End Function
31
32 Override Function Proc2( value As String ) As Boolean
33 Return ( value = ( "Proc2 calling" + a.ToString() ) )
34 End Function
35End Class
36
37Class Test2
38 Implements ITest1, ITest2, IGenericTest<String>
39
40 a As Long
41
42Public
43 Sub Test2( initValue As Long )
44 a = initValue
45 End Sub
46
47 Override Function Proc1() As String
48 Return "Proc1 result" + a.ToString()
49 End Function
50
51 Override Function Proc2( value As String ) As Boolean
52 Return ( value = ( "Proc2 calling" + a.ToString() ) )
53 End Function
54
55 Override Function Proc5() As String
56 Return "Proc5 result" + a.ToString()
57 End Function
58
59 Override Function Proc6( value As String ) As Boolean
60 Return ( value = ( "Proc6 calling" + a.ToString() ) )
61 End Function
62
63 Function GenericProc1() As String
64 Return "GenericProc1 is ok"
65 End Function
66
67 Function GenericProc2( value As String ) As Boolean
68 Return ( value = "GenericProc2 calling" )
69 End Function
70End Class
71
72Sub GlobalProc1( itest1 As ITest1, n As Long )
73 UnitTest( "Interface ... GlobalProc1-1 " + n.ToString(), itest1.Proc1() = "Proc1 result123" )
74 UnitTest( "Interface ... GlobalProc1-2 " + n.ToString(), itest1.Proc2( "Proc2 calling123" ) )
75End Sub
76
77Sub GlobalProc2( itest1 As ITest1, itest2 As ITest2, n As Long )
78 If ObjPtr( itest1 ) <> NULL Then
79 UnitTest( "Interface ... GlobalProc2-1 " + n.ToString(), itest1.Proc1() = "Proc1 result123" )
80 UnitTest( "Interface ... GlobalProc2-2 " + n.ToString(), itest1.Proc2( "Proc2 calling123" ) )
81 End If
82
83 UnitTest( "Interface ... GlobalProc2-3 " + n.ToString(), itest2.Proc5() = "Proc5 result123" )
84 UnitTest( "Interface ... GlobalProc2-4 " + n.ToString(), itest2.Proc6( "Proc6 calling123" ) )
85End Sub
86
87Sub TestMain()
88 Dim test1 = New Test1( 123 )
89 UnitTest( "Interface ... calling class1 method 1", test1.Proc1() = "Proc1 result123" )
90 UnitTest( "Interface ... calling class1 method 2", test1.Proc2( "Proc2 calling123" ) )
91
92 Dim itest1 = test1 As ITest1
93 UnitTest( "Interface ... calling class1 interface 1", itest1.Proc1() = "Proc1 result123" )
94 UnitTest( "Interface ... calling class1 interface 2", itest1.Proc2( "Proc2 calling123" ) )
95
96 GlobalProc1( test1, 1 )
97 GlobalProc1( itest1, 2 )
98
99 Dim test2 = New Test2( 123 )
100 UnitTest( "Interface ... calling class2 method 1", test2.Proc1() = "Proc1 result123" )
101 UnitTest( "Interface ... calling class2 method 2", test2.Proc2( "Proc2 calling123" ) )
102 UnitTest( "Interface ... calling class2 method 1", test2.Proc5() = "Proc5 result123" )
103 UnitTest( "Interface ... calling class2 method 2", test2.Proc6( "Proc6 calling123" ) )
104
105 Dim itest2 = test2 As ITest2
106 UnitTest( "Interface ... calling class2 interface 1", itest2.Proc5() = "Proc5 result123" )
107 UnitTest( "Interface ... calling class2 interface 2", itest2.Proc6( "Proc6 calling123" ) )
108
109 GlobalProc2( test2, test2, 1 )
110 GlobalProc2( Nothing, itest2, 2 )
111
112 Dim iGenericTest As IGenericTest<String>
113 iGenericTest = test2 As IGenericTest<String>
114 UnitTest( "Interface ... calling class2 interface 3", iGenericTest.GenericProc1() = "GenericProc1 is ok" )
115
116 UnitTest( "Interface ... calling class2 interface 4", iGenericTest.GenericProc2( "GenericProc2 calling" ) )
117End Sub
118
119End Namespace
120
121InterfaceTest.TestMain()
Note: See TracBrowser for help on using the repository browser.