source: trunk/ab5.0/ablib/TestCase/SimpleTestCase/InterfaceTest.ab@ 613

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

#200#201に関するテストケースを追加。

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