[356] | 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 |
|
---|
[397] | 13 | Interface IGenericTest<T>
|
---|
| 14 | Function GenericProc1() As T
|
---|
| 15 | Function GenericProc2( value As T ) As Boolean
|
---|
| 16 | End Interface
|
---|
| 17 |
|
---|
[356] | 18 | Class Test1
|
---|
| 19 | Implements ITest1
|
---|
| 20 |
|
---|
| 21 | a As Long
|
---|
| 22 |
|
---|
| 23 | Public
|
---|
| 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
|
---|
| 35 | End Class
|
---|
| 36 |
|
---|
| 37 | Class Test2
|
---|
[397] | 38 | Implements ITest1, ITest2, IGenericTest<String>
|
---|
[356] | 39 |
|
---|
| 40 | a As Long
|
---|
| 41 |
|
---|
| 42 | Public
|
---|
| 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
|
---|
[397] | 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
|
---|
[356] | 70 | End Class
|
---|
| 71 |
|
---|
| 72 | Sub 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" ) )
|
---|
| 75 | End Sub
|
---|
| 76 |
|
---|
| 77 | Sub 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" ) )
|
---|
| 85 | End Sub
|
---|
| 86 |
|
---|
| 87 | Sub 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 )
|
---|
[397] | 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" ) )
|
---|
[356] | 117 | End Sub
|
---|
| 118 |
|
---|
| 119 | End Namespace
|
---|
| 120 |
|
---|
| 121 | InterfaceTest.TestMain()
|
---|