1--TEST-- 2COM: General variant tests 3--SKIPIF-- 4<?php 5if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; 6if (4 != PHP_INT_SIZE) print "skip x86 only"; ?> 7--FILE-- 8<?php 9error_reporting(E_ALL); 10 11$v = new VARIANT(); 12if (VT_EMPTY != variant_get_type($v)) { 13 echo "VT_EMPTY: bork\n"; 14} 15 16$values = array(VT_I4 => 42, VT_R8 => 3.5, VT_BSTR => "hello", VT_BOOL => false); 17$binary_ops = array('add', 'cat', 'sub', 'mul', 'and', 'div', 18 'eqv', 'idiv', 'imp', 'mod', 'or', 'pow', 'xor'); 19 20foreach ($values as $t => $val) { 21 $v = new VARIANT($val); 22 if ($t != variant_get_type($v)) { 23 printf("Bork: [%d] %d: %s\n", $t, variant_get_type($v), $val); 24 print $v . "\n"; 25 } 26 $results = array(); 27 28 foreach ($values as $op2) { 29 echo "--\n"; 30 foreach ($binary_ops as $op) { 31 try { 32 echo "$op: " . call_user_func('variant_' . $op, $v, $op2) . "\n"; 33 } catch (com_exception $e) { 34 echo "$op:\n"; 35 echo "\tvariant_$op($v, $op2)\n"; 36 echo "\texception " . $e->getMessage(); 37 printf("\n\tcode %08x\n\n", $e->getCode()); 38 } 39 } 40 } 41} 42 43echo "OK!"; 44?> 45--EXPECT-- 46-- 47add: 84 48cat: 4242 49sub: 0 50mul: 1764 51and: 42 52div: 1 53eqv: -1 54idiv: 1 55imp: -1 56mod: 0 57or: 42 58pow: 1.50130937545297E+68 59xor: 0 60-- 61add: 45.5 62cat: 423.5 63sub: 38.5 64mul: 147 65and: 0 66div: 12 67eqv: -47 68idiv: 10 69imp: -43 70mod: 2 71or: 46 72pow: 480145.116863642 73xor: 46 74-- 75add: 76 variant_add(42, hello) 77 exception Type mismatch 78 code 80020005 79 80cat: 42hello 81sub: 82 variant_sub(42, hello) 83 exception Type mismatch 84 code 80020005 85 86mul: 87 variant_mul(42, hello) 88 exception Type mismatch 89 code 80020005 90 91and: 92 variant_and(42, hello) 93 exception Type mismatch 94 code 80020005 95 96div: 97 variant_div(42, hello) 98 exception Type mismatch 99 code 80020005 100 101eqv: 102 variant_eqv(42, hello) 103 exception Type mismatch 104 code 80020005 105 106idiv: 107 variant_idiv(42, hello) 108 exception Type mismatch 109 code 80020005 110 111imp: 112 variant_imp(42, hello) 113 exception Type mismatch 114 code 80020005 115 116mod: 117 variant_mod(42, hello) 118 exception Type mismatch 119 code 80020005 120 121or: 122 variant_or(42, hello) 123 exception Type mismatch 124 code 80020005 125 126pow: 127 variant_pow(42, hello) 128 exception Type mismatch 129 code 80020005 130 131xor: 132 variant_xor(42, hello) 133 exception Type mismatch 134 code 80020005 135 136-- 137add: 42 138cat: 42False 139sub: 42 140mul: 0 141and: 0 142div: 143 variant_div(42, ) 144 exception Division by zero 145 code 80020012 146 147eqv: -43 148idiv: 149 variant_idiv(42, ) 150 exception Division by zero 151 code 80020012 152 153imp: -43 154mod: 155 variant_mod(42, ) 156 exception Division by zero 157 code 80020012 158 159or: 42 160pow: 1 161xor: 42 162-- 163add: 45.5 164cat: 3.542 165sub: -38.5 166mul: 147 167and: 0 168div: 8.33333333333333E-02 169eqv: -47 170idiv: 0 171imp: -5 172mod: 4 173or: 46 174pow: 7.09345573078604E+22 175xor: 46 176-- 177add: 7 178cat: 3.53.5 179sub: 0 180mul: 12.25 181and: 4 182div: 1 183eqv: -1 184idiv: 1 185imp: -1 186mod: 0 187or: 4 188pow: 80.2117802289664 189xor: 0 190-- 191add: 192 variant_add(3.5, hello) 193 exception Type mismatch 194 code 80020005 195 196cat: 3.5hello 197sub: 198 variant_sub(3.5, hello) 199 exception Type mismatch 200 code 80020005 201 202mul: 203 variant_mul(3.5, hello) 204 exception Type mismatch 205 code 80020005 206 207and: 208 variant_and(3.5, hello) 209 exception Type mismatch 210 code 80020005 211 212div: 213 variant_div(3.5, hello) 214 exception Type mismatch 215 code 80020005 216 217eqv: 218 variant_eqv(3.5, hello) 219 exception Type mismatch 220 code 80020005 221 222idiv: 223 variant_idiv(3.5, hello) 224 exception Type mismatch 225 code 80020005 226 227imp: 228 variant_imp(3.5, hello) 229 exception Type mismatch 230 code 80020005 231 232mod: 233 variant_mod(3.5, hello) 234 exception Type mismatch 235 code 80020005 236 237or: 238 variant_or(3.5, hello) 239 exception Type mismatch 240 code 80020005 241 242pow: 243 variant_pow(3.5, hello) 244 exception Type mismatch 245 code 80020005 246 247xor: 248 variant_xor(3.5, hello) 249 exception Type mismatch 250 code 80020005 251 252-- 253add: 3.5 254cat: 3.5False 255sub: 3.5 256mul: 0 257and: 0 258div: 259 variant_div(3.5, ) 260 exception Division by zero 261 code 80020012 262 263eqv: -5 264idiv: 265 variant_idiv(3.5, ) 266 exception Division by zero 267 code 80020012 268 269imp: -5 270mod: 271 variant_mod(3.5, ) 272 exception Division by zero 273 code 80020012 274 275or: 4 276pow: 1 277xor: 4 278-- 279add: 280 variant_add(hello, 42) 281 exception Type mismatch 282 code 80020005 283 284cat: hello42 285sub: 286 variant_sub(hello, 42) 287 exception Type mismatch 288 code 80020005 289 290mul: 291 variant_mul(hello, 42) 292 exception Type mismatch 293 code 80020005 294 295and: 296 variant_and(hello, 42) 297 exception Type mismatch 298 code 80020005 299 300div: 301 variant_div(hello, 42) 302 exception Type mismatch 303 code 80020005 304 305eqv: 306 variant_eqv(hello, 42) 307 exception Type mismatch 308 code 80020005 309 310idiv: 311 variant_idiv(hello, 42) 312 exception Type mismatch 313 code 80020005 314 315imp: 316 variant_imp(hello, 42) 317 exception Type mismatch 318 code 80020005 319 320mod: 321 variant_mod(hello, 42) 322 exception Type mismatch 323 code 80020005 324 325or: 326 variant_or(hello, 42) 327 exception Type mismatch 328 code 80020005 329 330pow: 331 variant_pow(hello, 42) 332 exception Type mismatch 333 code 80020005 334 335xor: 336 variant_xor(hello, 42) 337 exception Type mismatch 338 code 80020005 339 340-- 341add: 342 variant_add(hello, 3.5) 343 exception Type mismatch 344 code 80020005 345 346cat: hello3.5 347sub: 348 variant_sub(hello, 3.5) 349 exception Type mismatch 350 code 80020005 351 352mul: 353 variant_mul(hello, 3.5) 354 exception Type mismatch 355 code 80020005 356 357and: 358 variant_and(hello, 3.5) 359 exception Type mismatch 360 code 80020005 361 362div: 363 variant_div(hello, 3.5) 364 exception Type mismatch 365 code 80020005 366 367eqv: 368 variant_eqv(hello, 3.5) 369 exception Type mismatch 370 code 80020005 371 372idiv: 373 variant_idiv(hello, 3.5) 374 exception Type mismatch 375 code 80020005 376 377imp: 378 variant_imp(hello, 3.5) 379 exception Type mismatch 380 code 80020005 381 382mod: 383 variant_mod(hello, 3.5) 384 exception Type mismatch 385 code 80020005 386 387or: 388 variant_or(hello, 3.5) 389 exception Type mismatch 390 code 80020005 391 392pow: 393 variant_pow(hello, 3.5) 394 exception Type mismatch 395 code 80020005 396 397xor: 398 variant_xor(hello, 3.5) 399 exception Type mismatch 400 code 80020005 401 402-- 403add: hellohello 404cat: hellohello 405sub: 406 variant_sub(hello, hello) 407 exception Type mismatch 408 code 80020005 409 410mul: 411 variant_mul(hello, hello) 412 exception Type mismatch 413 code 80020005 414 415and: 416 variant_and(hello, hello) 417 exception Type mismatch 418 code 80020005 419 420div: 421 variant_div(hello, hello) 422 exception Type mismatch 423 code 80020005 424 425eqv: 426 variant_eqv(hello, hello) 427 exception Type mismatch 428 code 80020005 429 430idiv: 431 variant_idiv(hello, hello) 432 exception Type mismatch 433 code 80020005 434 435imp: 436 variant_imp(hello, hello) 437 exception Type mismatch 438 code 80020005 439 440mod: 441 variant_mod(hello, hello) 442 exception Type mismatch 443 code 80020005 444 445or: 446 variant_or(hello, hello) 447 exception Type mismatch 448 code 80020005 449 450pow: 451 variant_pow(hello, hello) 452 exception Type mismatch 453 code 80020005 454 455xor: 456 variant_xor(hello, hello) 457 exception Type mismatch 458 code 80020005 459 460-- 461add: 462 variant_add(hello, ) 463 exception Type mismatch 464 code 80020005 465 466cat: helloFalse 467sub: 468 variant_sub(hello, ) 469 exception Type mismatch 470 code 80020005 471 472mul: 473 variant_mul(hello, ) 474 exception Type mismatch 475 code 80020005 476 477and: 478 variant_and(hello, ) 479 exception Type mismatch 480 code 80020005 481 482div: 483 variant_div(hello, ) 484 exception Type mismatch 485 code 80020005 486 487eqv: 488 variant_eqv(hello, ) 489 exception Type mismatch 490 code 80020005 491 492idiv: 493 variant_idiv(hello, ) 494 exception Type mismatch 495 code 80020005 496 497imp: 498 variant_imp(hello, ) 499 exception Type mismatch 500 code 80020005 501 502mod: 503 variant_mod(hello, ) 504 exception Type mismatch 505 code 80020005 506 507or: 508 variant_or(hello, ) 509 exception Type mismatch 510 code 80020005 511 512pow: 513 variant_pow(hello, ) 514 exception Type mismatch 515 code 80020005 516 517xor: 518 variant_xor(hello, ) 519 exception Type mismatch 520 code 80020005 521 522-- 523add: 42 524cat: False42 525sub: -42 526mul: 0 527and: 0 528div: 0 529eqv: -43 530idiv: 0 531imp: -1 532mod: 0 533or: 42 534pow: 0 535xor: 42 536-- 537add: 3.5 538cat: False3.5 539sub: -3.5 540mul: 0 541and: 0 542div: 0 543eqv: -5 544idiv: 0 545imp: -1 546mod: 0 547or: 4 548pow: 0 549xor: 4 550-- 551add: 552 variant_add(0, hello) 553 exception Type mismatch 554 code 80020005 555 556cat: Falsehello 557sub: 558 variant_sub(0, hello) 559 exception Type mismatch 560 code 80020005 561 562mul: 563 variant_mul(0, hello) 564 exception Type mismatch 565 code 80020005 566 567and: 568 variant_and(0, hello) 569 exception Type mismatch 570 code 80020005 571 572div: 573 variant_div(0, hello) 574 exception Type mismatch 575 code 80020005 576 577eqv: 578 variant_eqv(0, hello) 579 exception Type mismatch 580 code 80020005 581 582idiv: 583 variant_idiv(0, hello) 584 exception Type mismatch 585 code 80020005 586 587imp: 588 variant_imp(0, hello) 589 exception Type mismatch 590 code 80020005 591 592mod: 593 variant_mod(0, hello) 594 exception Type mismatch 595 code 80020005 596 597or: 598 variant_or(0, hello) 599 exception Type mismatch 600 code 80020005 601 602pow: 603 variant_pow(0, hello) 604 exception Type mismatch 605 code 80020005 606 607xor: 608 variant_xor(0, hello) 609 exception Type mismatch 610 code 80020005 611 612-- 613add: 0 614cat: FalseFalse 615sub: 0 616mul: 0 617and: 0 618div: 619 variant_div(0, ) 620 exception Out of present range 621 code 8002000a 622 623eqv: -1 624idiv: 625 variant_idiv(0, ) 626 exception Division by zero 627 code 80020012 628 629imp: -1 630mod: 631 variant_mod(0, ) 632 exception Division by zero 633 code 80020012 634 635or: 0 636pow: 1 637xor: 0 638OK! 639