1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
|
'
' LateBindingTests2.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 System
Imports System.Reflection
Imports NUnit.Framework
<TestFixture()> _
Public Class LateBindingTests2
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
Dim ss2 As String = "aa"
Dim ccA As A = New A
Dim ccB As BB = New BB
Dim ccc As CC = New CC
Dim iic As IConvertible = New IC
Dim sb As SByte = 1
Dim us As UShort = 1
Dim ui As UInteger = 1
Dim ul As ULong = 1
Private Class C1
Public Function F(ByVal o As Object) As String
Return "Object"
End Function
End Class
<Test()> _
Public Sub LateBind_Object()
Dim o As Object = New C1
Assert.AreEqual("Object", o.F(bo))
Assert.AreEqual("Object", o.F(b))
Assert.AreEqual("Object", o.F(s))
Assert.AreEqual("Object", o.F(i))
Assert.AreEqual("Object", o.F(l))
Assert.AreEqual("Object", o.F(c))
Assert.AreEqual("Object", o.F(d))
Assert.AreEqual("Object", o.F(si))
Assert.AreEqual("Object", o.F(ccA))
Assert.AreEqual("Object", o.F(ss2))
Assert.AreEqual("Object", o.F(iic))
Assert.AreEqual("Object", o.F(sb))
Assert.AreEqual("Object", o.F(us))
Assert.AreEqual("Object", o.F(ui))
Assert.AreEqual("Object", o.F(ul))
End Sub
Private Class C2
Public Function F(ByVal o As String) As String
Return "String"
End Function
End Class
<Test()> _
Public Sub LateBind_String()
Dim o As Object = New C2
Assert.AreEqual("String", o.F(bo))
Assert.AreEqual("String", o.F(b))
Assert.AreEqual("String", o.F(s))
Assert.AreEqual("String", o.F(i))
Assert.AreEqual("String", o.F(l))
Assert.AreEqual("String", o.F(c))
Assert.AreEqual("String", o.F(d))
Assert.AreEqual("String", o.F(si))
'Assert.AreEqual("String", o.F(ccA))
Assert.AreEqual("String", o.F(ss2))
'Assert.AreEqual("Object", o.F(iic))
Assert.AreEqual("String", o.F(sb))
Assert.AreEqual("String", o.F(us))
Assert.AreEqual("String", o.F(ui))
Assert.AreEqual("String", o.F(ul))
End Sub
<Test(), ExpectedException(GetType(InvalidCastException))> _
Public Sub LateBind_String2()
Dim o As Object = New C2
o.F(ccA)
End Sub
<Test(), ExpectedException(GetType(InvalidCastException))> _
Public Sub LateBind_String3()
Dim o As Object = New C2
o.F(iic)
End Sub
Private Class C100
Public Function F(ByVal o As Object) As String
Return "Object"
End Function
Public Function F(ByVal o As String) As String
Return "String"
End Function
End Class
<Test()> _
Public Sub LateBind_StringObject()
Dim o As Object = New C100
Dim ccA As A = New A
Assert.AreEqual("Object", o.F(bo))
Assert.AreEqual("Object", o.F(b))
Assert.AreEqual("Object", o.F(s))
Assert.AreEqual("Object", o.F(i))
Assert.AreEqual("Object", o.F(l))
Assert.AreEqual("String", o.F(c))
Assert.AreEqual("Object", o.F(d))
Assert.AreEqual("Object", o.F(si))
Assert.AreEqual("Object", o.F(ccA))
Assert.AreEqual("String", o.F(ss2))
Assert.AreEqual("Object", o.F(iic))
Assert.AreEqual("Object", o.F(sb))
Assert.AreEqual("Object", o.F(us))
Assert.AreEqual("Object", o.F(ui))
Assert.AreEqual("Object", o.F(ul))
End Sub
Private Class C4
Public Function F(ByVal ParamArray args() As A) As String
Return "ParamArray A()"
End Function
Public Function F(ByVal a As A, ByVal ParamArray args() As A) As String
Return "A,ParamArray A()"
End Function
End Class
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_Complex_ParamArray1()
Dim o As Object = New C4
o.F(ccA)
End Sub
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_Complex_ParamArray2()
Dim o As Object = New C4
o.F(ccA, ccA)
End Sub
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_Complex_ParamArray6()
Dim o As Object = New C4
o.F(ccA, ccA, ccA, ccA, ccA, ccA)
End Sub
Private Class C5
Public Function F(ByVal ParamArray args() As A) As String
Return "ParamArray A()"
End Function
Public Function F(ByVal a As A) As String
Return "A"
End Function
Public Function F(ByVal a1 As A, ByVal a2 As A) As String
Return "A,A"
End Function
Public Function F(ByVal a1 As A, ByVal a2 As A, ByVal a3 As A, ByVal a4 As A) As String
Return "A,A,A,A"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray10()
Dim o As Object = New C5
Assert.AreEqual("A", o.F(ccA))
Assert.AreEqual("A,A", o.F(ccA, ccA))
Assert.AreEqual("ParamArray A()", o.F(ccA, ccA, ccA))
Assert.AreEqual("A,A,A,A", o.F(ccA, ccA, ccA, ccA))
Assert.AreEqual("ParamArray A()", o.F(ccA, ccA, ccA, ccA, ccA))
End Sub
<Test()> _
Public Sub LateBind_Complex_ParamArray11()
Dim o As Object = New C5
Assert.AreEqual("A", o.F(ccB))
Assert.AreEqual("A,A", o.F(ccB, ccB))
Assert.AreEqual("ParamArray A()", o.F(ccB, ccB, ccB))
Assert.AreEqual("A,A,A,A", o.F(ccB, ccB, ccB, ccB))
Assert.AreEqual("ParamArray A()", o.F(ccB, ccB, ccB, ccB, ccB))
End Sub
Private Class C6
Public Function F(ByVal ParamArray args() As A) As String
Return "ParamArray A()"
End Function
Public Function F(ByVal a1 As A, ByVal a2 As A, ByVal a As A) As String
Return "A,A,A"
End Function
Public Function F(ByVal ParamArray args() As BB) As String
Return "ParamArray BB()"
End Function
Public Function F(ByVal a1 As BB, ByVal a2 As BB, ByVal a As BB) As String
Return "BB,BB,BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray12()
Dim o As Object = New C6
Assert.AreEqual("ParamArray A()", o.F(ccA))
Assert.AreEqual("A,A,A", o.F(ccA, ccA, ccA))
Assert.AreEqual("ParamArray A()", o.F(ccA, ccA, ccA, ccA, ccA))
Assert.AreEqual("ParamArray BB()", o.F(ccB))
Assert.AreEqual("BB,BB,BB", o.F(ccB, ccB, ccB))
Assert.AreEqual("ParamArray BB()", o.F(ccB, ccB, ccB, ccB, ccB))
Assert.AreEqual("A,A,A", o.F(ccB, ccA, ccA))
Assert.AreEqual("ParamArray A()", o.F(ccB, ccA, ccB, ccA, ccB))
End Sub
Private Class C7
Public Function F(ByVal b As Byte) As String
Return "Byte"
End Function
Public Function F(ByVal b As String) As String
Return "String"
End Function
Public Function F(ByVal o As Object) As String
Return "Object"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_IConvertible1()
Dim o As Object = New C7
Assert.AreEqual("Object", o.F(iic))
End Sub
Private Class C8
Public Function F(ByVal b As Byte) As String
Return "Byte"
End Function
Public Function F(ByVal b As String) As String
Return "String"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_IConvertible2()
Dim o As Object = New C8
o.F(iic)
End Sub
Private Class C9
Public Function F(ByVal b As Integer, ByVal s As String) As String
Return "Integer,String"
End Function
Public Function F(ByVal b As Short, ByVal o As Object) As String
Return "Short,Object"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Primitive_Object1()
Dim o As Object = New C9
o.F(b, c)
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_IConvertible_Primitive1()
Dim o As Object = New C9
o.F(iic, c)
End Sub
Private Class C10
Public Function F(ByVal o As Short, ByVal a1 As A)
Return "Short,A"
End Function
Public Function F(ByVal o As Object, ByVal b1 As BB)
Return "Object,BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_Primitive1()
Dim o As Object = New C10
Assert.AreEqual("Short,A", o.F(s, ccA))
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_Primitive2()
Dim o As Object = New C10
o.F(s, ccB)
End Sub
Private Class C11
Public Function F(ByVal o As Char, ByVal a1 As A)
Return "Char,A"
End Function
Public Function F(ByVal o As String, ByVal b1 As BB)
Return "Object,BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_Char1()
Dim o As Object = New C11
Assert.AreEqual("Char,A", o.F(c, ccA))
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_Char2()
Dim o As Object = New C11
o.F(c, ccB)
End Sub
Private Class C12
Public Function F(ByVal o As String, ByVal a1 As A)
Return "String,A"
End Function
Public Function F(ByVal o As Object, ByVal b1 As BB)
Return "Object,BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_Char3()
Dim o As Object = New C12
Assert.AreEqual("String,A", o.F(c, ccA))
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_Char4()
Dim o As Object = New C12
o.F(c, ccB)
End Sub
Private Class C13
Public Function F(ByVal o As Short, ByVal ParamArray arr() As Integer)
Return "Short,ParamArray arr() Integer"
End Function
Public Function F(ByVal o As Object, ByVal i1 As Integer, ByVal i2 As Integer)
Return "Object,Integer,Integer"
End Function
End Class
<Test()> _
Public Sub LateBind_Primitive_ParamArray1()
Dim o As Object = New C13
Assert.AreEqual("Short,ParamArray arr() Integer", o.F(b, i, i))
Assert.AreEqual("Object,Integer,Integer", o.F(l, i, i))
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Primitive_ParamArray2()
Dim o As Object = New C13
o.F(b, l, l)
End Sub
Private Class C14
Public Function F(ByVal o1 As Object, ByVal o2 As Object)
Return "Object,Object"
End Function
Public Function F(ByVal o1 As String, ByVal o2 As String)
Return "String,String"
End Function
End Class
<Test()> _
Public Sub LateBind_Primitive_Object2()
Dim o As Object = New C14
Assert.AreEqual("Object,Object", o.F(i, c))
End Sub
Private Class C15
Public Function F(ByVal a1 As A, ByVal ParamArray b1() As BB)
Return "A,ParamArray arr() BB"
End Function
Public Function F(ByVal b1 As BB, ByVal b2 As A, ByVal b3 As BB)
Return "BB,A,BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray20()
Dim o As Object = New C15
Assert.AreEqual("BB,A,BB", o.F(ccB, ccA, ccB))
End Sub
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_ParamArray30()
Dim o As Object = New C15
o.F(ccB, ccB, ccB)
End Sub
Private Class C16
Public Function F(ByVal b1 As BB, ByVal s As Short)
Return "BB,Short"
End Function
Public Function F(ByVal a As A, ByVal l As Long)
Return "A,Long"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_Primitive10()
Dim o As Object = New C16
Assert.AreEqual("A,Long", o.F(ccB, i))
End Sub
Private Class C17
Public Function F(ByVal a As A, ByVal s As Integer)
Return "A,Integer"
End Function
Public Function F(ByVal b1 As BB, ByVal l As Long)
Return "BB,Long"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_Primitive11()
Dim o As Object = New C17
o.F(ccB, i)
End Sub
Private Class C18
Public Function F(ByVal i As Integer, ByVal s As String)
Return "Integer,Short"
End Function
Public Function F(ByVal s As String, ByVal l As Long)
Return "String,Long"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Primitive_String10()
Dim o As Object = New C18
Assert.AreEqual("A,Long", o.F(i, i))
End Sub
Private Class C19
Public Function F(ByVal a As A)
Return "A"
End Function
Public Function F(ByVal b As BB)
Return "BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_20()
Dim o As Object = New C19
Assert.AreEqual("BB", o.F(ccc))
End Sub
Private Class C20
Public Function F(ByVal a As A, ByVal l As Long)
Return "A,Long"
End Function
Public Function F(ByVal b1 As BB, ByVal i As Integer)
Return "BB,Integer"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_21()
Dim o As Object = New C20
Assert.AreEqual("BB,Integer", o.F(ccc, i))
Assert.AreEqual("BB,Integer", o.F(ccc, s))
Assert.AreEqual("A,Long", o.F(ccc, l))
End Sub
Private Class C21
Public Function F(ByVal s As Short, ByVal i As Integer)
Return "Short,Integer"
End Function
Public Function F(ByVal s As Short, ByVal i As Long)
Return "Short,Long"
End Function
Public Function F(ByVal s As Short, ByVal i As Integer, ByVal s2 As Short)
Return "Short,Integer,Short"
End Function
Public Function F(ByVal s As Short, ByVal i As Long, ByVal i1 As Integer)
Return "Short,Long,Integer"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Primitive_50()
Dim o As Object = New C21
Assert.AreEqual("BB,Integer", o.F(i, i))
End Sub
Private Class C22
Public Function F(ByVal i1 As Long, ByVal i2 As Integer) As String
Return "Long,Integer"
End Function
Public Function F(ByVal i1 As Long, ByVal i2 As Long) As String
Return "Long,Long"
End Function
Public Function F(ByVal i1 As Integer, ByVal i2 As Long) As String
Return "Integer,Long"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Primitive_51()
Dim o As Object = New C22
Assert.AreEqual("Long,Integer", o.F(i, i))
End Sub
Private Class C41
Public Function F(ByVal a As A) As String
Return "A"
End Function
Public Function F(ByVal a As A, ByVal ParamArray args() As A) As String
Return "A,ParamArray A()"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray41()
Dim o As Object = New C41
Assert.AreEqual("A", o.F(ccA))
Assert.AreEqual("A", o.F(ccB))
Assert.AreEqual("A", o.F(ccc))
End Sub
Private Class C42
Public Function F(ByVal a As Object) As String
Return "Object"
End Function
Public Function F(ByVal a As A, ByVal ParamArray args() As A) As String
Return "A,ParamArray A()"
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray42()
Dim o As Object = New C42
Assert.AreEqual("A,ParamArray A()", o.F(ccA))
Assert.AreEqual("A,ParamArray A()", o.F(ccB))
Assert.AreEqual("A,ParamArray A()", o.F(ccc))
Assert.AreEqual("A,ParamArray A()", o.F(ccA, ccA))
Assert.AreEqual("A,ParamArray A()", o.F(ccc, ccB))
End Sub
Private Class C43
Public Function F(ByVal a As A, ByVal b As Object) As String
Return "A,Object"
End Function
Public Function F(ByVal a As Object, ByVal ParamArray args() As A) As String
Return "Object,ParamArray A()"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Complex_ParamArray43()
Dim o As Object = New C43
o.F(ccA, ccA)
End Sub
Private Class C600
Public Function F(ByVal ParamArray args() As Integer) As Integer
Return args.Length
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray600()
Dim o As Object = New C600
Dim a As Integer() = {1, 2, 3}
Dim x As Integer = 10
Assert.AreEqual(3, o.F(a))
Assert.AreEqual(4, o.F(x, x, x, x))
End Sub
Private Class C601
Public Function F(ByVal ParamArray args() As Long) As Integer
Return args.Length
End Function
Public Function F(ByVal ParamArray args() As Integer) As Integer
Return args.Length
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray601()
Dim o As Object = New C601
Dim a As Long() = {1, 2, 3}
Assert.AreEqual(3, o.F(a))
Assert.AreEqual(4, o.F(10, 20, 30, 40))
End Sub
Private Class C602
Function F(ByVal ParamArray a As Object()) As Integer
Return 0
End Function
Function F()
Return 1
End Function
Function F(ByVal a As Object, ByVal b As Object)
Return 2
End Function
Function F(ByVal a As Object, ByVal b As Object, ByVal ParamArray c As Object())
Return 3
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray602()
Dim o As Object = New C602
Assert.AreEqual(1, o.F())
Assert.AreEqual(0, o.F(1))
Assert.AreEqual(2, o.F(1, 2))
End Sub
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_Complex_ParamArray603()
Dim o As Object = New C602
o.F(1, 2, 3)
End Sub
Class C604
Function F(ByVal ParamArray args() As Integer) As Integer
Dim a As Integer
a = args.Length
Return a
End Function
End Class
<Test()> _
Public Sub LateBind_Complex_ParamArray604()
Dim o As Object = New C604
Dim a As Integer() = {1, 2, 3}
Dim b As Integer = 1
Assert.AreEqual(3, o.F(a))
Assert.AreEqual(4, o.F(10, b, 30, 40))
Assert.AreEqual(0, o.F())
End Sub
#Region "MS BUG"
' MS passes this test and fails in next that differs just by method ordering inside class
' we should fail in both cases
Private Class C23
Public Function F(ByVal i1 As Long, ByVal i2 As Integer, ByVal i3 As Long) As String
Return "Long,Integer,Long"
End Function
Public Function F(ByVal i1 As Integer, ByVal i2 As Long, ByVal i3 As Integer) As String
Return "Integer,Long,Integer"
End Function
Public Function F(ByVal i1 As Long, ByVal i2 As Integer, ByVal i3 As Integer) As String
Return "Long,Integer,Integer"
End Function
End Class
'THIS TEST SHOULD FAIL IN MS
<Test(), ExpectedException(GetType(AmbiguousMatchException)), Category("NotDotNet")> _
Public Sub LateBind_MS_Bug_NoFail()
Dim o As Object = New C23
Assert.AreEqual("Long,Integer,Integer", o.F(i, i, i))
End Sub
Private Class C24
Public Function F(ByVal i1 As Integer, ByVal i2 As Long, ByVal i3 As Integer) As String
Return "Integer,Long,Integer"
End Function
Public Function F(ByVal i1 As Long, ByVal i2 As Integer, ByVal i3 As Integer) As String
Return "Long,Integer,Integer"
End Function
Public Function F(ByVal i1 As Long, ByVal i2 As Integer, ByVal i3 As Long) As String
Return "Long,Integer,Long"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_MS_Bug_Fail()
Dim o As Object = New C24
o.F(i, i, i)
End Sub
#End Region
Class C400
Public Function fun(ByVal i As Integer, ByVal ParamArray a() As Long)
Return 10
End Function
Public Function fun(ByVal ParamArray a() As Long)
Return 20
End Function
End Class
<Test()> _
Public Sub LateBind_TypeMembersM()
Dim o As Object = New C400
Dim a As Integer = o.fun(1, 2, 3)
Assert.AreEqual(10, a)
End Sub
Class C401
Public Function fun(ByVal i1 As Long, ByVal i2 As Long, ByVal i3 As Long)
Return 10
End Function
Public Function fun(ByVal i1 As Integer, ByVal ParamArray a() As Long)
Return 20
End Function
End Class
<Test()> _
Public Sub LateBind_TypeMembersM_1()
Dim o As Object = New C401
Dim a As Integer = o.fun(1, 2, 3)
Assert.AreEqual(20, a)
End Sub
Class C402
Public Function fun(ByVal i1 As Integer, ByVal i2 As Long, ByVal ParamArray a() As Long)
Return 10
End Function
Public Function fun(ByVal i1 As Integer, ByVal ParamArray a() As Long)
Return 20
End Function
End Class
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_TypeMembersM_2()
Dim o As Object = New C402
o.fun(1, 2, 3)
End Sub
'TargetJvmNotWorking - Ambiguous matching in method resolution
<Category("TargetJvmNotWorking")> _
<Test()> _
Public Sub LateBind_TypeMembersM_3()
Dim o As Object = New C402
o.fun(1, 2)
End Sub
Class C403
Public Function fun(ByVal i1 As Short, ByVal i2 As Integer, ByVal ParamArray a() As Long)
Return 10
End Function
Public Function fun(ByVal i1 As Short, ByVal ParamArray a() As Long)
Return 20
End Function
End Class
<Test()> _
Public Sub LateBind_TypeMembersM_4()
Dim o As Object = New C403
Dim sh As Short = 2
Assert.AreEqual(10, o.fun(sh, sh, sh))
End Sub
Class C500
Sub fun(ByRef a As Long)
a = a + 10
End Sub
Sub fun(ByRef a As Integer)
a = a + 20
End Sub
Sub fun(ByRef a As Decimal)
a = a + 30
End Sub
End Class
<Test()> _
Public Sub LateBind_TypeMembersF()
Dim a As Integer = 10
Dim a1 As Long = 10
Dim a2 As Decimal = 10
Dim o As Object = New C500
o.fun(a)
o.fun(a1)
o.fun(a2)
Assert.AreEqual(30, a)
Assert.AreEqual(20, a1)
Assert.AreEqual(40, a2)
End Sub
Class C800
Public Function fun(ByVal i As Integer, ByVal a As Long)
If i = 2 And a = 1 Then
Return 10
End If
Return 11
End Function
End Class
<Test()> _
Public Sub LateBind_TypeMembersU()
Dim o As Object = New C800
Dim a As Integer = o.fun(a:=1, i:=2)
Assert.AreEqual(10, a)
End Sub
Class C700
Public b As Byte
End Class
<Test()> _
Public Sub LateBind_TypeMembersY()
Dim o As Object = New C700
o.b = 0
Assert.AreEqual(0, o.b)
End Sub
Private Class C900
Public Function F(ByVal ParamArray arr() As Integer) As String
Return "ParamArray Integer()"
End Function
Public Function F(ByVal ParamArray arr() As Long) As String
Return "ParamArray Long()"
End Function
End Class
<Test()> _
Public Sub LateBind_TypeMembers_2()
Dim o As Object = New C900
Dim i As Integer = 5
Dim l As Long = 7
Dim sh As Short = 3
Assert.AreEqual("ParamArray Integer()", o.F(i, i, i, i, i))
Assert.AreEqual("ParamArray Long()", o.F(l, l, l, l, l, l))
Assert.AreEqual("ParamArray Integer()", o.F(sh, sh, sh, sh))
End Sub
Private Class C1000
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
Public Function F(ByVal i As Long)
Return "Long"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_1()
Dim o As Object = New C1000
Assert.AreEqual("Integer", o.F(Nothing))
End Sub
Private Class C1001
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
Public Function F(ByVal i As Boolean)
Return "Boolean"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_2()
Dim o As Object = New C1001
o.F(Nothing)
End Sub
Private Class C1002
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
Public Function F(ByVal i As Byte)
Return "Byte"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_3()
Dim o As Object = New C1002
Assert.AreEqual("Byte", o.F(Nothing))
End Sub
Private Class C1003
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
Public Function F(ByVal i As Char)
Return "Char"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_4()
Dim o As Object = New C1003
o.F(Nothing)
End Sub
Private Class C1004
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
Public Function F(ByVal i As String)
Return "String"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_5()
Dim o As Object = New C1004
o.F(Nothing)
End Sub
Private Class C1005
Public Function F(ByVal i As Char)
Return "Char"
End Function
Public Function F(ByVal i As String)
Return "String"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_6()
Dim o As Object = New C1005
Assert.AreEqual("Char", o.F(Nothing))
End Sub
Private Class C1006
Public Function F(ByVal i As Char)
Return "Char"
End Function
Public Function F(ByVal i As Boolean)
Return "Boolean"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_7()
Dim o As Object = New C1006
Assert.AreEqual("Char", o.F(Nothing))
End Sub
Private Class C1007
Public Function F(ByVal i As Boolean)
Return "Boolean"
End Function
Public Function F(ByVal i As String)
Return "String"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_8()
Dim o As Object = New C1007
o.F(Nothing)
End Sub
Private Class C1008
Public Function F(ByVal i As Object)
Return "Object"
End Function
Public Function F(ByVal i As String)
Return "String"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_9()
Dim o As Object = New C1008
Assert.AreEqual("String", o.F(Nothing))
End Sub
Private Class C1009
Public Function F(ByVal i As Object)
Return "Object"
End Function
Public Function F(ByVal i As Char)
Return "Char"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_10()
Dim o As Object = New C1009
Assert.AreEqual("Char", o.F(Nothing))
End Sub
Private Class C1010
Public Function F(ByVal i As Object)
Return "Object"
End Function
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_11()
Dim o As Object = New C1010
Assert.AreEqual("Integer", o.F(Nothing))
End Sub
Private Class C1011
Public Function F(ByVal i As A)
Return "A"
End Function
Public Function F(ByVal i As Integer)
Return "Integer"
End Function
End Class
<Test(), ExpectedException(GetType(AmbiguousMatchException))> _
Public Sub LateBind_Nothing_12()
Dim o As Object = New C1011
o.F(Nothing)
End Sub
Private Class C1012
Public Function F(ByVal i As A)
Return "A"
End Function
Public Function F(ByVal i As BB)
Return "BB"
End Function
End Class
<Test()> _
Public Sub LateBind_Nothing_13()
Dim o As Object = New C1012
Assert.AreEqual("BB", o.F(Nothing))
End Sub
#Region "Private Helper Classes"
Private Class A
Public Overrides Function toString() As String
Return "A.instance"
End Function
End Class
Private Class BB
Inherits A
Public Overrides Function toString() As String
Return "BB.instance"
End Function
End Class
Private Class CC
Inherits BB
Public Overrides Function toString() As String
Return "CC.instance"
End Function
End Class
Private Class IC
Implements IConvertible
Public Function GetTypeCode() As System.TypeCode Implements System.IConvertible.GetTypeCode
Return TypeCode.Object
End Function
Public Function ToBoolean(ByVal provider As System.IFormatProvider) As Boolean Implements System.IConvertible.ToBoolean
Return True
End Function
Public Function ToByte(ByVal provider As System.IFormatProvider) As Byte Implements System.IConvertible.ToByte
Return 1
End Function
Public Function ToChar(ByVal provider As System.IFormatProvider) As Char Implements System.IConvertible.ToChar
Return "a"c
End Function
Public Function ToDateTime(ByVal provider As System.IFormatProvider) As Date Implements System.IConvertible.ToDateTime
Return New DateTime
End Function
Public Function ToDecimal(ByVal provider As System.IFormatProvider) As Decimal Implements System.IConvertible.ToDecimal
Return 1
End Function
Public Function ToDouble(ByVal provider As System.IFormatProvider) As Double Implements System.IConvertible.ToDouble
Return 1
End Function
Public Function ToInt16(ByVal provider As System.IFormatProvider) As Short Implements System.IConvertible.ToInt16
Return 1
End Function
Public Function ToInt32(ByVal provider As System.IFormatProvider) As Integer Implements System.IConvertible.ToInt32
Return 1
End Function
Public Function ToInt64(ByVal provider As System.IFormatProvider) As Long Implements System.IConvertible.ToInt64
Return 1
End Function
Public Function ToSByte(ByVal provider As System.IFormatProvider) As SByte Implements System.IConvertible.ToSByte
Return New SByte
End Function
Public Function ToSingle(ByVal provider As System.IFormatProvider) As Single Implements System.IConvertible.ToSingle
Return 1
End Function
Public Overloads Function ToString(ByVal provider As System.IFormatProvider) As String Implements System.IConvertible.ToString
Return "ICOnvertible.instance"
End Function
Public Function ToType(ByVal conversionType As System.Type, ByVal provider As System.IFormatProvider) As Object Implements System.IConvertible.ToType
Return New Object
End Function
Public Function ToUInt16(ByVal provider As System.IFormatProvider) As UInt16 Implements System.IConvertible.ToUInt16
Return New UInt16
End Function
Public Function ToUInt32(ByVal provider As System.IFormatProvider) As UInt32 Implements System.IConvertible.ToUInt32
Return New UInt32
End Function
Public Function ToUInt64(ByVal provider As System.IFormatProvider) As UInt64 Implements System.IConvertible.ToUInt64
Return New UInt64
End Function
End Class
#End Region
End Class
|