📄 latebindingtests.vb
字号:
'' LateBindingTests.vb'' Author:' Boris Kirzner (borisk@mainsoft.com)''' Copyright (C) 2002-2006 Mainsoft Corporation.' Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)'' Permission is hereby granted, free of charge, to any person obtaining' a copy of this software and associated documentation files (the' "Software"), to deal in the Software without restriction, including' without limitation the rights to use, copy, modify, merge, publish,' distribute, sublicense, and/or sell copies of the Software, and to' permit persons to whom the Software is furnished to do so, subject to' the following conditions:' ' The above copyright notice and this permission notice shall be' included in all copies or substantial portions of the Software.' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Imports SystemImports System.ReflectionImports NUnit.Framework#If mono_not_yet Then<TestFixture()> _Public Class LateBindingTests Dim bo As Boolean = True Dim b As Byte = 1 Dim s As Short = 1 Dim i As Integer = 1 Dim l As Long = 1 Dim c As Char = "a"c Dim d As Double = 1.0 Dim si As Single = 1.0#If NET_2_0 Then Dim sb As SByte = 1 Dim us As UShort = 1 Dim ui As UInteger = 1 Dim ul As ULong = 1#End If <Test()> _ Public Sub A_ShouldFailWithMono() ' FIXME: used to determine the environment the tests run in. Should be removed. Microsoft.VisualBasic.CompilerServices.ProjectData.ClearProjectError() End Sub Private Class C1 Public Function F(ByVal s As Byte) As String Return "Byte" End Function Public Function F(ByVal s As Short) As String Return "Short" End Function Public Function F(ByVal s As Integer) As String Return "Integer" End Function Public Function F(ByVal s As Long) As String Return "Long" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_1() Dim o As Object = New C1 Assert.AreEqual("Byte", o.F(b)) Assert.AreEqual("Short", o.F(s)) Assert.AreEqual("Integer", o.F(i)) Assert.AreEqual("Long", o.F(l)) End Sub Private Class C2 Public Function F(ByVal s As Short) As String Return "Short" End Function Public Function F(ByVal s As Long) As String Return "Long" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_11() Dim o As Object = New C2 Assert.AreEqual("Short", o.F(b)) Assert.AreEqual("Short", o.F(s)) Assert.AreEqual("Long", o.F(i)) Assert.AreEqual("Long", o.F(l)) End Sub Private Class C3 Public Function F(ByVal s As Byte) As String Return "Byte" End Function Public Function F(ByVal s As Integer) As String Return "Integer" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_12() Dim o As Object = New C3 Assert.AreEqual("Byte", o.F(b)) Assert.AreEqual("Integer", o.F(s)) Assert.AreEqual("Integer", o.F(i)) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_2() Dim o As Object = New C3 o.F(l) End Sub Private Class C4 Public Function F(ByVal s1 As Byte, ByVal s2 As Byte) As String Return "Byte,Byte" End Function Public Function F(ByVal s1 As Short, ByVal s2 As Short) As String Return "Short,Short" End Function Public Function F(ByVal s1 As Integer, ByVal s2 As Integer) As String Return "Integer,Integer" End Function Public Function F(ByVal s1 As Long, ByVal s2 As Long) As String Return "Long,Long" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_21() Dim o As Object = New C4 Assert.AreEqual("Byte,Byte", o.F(b, b)) Assert.AreEqual("Short,Short", o.F(s, s)) Assert.AreEqual("Integer,Integer", o.F(i, i)) Assert.AreEqual("Long,Long", o.F(l, l)) End Sub <Test()> _ Public Sub LateBind_PrimitiveTypes_22() Dim o As Object = New C4 Assert.AreEqual("Short,Short", o.F(b, s)) Assert.AreEqual("Short,Short", o.F(s, b)) Assert.AreEqual("Integer,Integer", o.F(b, i)) Assert.AreEqual("Integer,Integer", o.F(i, b)) Assert.AreEqual("Integer,Integer", o.F(i, s)) Assert.AreEqual("Integer,Integer", o.F(s, i)) Assert.AreEqual("Long,Long", o.F(b, l)) Assert.AreEqual("Long,Long", o.F(l, b)) Assert.AreEqual("Long,Long", o.F(s, l)) Assert.AreEqual("Long,Long", o.F(l, s)) Assert.AreEqual("Long,Long", o.F(i, l)) Assert.AreEqual("Long,Long", o.F(l, i)) End Sub Private Class C5 Public Function F(ByVal s1 As Short, ByVal s2 As Short) As String Return "Short,Short" End Function Public Function F(ByVal s1 As Long, ByVal s2 As Long) As String Return "Long,Long" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_3() Dim o As Object = New C5 Assert.AreEqual("Short,Short", o.F(b, s)) Assert.AreEqual("Short,Short", o.F(s, b)) Assert.AreEqual("Long,Long", o.F(b, i)) Assert.AreEqual("Long,Long", o.F(i, b)) Assert.AreEqual("Long,Long", o.F(i, s)) Assert.AreEqual("Long,Long", o.F(s, i)) Assert.AreEqual("Long,Long", o.F(b, l)) Assert.AreEqual("Long,Long", o.F(l, b)) Assert.AreEqual("Long,Long", o.F(s, l)) Assert.AreEqual("Long,Long", o.F(l, s)) Assert.AreEqual("Long,Long", o.F(i, l)) Assert.AreEqual("Long,Long", o.F(l, i)) End Sub Private Class C6 Public Function F(ByVal s1 As Byte, ByVal s2 As Byte) As String Return "Byte,Byte" End Function Public Function F(ByVal s1 As Integer, ByVal s2 As Integer) As String Return "Integer,Integer" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_31() Dim o As Object = New C6 Assert.AreEqual("Integer,Integer", o.F(b, s)) Assert.AreEqual("Integer,Integer", o.F(s, b)) Assert.AreEqual("Integer,Integer", o.F(b, i)) Assert.AreEqual("Integer,Integer", o.F(i, b)) Assert.AreEqual("Integer,Integer", o.F(i, s)) Assert.AreEqual("Integer,Integer", o.F(s, i)) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_4() Dim o As Object = New C6 o.F(b, l) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_5() Dim o As Object = New C6 o.F(l, b) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_6() Dim o As Object = New C6 o.F(s, l) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_7() Dim o As Object = New C6 o.F(l, s) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_8() Dim o As Object = New C6 o.F(i, l) End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_9() Dim o As Object = New C6 o.F(l, i) End Sub Private Class C100 Public Function F(ByVal s As Boolean) As String Return "Boolean" End Function Public Function F(ByVal s As Byte) As String Return "Byte" End Function Public Function F(ByVal s As Short) As String Return "Short" End Function#If NET_2_0 Then Public Function F(ByVal s As SByte) As String Return "SByte" End Function Public Function F(ByVal s As UShort) As String Return "UShort" End Function Public Function F(ByVal s As UInteger) As String Return "UInteger" End Function Public Function F(ByVal s As ULong) As String Return "ULong" End Function#End If Public Function F(ByVal s As Integer) As String Return "Integer" End Function Public Function F(ByVal s As Long) As String Return "Long" End Function Public Function F(ByVal s As Char) As String Return "Char" End Function Public Function F(ByVal s As Double) As String Return "Double" End Function Public Function F(ByVal s As Single) As String Return "Single" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_100() Dim o As Object = New C100 Assert.AreEqual("Boolean", o.F(bo)) Assert.AreEqual("Byte", o.F(b)) Assert.AreEqual("Short", o.F(s)) Assert.AreEqual("Integer", o.F(i)) Assert.AreEqual("Long", o.F(l)) Assert.AreEqual("Char", o.F(c)) Assert.AreEqual("Double", o.F(d)) Assert.AreEqual("Single", o.F(si))#If NET_2_0 Then Assert.AreEqual("SByte", o.F(sb)) Assert.AreEqual("UShort", o.F(us)) Assert.AreEqual("UInteger", o.F(ui)) Assert.AreEqual("ULong", o.F(ul))#End If End Sub Private Class C200 'Public Function F(ByVal s As Boolean) As String ' Return "Boolean" 'End Function Public Function F(ByVal s As Byte) As String Return "Byte" End Function Public Function F(ByVal s As Short) As String Return "Short" End Function#If NET_2_0 Then Public Function F(ByVal s As SByte) As String Return "SByte" End Function Public Function F(ByVal s As UShort) As String Return "UShort" End Function Public Function F(ByVal s As UInteger) As String Return "UInteger" End Function Public Function F(ByVal s As ULong) As String Return "ULong" End Function#End If Public Function F(ByVal s As Integer) As String Return "Integer" End Function Public Function F(ByVal s As Long) As String Return "Long" End Function Public Function F(ByVal s As Char) As String Return "Char" End Function Public Function F(ByVal s As Double) As String Return "Double" End Function Public Function F(ByVal s As Single) As String Return "Single" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_200() Dim o As Object = New C200 'Assert.AreEqual("Boolean", o.F(bo)) Assert.AreEqual("Byte", o.F(b)) Assert.AreEqual("Short", o.F(s)) Assert.AreEqual("Integer", o.F(i)) Assert.AreEqual("Long", o.F(l)) Assert.AreEqual("Char", o.F(c)) Assert.AreEqual("Double", o.F(d)) Assert.AreEqual("Single", o.F(si))#If NET_2_0 Then Assert.AreEqual("SByte", o.F(sb)) Assert.AreEqual("UShort", o.F(us)) Assert.AreEqual("UInteger", o.F(ui)) Assert.AreEqual("ULong", o.F(ul))#End If End Sub <Test(), ExpectedException(GetType(AmbiguousMatchException))> _ Public Sub LateBind_PrimitiveTypes_201() Dim o As Object = New C200 o.F(bo) End Sub Private Class C210 Public Function F(ByVal s As Boolean) As String Return "Boolean" End Function 'Public Function F(ByVal s As Byte) As String ' Return "Byte" 'End Function Public Function F(ByVal s As Short) As String Return "Short" End Function#If NET_2_0 Then Public Function F(ByVal s As SByte) As String Return "SByte" End Function Public Function F(ByVal s As UShort) As String Return "UShort" End Function Public Function F(ByVal s As UInteger) As String Return "UInteger" End Function Public Function F(ByVal s As ULong) As String Return "ULong" End Function#End If Public Function F(ByVal s As Integer) As String Return "Integer" End Function Public Function F(ByVal s As Long) As String Return "Long" End Function Public Function F(ByVal s As Char) As String Return "Char" End Function Public Function F(ByVal s As Double) As String Return "Double" End Function Public Function F(ByVal s As Single) As String Return "Single" End Function End Class <Test()> _ Public Sub LateBind_PrimitiveTypes_210() Dim o As Object = New C210
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -