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