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

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

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

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