1 | Namespace InterfaceTest
|
---|
2 |
|
---|
3 | Interface ITest1
|
---|
4 | Function Proc1() As String
|
---|
5 | Function Proc2( value As String ) As Boolean
|
---|
6 | End Interface
|
---|
7 |
|
---|
8 | Interface ITest2
|
---|
9 | Function Proc5() As String
|
---|
10 | Function Proc6( value As String ) As Boolean
|
---|
11 | End Interface
|
---|
12 |
|
---|
13 | Interface IGenericTestBase<T>
|
---|
14 | Function GenericProc1() As T
|
---|
15 | End Interface
|
---|
16 |
|
---|
17 | Interface IGenericTest<T>
|
---|
18 | Inherits IGenericTestBase
|
---|
19 | Function GenericProc2( value As T ) As Boolean
|
---|
20 | End Interface
|
---|
21 |
|
---|
22 | Class Test1
|
---|
23 | Implements ITest1
|
---|
24 |
|
---|
25 | a As Long
|
---|
26 |
|
---|
27 | Public
|
---|
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
|
---|
39 | End Class
|
---|
40 |
|
---|
41 | Class Test2
|
---|
42 | Implements ITest1, ITest2, IGenericTest<String>
|
---|
43 |
|
---|
44 | a As Long
|
---|
45 |
|
---|
46 | Public
|
---|
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
|
---|
74 | End Class
|
---|
75 |
|
---|
76 | Sub 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" ) )
|
---|
79 | End Sub
|
---|
80 |
|
---|
81 | Sub 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" ) )
|
---|
89 | End Sub
|
---|
90 |
|
---|
91 | Sub 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" ) )
|
---|
121 | End Sub
|
---|
122 |
|
---|
123 | End Namespace
|
---|
124 |
|
---|
125 | InterfaceTest.TestMain()
|
---|